@sentry/junior-github 0.268.0 → 0.270.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.
@@ -57,4 +57,40 @@ export declare function listGitHubAssignedWork(db: GitHubDb, conversationIds: st
57
57
  export declare function recordGitHubPullRequestConversations(db: GitHubDb, input: GitHubPullRequestConversationsInput): Promise<boolean>;
58
58
  /** Link an existing Junior-owned PR to tracked issues across repositories. */
59
59
  export declare function recordGitHubPullRequestLinkedIssues(db: GitHubDb, input: GitHubPullRequestLinkedIssuesInput): Promise<boolean>;
60
+ /**
61
+ * Ask to check whether a Junior pull request is ready to merge, and claim the
62
+ * check when no other webhook runs one. A claim older than `staleMs` is free.
63
+ * Return the claim, or undefined when another webhook runs the check or
64
+ * Junior does not own the pull request. The webhook that runs the check sees
65
+ * the new request in `releaseGitHubPullRequestReadySync`.
66
+ */
67
+ export declare function claimGitHubPullRequestReadySync(db: GitHubDb, target: {
68
+ number: number;
69
+ repositoryFullName: string;
70
+ }, options: {
71
+ now: Date;
72
+ staleMs: number;
73
+ }): Promise<{
74
+ id: number;
75
+ ready: boolean;
76
+ requests: number;
77
+ } | undefined>;
78
+ /** Save whether a Junior pull request is ready to merge. */
79
+ export declare function setGitHubPullRequestReadyToMerge(db: GitHubDb, target: {
80
+ number: number;
81
+ ready: boolean;
82
+ repositoryFullName: string;
83
+ }): Promise<void>;
84
+ /**
85
+ * End a claimed check. When a webhook asked again during the check, keep the
86
+ * claim and return the new request count, so the caller checks once more.
87
+ * Return undefined when the claim ended or another webhook took it.
88
+ */
89
+ export declare function releaseGitHubPullRequestReadySync(db: GitHubDb, target: {
90
+ number: number;
91
+ repositoryFullName: string;
92
+ }, claim: {
93
+ id: number;
94
+ requests: number;
95
+ }): Promise<number | undefined>;
60
96
  export {};
@@ -9,6 +9,7 @@ import type { GitHubDb } from "../db/database.js";
9
9
  * retry of the same create call can call this again.
10
10
  */
11
11
  export declare function recordGitHubPullRequestOpener(db: GitHubDb, input: {
12
+ conversationId: string;
12
13
  createdAt: Date;
13
14
  identityId: string;
14
15
  number: number;
@@ -23,12 +24,18 @@ export declare function recordGitHubPullRequestRequester(db: GitHubDb, input: {
23
24
  number: number;
24
25
  repositoryFullName: string;
25
26
  }): Promise<void>;
27
+ /** The first person who asked Junior for a pull request. */
28
+ export interface GitHubPullRequestOpener {
29
+ /** Set only for the person who asked Junior to open it. */
30
+ conversationId?: string;
31
+ identityId: string;
32
+ }
26
33
  /**
27
- * Load the Junior identity id of the first requester of each pull request.
28
- * This is the person who asked Junior to open it, or, when the create had no
29
- * identity, the first person who asked Junior to update it.
34
+ * Load the first requester of each pull request. This is the person who
35
+ * asked Junior to open it, or, when the create had no identity, the first
36
+ * person who asked Junior to update it.
30
37
  */
31
38
  export declare function listGitHubPullRequestOpeners(db: GitHubDb, input: {
32
39
  numbers: number[];
33
40
  repositoryFullName: string;
34
- }): Promise<Map<number, string>>;
41
+ }): Promise<Map<number, GitHubPullRequestOpener>>;
package/dist/testing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normalizeGitHubEvents
3
- } from "./chunk-PQFFT2UO.js";
3
+ } from "./chunk-MUWR6X24.js";
4
4
  export {
5
5
  normalizeGitHubEvents
6
6
  };
@@ -11,13 +11,14 @@ declare const STATUS_TO_REACTION_CONTENT: {
11
11
  };
12
12
  type FeedbackStatus = keyof typeof STATUS_TO_REACTION_CONTENT;
13
13
  type PullRequestCommentKind = "conversation" | "review";
14
- /** Build the GitHub API path for one pull request comment's reactions. */
15
- export declare function pullRequestCommentReactionsPath(input: {
14
+ interface PullRequestCommentRef {
16
15
  owner: string;
17
16
  name: string;
18
17
  commentKind: PullRequestCommentKind;
19
18
  commentId: number;
20
- }): string;
19
+ }
20
+ /** Build the GitHub API path for one pull request comment's reactions. */
21
+ export declare function pullRequestCommentReactionsPath(input: PullRequestCommentRef): string;
21
22
  /** Return the GitHub reaction for one feedback state. */
22
23
  export declare function pullRequestFeedbackReactionContent(status: FeedbackStatus): (typeof STATUS_TO_REACTION_CONTENT)[FeedbackStatus];
