@sentry/junior-github 0.291.0 → 0.293.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The heartbeat part of merge conflict checks. For each due repository, a
3
+ * GraphQL search reads the open Junior pull requests with their
4
+ * mergeability.
5
+ * Only a conflict that a Watch or event automation wants publishes
6
+ * `pull_request.merge_conflict`. No agent runs for the check.
7
+ */
8
+ import type { EventPublisher, PluginLogger, PluginState } from "@sentry/junior-plugin-api";
9
+ import type { GitHubDb } from "../db/database.js";
10
+ type SearchOpenPullRequests = (input: {
11
+ after?: string;
12
+ repositoryFullName: string;
13
+ }) => Promise<unknown>;
14
+ interface CheckArgs {
15
+ db: GitHubDb;
16
+ events: EventPublisher;
17
+ log: Pick<PluginLogger, "error">;
18
+ now: Date;
19
+ search: SearchOpenPullRequests;
20
+ state: PluginState;
21
+ }
22
+ /**
23
+ * Run the merge conflict checks that are due. Only a repository with open
24
+ * Junior pull requests can have a check.
25
+ */
26
+ export declare function runGitHubConflictChecks(args: CheckArgs): Promise<void>;
27
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Merge conflict checks that wait for the heartbeat, one per repository.
3
+ *
4
+ * A check is only a debounce, so it lives in plugin state, not in the
5
+ * database. When a check is lost, the next push or pull request event
6
+ * checks again. A push to the default branch adds a check, and a check
7
+ * that already waits keeps its time. The heartbeat reads GitHub later, so a
8
+ * burst of pushes gives one check, and GitHub has time to calculate
9
+ * mergeability.
10
+ */
11
+ import type { PluginState } from "@sentry/junior-plugin-api";
12
+ import type { GitHubDb } from "../db/database.js";
13
+ /** One claimed check. */
14
+ export interface GitHubConflictCheck {
15
+ attempts: number;
16
+ repositoryFullName: string;
17
+ }
18
+ /** Return the repositories that have open Junior pull requests. */
19
+ export declare function listGitHubRepositoriesWithOpenPullRequests(db: GitHubDb, repositoryFullName?: string): Promise<string[]>;
20
+ /**
21
+ * Add a check at `dueAtMs` for a repository with open Junior pull requests.
22
+ * A check that already waits keeps its earlier time, so pushes that keep
23
+ * coming do not delay it. Return whether a check waits.
24
+ */
25
+ export declare function scheduleGitHubConflictCheck(args: {
26
+ db: GitHubDb;
27
+ dueAtMs: number;
28
+ repositoryFullName: string;
29
+ state: PluginState;
30
+ }): Promise<boolean>;
31
+ /**
32
+ * Claim the due check of a repository. The claim removes the push key
33
+ * before the check reads GitHub, so the read includes every push that the
34
+ * key held, and a later push adds a new key. A repeat at `claimedUntilMs`
35
+ * runs the check again when it stops without an end.
36
+ */
37
+ export declare function claimGitHubConflictCheck(args: {
38
+ claimedUntilMs: number;
39
+ nowMs: number;
40
+ repositoryFullName: string;
41
+ state: PluginState;
42
+ }): Promise<GitHubConflictCheck | undefined>;
43
+ /** End a claimed check, or repeat it at `retryAtMs`. */
44
+ export declare function settleGitHubConflictCheck(state: PluginState, check: GitHubConflictCheck, retryAtMs?: number): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The `push` webhook part of merge conflict checks. It makes no GitHub API
3
+ * calls, so a busy default branch costs one database read and a state
4
+ * write.
5
+ */
6
+ import type { PluginState } from "@sentry/junior-plugin-api";
7
+ import type { GitHubDb } from "../db/database.js";
8
+ /**
9
+ * Time from a push to its check. GitHub calculates mergeability after a
10
+ * push, and pushes in this time share one check.
11
+ */
12
+ export declare const CONFLICT_CHECK_DELAY_MS: number;
13
+ /**
14
+ * Schedule a check after a push to a repository's default branch. Stacked
15
+ * pull requests do not need this, because Junior restacks them when it
16
+ * pushes the branch below. Return whether a check waits.
17
+ */
18
+ export declare function scheduleGitHubPushConflictCheck(args: {
19
+ body: unknown;
20
+ db: GitHubDb;
21
+ now: Date;
22
+ state: PluginState;
23
+ }): Promise<boolean>;
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeGitHubEvents
3
- } from "./chunk-RRID5LSH.js";
3
+ } from "./chunk-J4ZSG7SD.js";
4
4
  export {
5
5
  normalizeGitHubEvents
6
6
  };
@@ -3,6 +3,32 @@
3
3
  * normalizers.
4
4
  */
5
5
  import type { EventInput } from "@sentry/junior-plugin-api";
6
+ import * as z from "zod";
7
+ /**
8
+ * The user who sent a webhook. GitHub authenticates this user, so on a comment
9
+ * or review it is the author, and on an issue update it made the change.
10
+ * Match on the numeric id; logins can be renamed and reused.
11
+ */
12
+ export declare const gitHubSenderSchema: z.ZodObject<{
13
+ id: z.ZodNumber;
14
+ login: z.ZodString;
15
+ }, z.core.$strip>;
16
+ /** Trusted event data that names who sent a webhook. */
17
+ export declare function gitHubSenderData(sender: z.output<typeof gitHubSenderSchema> | undefined): {
18
+ senderId?: number;
19
+ senderLogin?: string;
20
+ };
21
+ /** The GitHub user who did what an Event describes, when GitHub names one. */
22
+ export declare function gitHubDoneBy(login: string | undefined): Pick<EventInput, "doneBy"> | undefined;
23
+ /** The text of a webhook value, or undefined when it is missing or blank. */
24
+ export declare function nonBlank(value: string | null | undefined): string | undefined;
25
+ /** The title and body of an issue or pull request, as untrusted text. */
26
+ export declare function titleAndBodyText(item: {
27
+ body?: string | null;
28
+ title?: string;
29
+ }): string | undefined;
30
+ /** Convert an optional provider timestamp for receipt-time fallback ordering. */
31
+ export declare function providerTime(value: string | null | undefined): number | undefined;
6
32
  /**
7
33
  * Drop missing values from event data. A filter on a value that GitHub did not
8
34
  * send then does not match.
@@ -1,5 +1,5 @@
1
1
  import type { GitHubStatusIncident } from "../github-status.js";
2
- import type { CodeChangePublisher, PluginConversationAnnotations, PluginConversationReviewItems, PluginLogger, PluginRoute, EventPublisher } from "@sentry/junior-plugin-api";
2
+ import type { CodeChangePublisher, PluginConversationAnnotations, PluginConversationReviewItems, PluginLogger, PluginRoute, EventPublisher, PluginState } from "@sentry/junior-plugin-api";
3
3
  import * as z from "zod";
4
4
  import type { GitHubDb } from "../db/database.js";
5
5
  import type { GitHubPullRequestCommitComposition } from "../db/schema.js";
@@ -47,6 +47,7 @@ export declare function createGitHubWebhookRoute(args: {
47
47
  privateKeyEnv: string;
48
48
  events: EventPublisher;
49
49
  reviewItems: PluginConversationReviewItems;
50
+ state: PluginState;
50
51
  webhookSecret(): string | undefined;
51
52
  }): PluginRoute;
52
53
  export {};
@@ -21,6 +21,15 @@ export declare function loadPullRequest(env: GitHubInstallationEnv, pullRequest:
21
21
  number: number;
22
22
  repositoryFullName: string;
23
23
  }): Promise<unknown>;
24
+ /**
25
+ * Read one page of a repository's open pull requests by one author, with
26
+ * their mergeability, through GraphQL search and a read-only token.
27
+ */
28
+ export declare function searchOpenPullRequestMergeability(env: GitHubInstallationEnv, input: {
29
+ after?: string;
30
+ author: string;
31
+ repositoryFullName: string;
32
+ }): Promise<unknown>;
24
33
  /** Add the "reviewing" reaction to one pull request feedback comment. */
25
34
  export declare function markPullRequestFeedbackReviewing(env: GitHubInstallationEnv, target: {
26
35
  commentId: number;
@@ -0,0 +1,8 @@
1
+ import type { EventInput } from "@sentry/junior-plugin-api";
2
+ /**
3
+ * Normalize an issue edit, label, assignee, or milestone change into
4
+ * `issue.updated` for the issue and its repository. Return undefined when the
5
+ * delivery is not one of these updates. Changes that the bot makes publish
6
+ * nothing, so Junior's own issue updates do not wake its Watches.
7
+ */
8
+ export declare function normalizeIssueUpdateEvents(deliveryId: string, body: unknown, botEmail: string | undefined): EventInput[] | undefined;
@@ -5,7 +5,9 @@
5
5
  * conflicted pull request gets no new checks. So when a webhook delivers
6
6
  * another event for a watched pull request, such as a comment, a review, or a
7
7
  * check result, the webhook also reads its mergeability and publishes
8
- * `pull_request.merge_conflict`.
8
+ * `pull_request.merge_conflict`. A push to the default branch also starts a
9
+ * check of the repository's open Junior pull requests. See
10
+ * `merge-conflict-checks/`.
9
11
  */
10
12
  import type { EventInput, EventPublisher, PluginLogger } from "@sentry/junior-plugin-api";
11
13
  /** Values that GitHub reports for a conflicted pull request. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-github",
3
- "version": "0.291.0",
3
+ "version": "0.293.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -32,7 +32,7 @@
32
32
  "drizzle-orm": "^0.45.2",
33
33
  "marked": "^18.1.2",
34
34
  "zod": "^4.5.4",
35
- "@sentry/junior-plugin-api": "0.291.0"
35
+ "@sentry/junior-plugin-api": "0.293.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@oxlint/plugins": "1.79.0",
@@ -34,7 +34,7 @@ Open this when making repository edits, not for read-only inspection.
34
34
  1. Reuse the current non-default branch or create a focused branch.
35
35
  2. Commit with repo conventions, else `<type>(<scope>): <Subject>` imperative present, no agent branding.
36
36
  3. Push with `git push -u origin BRANCH`.
37
- If the branch has an open PR, check that it can merge. Do this after every push, including fixes for review feedback or failed checks. A conflicted PR gets no new checks. A watched PR gets `pull_request.merge_conflict` only with its next event, so do not wait for it.
37
+ If the branch has an open PR, check that it can merge. Do this after every push, including fixes for review feedback or failed checks. A conflicted PR gets no new checks. A watched PR gets `pull_request.merge_conflict` minutes later at the earliest, so do not wait for it.
38
38
  - Run `gh pr view NUMBER --repo owner/repo --json mergeable,baseRefName`.
39
39
  - `UNKNOWN`: GitHub is still calculating it. Wait about 5 seconds and check again, up to 3 times. If it stays `UNKNOWN`, report that and continue.
40
40
  - `CONFLICTING`: resolve it now. Do not ask first. First check if the PR is in a stack: `gh api 'repos/owner/repo/stacks?pull_request=NUMBER'`.