23
24
  /**
@@ -50,6 +50,11 @@ export declare function selectFailingChecks(checkRuns: unknown, options?: {
50
50
  }): GitHubFailingCheck[];
51
51
  /** Normalize a completed check suite for attached PRs, or the repository alone. */
52
52
  export declare function normalizeCheckSuiteEvents(deliveryId: string, body: unknown, options?: GitHubCheckSuiteFacts): EventInput[];
53
+ /** The same-repository pull requests of one completed check suite. */
54
+ export declare function checkSuitePullRequests(body: unknown): Array<{
55
+ number: number;
56
+ repositoryFullName: string;
57
+ }>;
53
58
  /** Identifiers and event types one completed check suite may publish. */
54
59
  export declare function parseCheckSuitePublishTargets(body: unknown): {
55
60
  data: {
@@ -1,7 +1,8 @@
1
- import type { CodeChangePublisher, PluginConversationAnnotations, PluginLogger, PluginRoute, EventPublisher } from "@sentry/junior-plugin-api";
1
+ import type { CodeChangePublisher, PluginConversationAnnotations, PluginConversationReviewItems, PluginLogger, PluginRoute, EventPublisher } from "@sentry/junior-plugin-api";
2
2
  import { z } from "zod";
3
3
  import type { GitHubDb } from "../db/database.js";
4
4
  import type { GitHubPullRequestCommitComposition } from "../db/schema.js";
5
+ import { type GitHubPullRequestRef } from "./merge-conflict.js";
5
6
  import { type GitHubRoleTarget } from "./pull-request-match-data.js";
6
7
  import { type GitHubCommitPageLoader, type GitHubPullRequestTarget } from "./pull-request-people.js";
7
8
  /** The pull request comment data that the feedback reaction needs. */
@@ -32,6 +33,8 @@ export declare function createGitHubWebhookRoute(args: {
32
33
  * involved.
33
34
  */
34
35
  loadPullRequestCommitPages?(target: GitHubPullRequestTarget): Promise<GitHubCommitPageLoader>;
36
+ /** Read one pull request for its mergeability. */
37
+ loadPullRequest?(pullRequest: GitHubPullRequestRef): Promise<unknown>;
35
38
  /** Load a repository role for `openerRole`. */
36
39
  loadRepositoryRole?(target: GitHubRoleTarget): Promise<string>;
37
40
  /** Linked GitHub login of the user of one Junior identity, if any. */
@@ -40,6 +43,7 @@ export declare function createGitHubWebhookRoute(args: {
40
43
  markFeedbackReviewing(input: FeedbackTarget): Promise<void>;
41
44
  privateKeyEnv: string;
42
45
  events: EventPublisher;
46
+ reviewItems: PluginConversationReviewItems;
43
47
  webhookSecret(): string | undefined;
44
48
  }): PluginRoute;
45
49
  export {};
@@ -16,6 +16,11 @@ export declare function loadPullRequestCommitPages(env: GitHubInstallationEnv, p
16
16
  number: number;
17
17
  repositoryFullName: string;
18
18
  }): Promise<(page: number, perPage: number) => Promise<unknown>>;
19
+ /** Read one pull request, with a read-only token. */
20
+ export declare function loadPullRequest(env: GitHubInstallationEnv, pullRequest: {
21
+ number: number;
22
+ repositoryFullName: string;
23
+ }): Promise<unknown>;
19
24
  /** Add the "reviewing" reaction to one pull request feedback comment. */
20
25
  export declare function markPullRequestFeedbackReviewing(env: GitHubInstallationEnv, target: {
21
26
  commentId: number;
@@ -31,3 +36,32 @@ export declare function loadRepositoryRole(env: GitHubInstallationEnv, cache: Pl
31
36
  login: string;
32
37
  repositoryFullName: string;
33
38
  }): Promise<string>;
39
+ /** The pull request facts that decide whether it is ready to merge. */
40
+ export interface GitHubPullRequestMergeState {
41
+ /**
42
+ * At least one approval, and no reviewer still requests changes. Read
43
+ * only when GitHub says the pull request can merge cleanly.
44
+ */
45
+ approved: boolean;
46
+ draft: boolean;
47
+ /**
48
+ * GitHub's `mergeable_state`, such as `clean` or `blocked`. `clean` means
49
+ * that the required reviews and every check and status passed, and there
50
+ * are no conflicts. Undefined when GitHub has not computed it yet.
51
+ */
52
+ mergeableState?: string;
53
+ state: "closed" | "merged" | "open";
54
+ title: string;
55
+ url: string;
56
+ }
57
+ /**
58
+ * Read whether a pull request is ready to merge, with a read-only token.
59
+ * GitHub computes `mergeable_state` after a change, so an unknown state is
60
+ * read once more. Reviews load only for an open pull request that is not a
61
+ * draft and can merge cleanly. Each reviewer counts by their latest
62
+ * approval, change request, or dismissal. Comments do not change the result.
63
+ */
64
+ export declare function loadPullRequestMergeState(env: GitHubInstallationEnv, pullRequest: {
65
+ number: number;
66
+ repositoryFullName: string;
67
+ }): Promise<GitHubPullRequestMergeState>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Merge conflict checks on pull request webhook events.
3
+ *
4
+ * GitHub sends no webhook when a pull request gets a conflict, and a
5
+ * conflicted pull request gets no new checks. So when a webhook delivers
6
+ * another event for a watched pull request, such as a comment, a review, or a
7
+ * check result, the webhook also reads its mergeability and publishes
8
+ * `pull_request.merge_conflict`.
9
+ */
10
+ import type { EventInput, EventPublisher, PluginLogger } from "@sentry/junior-plugin-api";
11
+ /** Values that GitHub reports for a conflicted pull request. */
12
+ export interface GitHubMergeConflict {
13
+ baseBranch: string;
14
+ headSha: string;
15
+ url?: string;
16
+ }
17
+ /** One pull request in one repository. */
18
+ export interface GitHubPullRequestRef {
19
+ number: number;
20
+ repositoryFullName: string;
21
+ }
22
+ /**
23
+ * Build the `pull_request.merge_conflict` copies for one pull request. With
24
+ * no conflict, the copies have only the values that filters can match. The
25
+ * event key names the head commit, so each head commit publishes once.
26
+ */
27
+ export declare function gitHubMergeConflictEvents(input: GitHubPullRequestRef & {
28
+ conflict?: GitHubMergeConflict;
29
+ }): EventInput[];
30
+ /**
31
+ * Return `pull_request.merge_conflict` events for the open pull requests that
32
+ * these events are about, when a Watch or event automation wants them and
33
+ * GitHub reports a conflict. A `pull_request` webhook payload gives the
34
+ * mergeability when GitHub knows it. Otherwise the check reads the pull
35
+ * request, which also makes GitHub calculate its mergeability. When GitHub
36
+ * does not know it yet, a later event reads it again.
37
+ */
38
+ export declare function loadGitHubMergeConflictEvents(args: {
39
+ deliveryId: string;
40
+ events: EventInput[];
41
+ hasMatch: EventPublisher["hasMatch"];
42
+ loadPullRequest?(ref: GitHubPullRequestRef): Promise<unknown>;
43
+ log?: Pick<PluginLogger, "error">;
44
+ /** The body of a `pull_request` webhook. */
45
+ pullRequestPayload?: unknown;
46
+ }): Promise<EventInput[]>;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The "ready to merge" notice on the review desk for a Junior pull request.
3
+ *
4
+ * A pull request is ready to merge when it is open, not a draft, approved,
5
+ * and GitHub's merge state is `clean`. Each webhook that can change one of
6
+ * these facts reads them again from GitHub. The notice goes to the person
7
+ * who asked Junior to open the pull request, in the Conversation where they
8
+ * asked. It closes when the pull request merges, closes, or is no longer
9
+ * ready.
10
+ */
11
+ import type { PluginConversationReviewItems, PluginLogger } from "@sentry/junior-plugin-api";
12
+ import type { GitHubDb } from "../db/database.js";
13
+ import { type GitHubInstallationEnv } from "./installation-requests.js";
14
+ import type { GitHubPullRequestTarget } from "./pull-request-people.js";
15
+ /** Return the pull requests whose readiness one webhook delivery can change. */
16
+ export declare function pullRequestReadyTargets(eventName: string, body: unknown): GitHubPullRequestTarget[];
17
+ /**
18
+ * Add or close the "ready to merge" notice of each Junior pull request that a
19
+ * webhook delivery can change. The notice is optional, so a failure is logged
20
+ * and does not fail the delivery.
21
+ */
22
+ export declare function syncGitHubPullRequestReadyNotices(args: {
23
+ db: GitHubDb;
24
+ deliveryId: string;
25
+ env: GitHubInstallationEnv;
26
+ log?: Pick<PluginLogger, "error">;
27
+ reviewItems: PluginConversationReviewItems;
28
+ targets: GitHubPullRequestTarget[];
29
+ }): Promise<void>;
@@ -0,0 +1,5 @@
1
+ ALTER TABLE "junior_github_pull_request_requesters" ADD COLUMN "conversation_id" text;--> statement-breakpoint
2
+ ALTER TABLE "junior_github_pull_requests" ADD COLUMN "ready_to_merge_at" timestamp with time zone;--> statement-breakpoint
3
+ ALTER TABLE "junior_github_pull_requests" ADD COLUMN "ready_sync_requests" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
4
+ ALTER TABLE "junior_github_pull_requests" ADD COLUMN "ready_sync_id" integer;--> statement-breakpoint
5
+ ALTER TABLE "junior_github_pull_requests" ADD COLUMN "ready_sync_at" timestamp with time zone;