Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(github): store comments and status checks (#3649)

Will Hutchinson0c86d2f9069f
diff --git a/js/app/packages/queries/storage/github-pull-requests.ts b/js/app/packages/queries/storage/github-pull-requests.ts
index 8e89b80894..d98b8baa8c 100644
--- a/js/app/packages/queries/storage/github-pull-requests.ts
+++ b/js/app/packages/queries/storage/github-pull-requests.ts
@@ -51,6 +51,8 @@ function toStorageGithubPullRequest(
): GithubPullRequest {
return {
additions: pullRequest.additions,
+ checks: pullRequest.checks,
+ comments: pullRequest.comments,
deletions: pullRequest.deletions,
displayName: pullRequest.displayName,
githubKey: pullRequest.githubKey,
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequest.ts b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequest.ts
index f94266c97a..df9232695a 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequest.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequest.ts
@@ -5,6 +5,8 @@
* OpenAPI spec version: 0.1.0
*/
import type { EnrichedGithubPullRequestAdditions } from './enrichedGithubPullRequestAdditions';
+import type { EnrichedGithubPullRequestChecks } from './enrichedGithubPullRequestChecks';
+import type { EnrichedGithubPullRequestComments } from './enrichedGithubPullRequestComments';
import type { EnrichedGithubPullRequestDeletions } from './enrichedGithubPullRequestDeletions';
import type { EnrichedGithubPullRequestName } from './enrichedGithubPullRequestName';
import type { EnrichedGithubPullRequestStatus } from './enrichedGithubPullRequestStatus';
@@ -18,6 +20,10 @@ export interface EnrichedGithubPullRequest {
* @minimum 0
*/
additions?: EnrichedGithubPullRequestAdditions;
+ /** Check runs collected from the pull request head commit, when enrichment includes them. */
+ checks?: EnrichedGithubPullRequestChecks;
+ /** Comments collected from the pull request, when enrichment includes them. */
+ comments?: EnrichedGithubPullRequestComments;
/**
* The number of deleted lines reported by GitHub, when enrichment succeeds.
* @minimum 0
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestChecks.ts b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestChecks.ts
new file mode 100644
index 0000000000..f1e11f0162
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestChecks.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCheckRun } from './githubPullRequestCheckRun';
+
+/**
+ * Check runs collected from the pull request head commit, when enrichment includes them.
+ */
+export type EnrichedGithubPullRequestChecks =
+ | GithubPullRequestCheckRun[]
+ | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestComments.ts b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestComments.ts
new file mode 100644
index 0000000000..ba5f2c1241
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/enrichedGithubPullRequestComments.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestComment } from './githubPullRequestComment';
+
+/**
+ * Comments collected from the pull request, when enrichment includes them.
+ */
+export type EnrichedGithubPullRequestComments =
+ | GithubPullRequestComment[]
+ | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRun.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRun.ts
new file mode 100644
index 0000000000..9de255da19
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRun.ts
@@ -0,0 +1,33 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCheckRunCompletedAt } from './githubPullRequestCheckRunCompletedAt';
+import type { GithubPullRequestCheckRunConclusion } from './githubPullRequestCheckRunConclusion';
+import type { GithubPullRequestCheckRunStartedAt } from './githubPullRequestCheckRunStartedAt';
+import type { GithubPullRequestCheckRunUrl } from './githubPullRequestCheckRunUrl';
+
+/**
+ * A check run associated with a GitHub pull request.
+ */
+export interface GithubPullRequestCheckRun {
+ /** When the check run completed, when available. */
+ completedAt?: GithubPullRequestCheckRunCompletedAt;
+ /** The raw GitHub check run conclusion, when the run has completed. */
+ conclusion?: GithubPullRequestCheckRunConclusion;
+ /**
+ * The unique GitHub identifier for the check run.
+ * @minimum 0
+ */
+ id: number;
+ /** The check run name. */
+ name: string;
+ /** When the check run started, when available. */
+ startedAt?: GithubPullRequestCheckRunStartedAt;
+ /** The raw GitHub check run status. */
+ status: string;
+ /** The public GitHub URL for the check run, when available. */
+ url?: GithubPullRequestCheckRunUrl;
+}
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunCompletedAt.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunCompletedAt.ts
new file mode 100644
index 0000000000..a86d04cac1
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunCompletedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the check run completed, when available.
+ */
+export type GithubPullRequestCheckRunCompletedAt = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunConclusion.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunConclusion.ts
new file mode 100644
index 0000000000..191fb9ab99
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunConclusion.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The raw GitHub check run conclusion, when the run has completed.
+ */
+export type GithubPullRequestCheckRunConclusion = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunStartedAt.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunStartedAt.ts
new file mode 100644
index 0000000000..850cae0278
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunStartedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the check run started, when available.
+ */
+export type GithubPullRequestCheckRunStartedAt = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunUrl.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunUrl.ts
new file mode 100644
index 0000000000..fb5ba40651
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCheckRunUrl.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The public GitHub URL for the check run, when available.
+ */
+export type GithubPullRequestCheckRunUrl = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestComment.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestComment.ts
new file mode 100644
index 0000000000..2cee3177d2
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestComment.ts
@@ -0,0 +1,36 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCommentAuthorAssociation } from './githubPullRequestCommentAuthorAssociation';
+import type { GithubPullRequestCommentAuthorLogin } from './githubPullRequestCommentAuthorLogin';
+import type { GithubPullRequestCommentCreatedAt } from './githubPullRequestCommentCreatedAt';
+import type { GithubPullRequestCommentUpdatedAt } from './githubPullRequestCommentUpdatedAt';
+import type { GithubPullRequestCommentUrl } from './githubPullRequestCommentUrl';
+
+/**
+ * A comment associated with a GitHub pull request.
+ */
+export interface GithubPullRequestComment {
+ /** GitHub's relationship label for the author, when available. */
+ authorAssociation?: GithubPullRequestCommentAuthorAssociation;
+ /** The GitHub login for the comment author, when available. */
+ authorLogin?: GithubPullRequestCommentAuthorLogin;
+ /** The comment or review body text. */
+ body: string;
+ /** When the comment was created or the review was submitted. */
+ createdAt?: GithubPullRequestCommentCreatedAt;
+ /**
+ * The unique GitHub identifier for the comment or review.
+ * @minimum 0
+ */
+ id: number;
+ /** The GitHub source for the comment, such as `issue_comment` or `review_comment`. */
+ source: string;
+ /** When the comment or review was last updated. */
+ updatedAt?: GithubPullRequestCommentUpdatedAt;
+ /** The public GitHub URL for the comment or review, when available. */
+ url?: GithubPullRequestCommentUrl;
+}
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorAssociation.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorAssociation.ts
new file mode 100644
index 0000000000..9142918986
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorAssociation.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * GitHub's relationship label for the author, when available.
+ */
+export type GithubPullRequestCommentAuthorAssociation = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorLogin.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorLogin.ts
new file mode 100644
index 0000000000..6651ffa875
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentAuthorLogin.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The GitHub login for the comment author, when available.
+ */
+export type GithubPullRequestCommentAuthorLogin = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentCreatedAt.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentCreatedAt.ts
new file mode 100644
index 0000000000..8305c61f56
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentCreatedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the comment was created or the review was submitted.
+ */
+export type GithubPullRequestCommentCreatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUpdatedAt.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUpdatedAt.ts
new file mode 100644
index 0000000000..709f80ebb4
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUpdatedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the comment or review was last updated.
+ */
+export type GithubPullRequestCommentUpdatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUrl.ts b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUrl.ts
new file mode 100644
index 0000000000..451342dbcb
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/githubPullRequestCommentUrl.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The public GitHub URL for the comment or review, when available.
+ */
+export type GithubPullRequestCommentUrl = string | null;
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
index 0ca6ed983a..6be1f0c986 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
@@ -23,6 +23,8 @@ export * from './createUserRequest';
export * from './emptyResponse';
export * from './enrichedGithubPullRequest';
export * from './enrichedGithubPullRequestAdditions';
+export * from './enrichedGithubPullRequestChecks';
+export * from './enrichedGithubPullRequestComments';
export * from './enrichedGithubPullRequestDeletions';
export * from './enrichedGithubPullRequestName';
export * from './enrichedGithubPullRequestStatus';
@@ -39,6 +41,17 @@ export * from './getProfilePicturesRequestBody';
export * from './getUserInfo';
export * from './getUserInfoOrganizationId';
export * from './getUserLinkExistsParams';
+export * from './githubPullRequestCheckRun';
+export * from './githubPullRequestCheckRunCompletedAt';
+export * from './githubPullRequestCheckRunConclusion';
+export * from './githubPullRequestCheckRunStartedAt';
+export * from './githubPullRequestCheckRunUrl';
+export * from './githubPullRequestComment';
+export * from './githubPullRequestCommentAuthorAssociation';
+export * from './githubPullRequestCommentAuthorLogin';
+export * from './githubPullRequestCommentCreatedAt';
+export * from './githubPullRequestCommentUpdatedAt';
+export * from './githubPullRequestCommentUrl';
export * from './githubPullRequestRef';
export * from './githubPullRequestStatus';
export * from './initGithubLinkParams';
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index 0119569159..43799d8f90 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -3500,6 +3500,20 @@
"description": "The number of added lines reported by GitHub, when enrichment succeeds.",
"minimum": 0
},
+ "checks": {
+ "type": ["array", "null"],
+ "items": {
+ "$ref": "#/components/schemas/GithubPullRequestCheckRun"
+ },
+ "description": "Check runs collected from the pull request head commit, when enrichment includes them."
+ },
+ "comments": {
+ "type": ["array", "null"],
+ "items": {
+ "$ref": "#/components/schemas/GithubPullRequestComment"
+ },
+ "description": "Comments collected from the pull request, when enrichment includes them."
+ },
"deletions": {
"type": ["integer", "null"],
"format": "int64",
@@ -3696,6 +3710,88 @@
}
}
},
+ "GithubPullRequestCheckRun": {
+ "type": "object",
+ "description": "A check run associated with a GitHub pull request.",
+ "required": ["id", "name", "status"],
+ "properties": {
+ "completedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the check run completed, when available."
+ },
+ "conclusion": {
+ "type": ["string", "null"],
+ "description": "The raw GitHub check run conclusion, when the run has completed."
+ },
+ "id": {
+ "type": "integer",
+ "format": "int64",
+ "description": "The unique GitHub identifier for the check run.",
+ "minimum": 0
+ },
+ "name": {
+ "type": "string",
+ "description": "The check run name."
+ },
+ "startedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the check run started, when available."
+ },
+ "status": {
+ "type": "string",
+ "description": "The raw GitHub check run status."
+ },
+ "url": {
+ "type": ["string", "null"],
+ "description": "The public GitHub URL for the check run, when available."
+ }
+ }
+ },
+ "GithubPullRequestComment": {
+ "type": "object",
+ "description": "A comment associated with a GitHub pull request.",
+ "required": ["id", "body", "source"],
+ "properties": {
+ "authorAssociation": {
+ "type": ["string", "null"],
+ "description": "GitHub's relationship label for the author, when available."
+ },
+ "authorLogin": {
+ "type": ["string", "null"],
+ "description": "The GitHub login for the comment author, when available."
+ },
+ "body": {
+ "type": "string",
+ "description": "The comment or review body text."
+ },
+ "createdAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the comment was created or the review was submitted."
+ },
+ "id": {
+ "type": "integer",
+ "format": "int64",
+ "description": "The unique GitHub identifier for the comment or review.",
+ "minimum": 0
+ },
+ "source": {
+ "type": "string",
+ "description": "The GitHub source for the comment, such as `issue_comment` or `review_comment`."
+ },
+ "updatedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the comment or review was last updated."
+ },
+ "url": {
+ "type": ["string", "null"],
+ "description": "The public GitHub URL for the comment or review, when available."
+ }
+ }
+ },
"GithubPullRequestRef": {
"type": "object",
"description": "A pull request reference that can be enriched with live GitHub data.",
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequest.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequest.ts
index 6a4c1a29f3..3da2adee18 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequest.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequest.ts
@@ -5,6 +5,8 @@
* OpenAPI spec version: 0.1.0
*/
import type { GithubPullRequestAdditions } from './githubPullRequestAdditions';
+import type { GithubPullRequestChecks } from './githubPullRequestChecks';
+import type { GithubPullRequestComments } from './githubPullRequestComments';
import type { GithubPullRequestDeletions } from './githubPullRequestDeletions';
import type { GithubPullRequestName } from './githubPullRequestName';
import type { GithubPullRequestStatus } from './githubPullRequestStatus';
@@ -18,6 +20,10 @@ export interface GithubPullRequest {
* @minimum 0
*/
additions?: GithubPullRequestAdditions;
+ /** Check runs collected from the pull request head commit, when enrichment data is available. */
+ checks?: GithubPullRequestChecks;
+ /** Comments collected from the pull request, when enrichment data is available. */
+ comments?: GithubPullRequestComments;
/**
* The number of deleted lines in the pull request, when enrichment data is available.
* @minimum 0
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRun.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRun.ts
new file mode 100644
index 0000000000..7e74fa5118
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRun.ts
@@ -0,0 +1,33 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCheckRunCompletedAt } from './githubPullRequestCheckRunCompletedAt';
+import type { GithubPullRequestCheckRunConclusion } from './githubPullRequestCheckRunConclusion';
+import type { GithubPullRequestCheckRunStartedAt } from './githubPullRequestCheckRunStartedAt';
+import type { GithubPullRequestCheckRunUrl } from './githubPullRequestCheckRunUrl';
+
+/**
+ * A check run associated with a GitHub pull request.
+ */
+export interface GithubPullRequestCheckRun {
+ /** When the check run completed, when available. */
+ completedAt?: GithubPullRequestCheckRunCompletedAt;
+ /** The raw GitHub check run conclusion, when the run has completed. */
+ conclusion?: GithubPullRequestCheckRunConclusion;
+ /**
+ * The unique GitHub identifier for the check run.
+ * @minimum 0
+ */
+ id: number;
+ /** The check run name. */
+ name: string;
+ /** When the check run started, when available. */
+ startedAt?: GithubPullRequestCheckRunStartedAt;
+ /** The raw GitHub check run status. */
+ status: string;
+ /** The public GitHub URL for the check run, when available. */
+ url?: GithubPullRequestCheckRunUrl;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunCompletedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunCompletedAt.ts
new file mode 100644
index 0000000000..f36b768955
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunCompletedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the check run completed, when available.
+ */
+export type GithubPullRequestCheckRunCompletedAt = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunConclusion.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunConclusion.ts
new file mode 100644
index 0000000000..f9b877fd4c
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunConclusion.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The raw GitHub check run conclusion, when the run has completed.
+ */
+export type GithubPullRequestCheckRunConclusion = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunStartedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunStartedAt.ts
new file mode 100644
index 0000000000..5bfbaf85d5
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunStartedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the check run started, when available.
+ */
+export type GithubPullRequestCheckRunStartedAt = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunUrl.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunUrl.ts
new file mode 100644
index 0000000000..b0e713f733
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCheckRunUrl.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The public GitHub URL for the check run, when available.
+ */
+export type GithubPullRequestCheckRunUrl = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestChecks.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestChecks.ts
new file mode 100644
index 0000000000..3980b09e6b
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestChecks.ts
@@ -0,0 +1,12 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCheckRun } from './githubPullRequestCheckRun';
+
+/**
+ * Check runs collected from the pull request head commit, when enrichment data is available.
+ */
+export type GithubPullRequestChecks = GithubPullRequestCheckRun[] | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComment.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComment.ts
new file mode 100644
index 0000000000..3d3e9ea483
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComment.ts
@@ -0,0 +1,36 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestCommentAuthorAssociation } from './githubPullRequestCommentAuthorAssociation';
+import type { GithubPullRequestCommentAuthorLogin } from './githubPullRequestCommentAuthorLogin';
+import type { GithubPullRequestCommentCreatedAt } from './githubPullRequestCommentCreatedAt';
+import type { GithubPullRequestCommentUpdatedAt } from './githubPullRequestCommentUpdatedAt';
+import type { GithubPullRequestCommentUrl } from './githubPullRequestCommentUrl';
+
+/**
+ * A comment associated with a GitHub pull request.
+ */
+export interface GithubPullRequestComment {
+ /** GitHub's relationship label for the author, when available. */
+ authorAssociation?: GithubPullRequestCommentAuthorAssociation;
+ /** The GitHub login for the comment author, when available. */
+ authorLogin?: GithubPullRequestCommentAuthorLogin;
+ /** The comment or review body text. */
+ body: string;
+ /** When the comment was created or the review was submitted. */
+ createdAt?: GithubPullRequestCommentCreatedAt;
+ /**
+ * The unique GitHub identifier for the comment or review.
+ * @minimum 0
+ */
+ id: number;
+ /** The GitHub source for the comment, such as `issue_comment` or `review_comment`. */
+ source: string;
+ /** When the comment or review was last updated. */
+ updatedAt?: GithubPullRequestCommentUpdatedAt;
+ /** The public GitHub URL for the comment or review, when available. */
+ url?: GithubPullRequestCommentUrl;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorAssociation.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorAssociation.ts
new file mode 100644
index 0000000000..f531b8ccce
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorAssociation.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * GitHub's relationship label for the author, when available.
+ */
+export type GithubPullRequestCommentAuthorAssociation = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorLogin.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorLogin.ts
new file mode 100644
index 0000000000..f7e151f0a6
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentAuthorLogin.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The GitHub login for the comment author, when available.
+ */
+export type GithubPullRequestCommentAuthorLogin = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentCreatedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentCreatedAt.ts
new file mode 100644
index 0000000000..121ffd4d83
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentCreatedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the comment was created or the review was submitted.
+ */
+export type GithubPullRequestCommentCreatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUpdatedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUpdatedAt.ts
new file mode 100644
index 0000000000..f2d42e9889
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUpdatedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the comment or review was last updated.
+ */
+export type GithubPullRequestCommentUpdatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUrl.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUrl.ts
new file mode 100644
index 0000000000..787826f06a
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestCommentUrl.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The public GitHub URL for the comment or review, when available.
+ */
+export type GithubPullRequestCommentUrl = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComments.ts b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComments.ts
new file mode 100644
index 0000000000..01174f0727
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/githubPullRequestComments.ts
@@ -0,0 +1,12 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { GithubPullRequestComment } from './githubPullRequestComment';
+
+/**
+ * Comments collected from the pull request, when enrichment data is available.
+ */
+export type GithubPullRequestComments = GithubPullRequestComment[] | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index 15d681d6fb..331a002905 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -510,6 +510,19 @@ export * from './getUserDocumentsHandlerParams';
export * from './getUserHistoryResponse';
export * from './githubPullRequest';
export * from './githubPullRequestAdditions';
+export * from './githubPullRequestCheckRun';
+export * from './githubPullRequestCheckRunCompletedAt';
+export * from './githubPullRequestCheckRunConclusion';
+export * from './githubPullRequestCheckRunStartedAt';
+export * from './githubPullRequestCheckRunUrl';
+export * from './githubPullRequestChecks';
+export * from './githubPullRequestComment';
+export * from './githubPullRequestCommentAuthorAssociation';
+export * from './githubPullRequestCommentAuthorLogin';
+export * from './githubPullRequestCommentCreatedAt';
+export * from './githubPullRequestComments';
+export * from './githubPullRequestCommentUpdatedAt';
+export * from './githubPullRequestCommentUrl';
export * from './githubPullRequestDeletions';
export * from './githubPullRequestName';
export * from './githubPullRequestStatus';
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 99ea269777..49d0b02c5d 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -4583,6 +4583,10 @@ export const getDocumentGithubPullRequestsParams = zod.object({
export const getDocumentGithubPullRequestsResponsePullRequestsItemAdditionsMin = 0;
+export const getDocumentGithubPullRequestsResponsePullRequestsItemChecksItemIdMin = 0;
+
+export const getDocumentGithubPullRequestsResponsePullRequestsItemCommentsItemIdMin = 0;
+
export const getDocumentGithubPullRequestsResponsePullRequestsItemDeletionsMin = 0;
export const getDocumentGithubPullRequestsResponsePullRequestsItemNumberMin = 0;
@@ -4602,6 +4606,108 @@ export const getDocumentGithubPullRequestsResponse = zod
.describe(
'The number of added lines in the pull request, when enrichment data is available.'
),
+ checks: zod
+ .array(
+ zod
+ .object({
+ completedAt: zod.iso
+ .datetime({})
+ .nullish()
+ .describe(
+ 'When the check run completed, when available.'
+ ),
+ conclusion: zod
+ .string()
+ .nullish()
+ .describe(
+ 'The raw GitHub check run conclusion, when the run has completed.'
+ ),
+ id: zod
+ .number()
+ .min(
+ getDocumentGithubPullRequestsResponsePullRequestsItemChecksItemIdMin
+ )
+ .describe(
+ 'The unique GitHub identifier for the check run.'
+ ),
+ name: zod.string().describe('The check run name.'),
+ startedAt: zod.iso
+ .datetime({})
+ .nullish()
+ .describe('When the check run started, when available.'),
+ status: zod
+ .string()
+ .describe('The raw GitHub check run status.'),
+ url: zod
+ .string()
+ .nullish()
+ .describe(
+ 'The public GitHub URL for the check run, when available.'
+ ),
+ })
+ .describe(
+ 'A check run associated with a GitHub pull request.'
+ )
+ )
+ .nullish()
+ .describe(
+ 'Check runs collected from the pull request head commit, when enrichment data is available.'
+ ),
+ comments: zod
+ .array(
+ zod
+ .object({
+ authorAssociation: zod
+ .string()
+ .nullish()
+ .describe(
+ "GitHub's relationship label for the author, when available."
+ ),
+ authorLogin: zod
+ .string()
+ .nullish()
+ .describe(
+ 'The GitHub login for the comment author, when available.'
+ ),
+ body: zod
+ .string()
+ .describe('The comment or review body text.'),
+ createdAt: zod.iso
+ .datetime({})
+ .nullish()
+ .describe(
+ 'When the comment was created or the review was submitted.'
+ ),
+ id: zod
+ .number()
+ .min(
+ getDocumentGithubPullRequestsResponsePullRequestsItemCommentsItemIdMin
+ )
+ .describe(
+ 'The unique GitHub identifier for the comment or review.'
+ ),
+ source: zod
+ .string()
+ .describe(
+ 'The GitHub source for the comment, such as `issue_comment` or `review_comment`.'
+ ),
+ updatedAt: zod.iso
+ .datetime({})
+ .nullish()
+ .describe('When the comment or review was last updated.'),
+ url: zod
+ .string()
+ .nullish()
+ .describe(
+ 'The public GitHub URL for the comment or review, when available.'
+ ),
+ })
+ .describe('A comment associated with a GitHub pull request.')
+ )
+ .nullish()
+ .describe(
+ 'Comments collected from the pull request, when enrichment data is available.'
+ ),
deletions: zod
.number()
.min(
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 991a66ae7c..3f5921c538 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -13323,6 +13323,20 @@
"description": "The number of added lines in the pull request, when enrichment data is available.",
"minimum": 0
},
+ "checks": {
+ "type": ["array", "null"],
+ "items": {
+ "$ref": "#/components/schemas/GithubPullRequestCheckRun"
+ },
+ "description": "Check runs collected from the pull request head commit, when enrichment data is available."
+ },
+ "comments": {
+ "type": ["array", "null"],
+ "items": {
+ "$ref": "#/components/schemas/GithubPullRequestComment"
+ },
+ "description": "Comments collected from the pull request, when enrichment data is available."
+ },
"deletions": {
"type": ["integer", "null"],
"format": "int64",
@@ -13365,6 +13379,88 @@
}
}
},
+ "GithubPullRequestCheckRun": {
+ "type": "object",
+ "description": "A check run associated with a GitHub pull request.",
+ "required": ["id", "name", "status"],
+ "properties": {
+ "completedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the check run completed, when available."
+ },
+ "conclusion": {
+ "type": ["string", "null"],
+ "description": "The raw GitHub check run conclusion, when the run has completed."
+ },
+ "id": {
+ "type": "integer",
+ "format": "int64",
+ "description": "The unique GitHub identifier for the check run.",
+ "minimum": 0
+ },
+ "name": {
+ "type": "string",
+ "description": "The check run name."
+ },
+ "startedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the check run started, when available."
+ },
+ "status": {
+ "type": "string",
+ "description": "The raw GitHub check run status."
+ },
+ "url": {
+ "type": ["string", "null"],
+ "description": "The public GitHub URL for the check run, when available."
+ }
+ }
+ },
+ "GithubPullRequestComment": {
+ "type": "object",
+ "description": "A comment associated with a GitHub pull request.",
+ "required": ["id", "body", "source"],
+ "properties": {
+ "authorAssociation": {
+ "type": ["string", "null"],
+ "description": "GitHub's relationship label for the author, when available."
+ },
+ "authorLogin": {
+ "type": ["string", "null"],
+ "description": "The GitHub login for the comment author, when available."
+ },
+ "body": {
+ "type": "string",
+ "description": "The comment or review body text."
+ },
+ "createdAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the comment was created or the review was submitted."
+ },
+ "id": {
+ "type": "integer",
+ "format": "int64",
+ "description": "The unique GitHub identifier for the comment or review.",
+ "minimum": 0
+ },
+ "source": {
+ "type": "string",
+ "description": "The GitHub source for the comment, such as `issue_comment` or `review_comment`."
+ },
+ "updatedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the comment or review was last updated."
+ },
+ "url": {
+ "type": ["string", "null"],
+ "description": "The public GitHub URL for the comment or review, when available."
+ }
+ }
+ },
"GithubPullRequestsResponse": {
"type": "object",
"description": "Response containing all GitHub pull requests associated with a task.",
diff --git a/rust/cloud-storage/authentication_service/src/api/swagger.rs b/rust/cloud-storage/authentication_service/src/api/swagger.rs
index 45bfacbd38..c387a5e7f0 100644
--- a/rust/cloud-storage/authentication_service/src/api/swagger.rs
+++ b/rust/cloud-storage/authentication_service/src/api/swagger.rs
@@ -1,6 +1,7 @@
use github::domain::models::{
EnrichGithubPullRequestsProxyRequest, EnrichGithubPullRequestsResponse,
- EnrichedGithubPullRequest, GithubPullRequestRef, GithubPullRequestStatus,
+ EnrichedGithubPullRequest, GithubPullRequestCheckRun, GithubPullRequestComment,
+ GithubPullRequestRef, GithubPullRequestStatus,
};
use model::authentication::login::request::{AppleLoginRequest, PasswordRequest};
use teams::domain::model::{
@@ -181,6 +182,8 @@ use model::user::{
EnrichGithubPullRequestsProxyRequest,
EnrichGithubPullRequestsResponse,
EnrichedGithubPullRequest,
+ GithubPullRequestCheckRun,
+ GithubPullRequestComment,
GithubPullRequestRef,
GithubPullRequestStatus,
@@ -260,6 +263,8 @@ mod tests {
"EnrichGithubPullRequestsProxyRequest",
"EnrichGithubPullRequestsResponse",
"EnrichedGithubPullRequest",
+ "GithubPullRequestCheckRun",
+ "GithubPullRequestComment",
"GithubPullRequestRef",
"GithubPullRequestStatus",
] {
@@ -272,5 +277,9 @@ mod tests {
let request_properties = &schemas["EnrichGithubPullRequestsProxyRequest"]["properties"];
assert!(request_properties.get("pullRequests").is_some());
assert!(request_properties.get("macroUserId").is_none());
+
+ let response_properties = &schemas["EnrichedGithubPullRequest"]["properties"];
+ assert!(response_properties.get("comments").is_some());
+ assert!(response_properties.get("checks").is_some());
}
}
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 0bca087d46..147d3e64d2 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -509,6 +509,8 @@ use utoipa::OpenApi;
BranchNameResponse,
ShortIdResponse,
documents_hex::domain::models::GithubPullRequest,
+ documents_hex::domain::models::GithubPullRequestCheckRun,
+ documents_hex::domain::models::GithubPullRequestComment,
documents_hex::domain::models::GithubPullRequestsResponse,
// Sync service
diff --git a/rust/cloud-storage/documents/src/domain/models.rs b/rust/cloud-storage/documents/src/domain/models.rs
index 553037f30f..ea0cae9528 100644
--- a/rust/cloud-storage/documents/src/domain/models.rs
+++ b/rust/cloud-storage/documents/src/domain/models.rs
@@ -103,6 +103,50 @@ pub struct TaskBranchName {
pub branch_name: String,
}
+/// A comment associated with a GitHub pull request.
+#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, Clone)]
+#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GithubPullRequestComment {
+ /// The unique GitHub identifier for the comment or review.
+ pub id: u64,
+ /// The comment or review body text.
+ pub body: String,
+ /// The GitHub login for the comment author, when available.
+ pub author_login: Option<String>,
+ /// GitHub's relationship label for the author, when available.
+ pub author_association: Option<String>,
+ /// The public GitHub URL for the comment or review, when available.
+ pub url: Option<String>,
+ /// When the comment was created or the review was submitted.
+ pub created_at: Option<DateTime<Utc>>,
+ /// When the comment or review was last updated.
+ pub updated_at: Option<DateTime<Utc>>,
+ /// The GitHub source for the comment, such as `issue_comment` or `review_comment`.
+ pub source: String,
+}
+
+/// A check run associated with a GitHub pull request.
+#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, Clone)]
+#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GithubPullRequestCheckRun {
+ /// The unique GitHub identifier for the check run.
+ pub id: u64,
+ /// The check run name.
+ pub name: String,
+ /// The raw GitHub check run status.
+ pub status: String,
+ /// The raw GitHub check run conclusion, when the run has completed.
+ pub conclusion: Option<String>,
+ /// The public GitHub URL for the check run, when available.
+ pub url: Option<String>,
+ /// When the check run started, when available.
+ pub started_at: Option<DateTime<Utc>>,
+ /// When the check run completed, when available.
+ pub completed_at: Option<DateTime<Utc>>,
+}
+
/// Display-ready data for a GitHub pull request associated with a task.
#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, Clone)]
#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
@@ -132,6 +176,12 @@ pub struct GithubPullRequest {
/// The number of deleted lines in the pull request, when enrichment data is available.
#[serde(skip_serializing_if = "Option::is_none")]
pub deletions: Option<u64>,
+ /// Comments collected from the pull request, when enrichment data is available.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub comments: Option<Vec<GithubPullRequestComment>>,
+ /// Check runs collected from the pull request head commit, when enrichment data is available.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub checks: Option<Vec<GithubPullRequestCheckRun>>,
}
impl GithubPullRequest {
@@ -167,6 +217,8 @@ impl GithubPullRequest {
status: None,
additions: None,
deletions: None,
+ comments: None,
+ checks: None,
})
}
}
diff --git a/rust/cloud-storage/documents/src/domain/service/tests.rs b/rust/cloud-storage/documents/src/domain/service/tests.rs
index 5c3365d7ba..49087b2889 100644
--- a/rust/cloud-storage/documents/src/domain/service/tests.rs
+++ b/rust/cloud-storage/documents/src/domain/service/tests.rs
@@ -231,6 +231,12 @@ fn assert_raw_pull_request(
assert!(pull_request.status.is_none());
assert!(pull_request.additions.is_none());
assert!(pull_request.deletions.is_none());
+ assert!(pull_request.comments.is_none());
+ assert!(pull_request.checks.is_none());
+
+ let pull_request_json = serde_json::to_value(pull_request).unwrap();
+ assert!(pull_request_json.get("comments").is_none());
+ assert!(pull_request_json.get("checks").is_none());
}
#[tokio::test]
diff --git a/rust/cloud-storage/documents/src/inbound/axum_router/get_github_pull_requests.rs b/rust/cloud-storage/documents/src/inbound/axum_router/get_github_pull_requests.rs
index 4ea6bc9e5f..4e81735f15 100644
--- a/rust/cloud-storage/documents/src/inbound/axum_router/get_github_pull_requests.rs
+++ b/rust/cloud-storage/documents/src/inbound/axum_router/get_github_pull_requests.rs
@@ -58,6 +58,8 @@ mod tests {
paths(super::get_github_pull_requests_handler),
components(schemas(
crate::domain::models::GithubPullRequest,
+ crate::domain::models::GithubPullRequestCheckRun,
+ crate::domain::models::GithubPullRequestComment,
crate::domain::models::GithubPullRequestsResponse,
))
)]
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
index b4473a5eac..5d616af2b4 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
@@ -1007,6 +1007,8 @@ async fn test_get_github_pull_request_keys_orders_and_parses(pool: Pool<Postgres
status: None,
additions: None,
deletions: None,
+ comments: None,
+ checks: None,
},
GithubPullRequest {
github_key: "macro/macro/pull/10".to_string(),
@@ -1019,6 +1021,8 @@ async fn test_get_github_pull_request_keys_orders_and_parses(pool: Pool<Postgres
status: None,
additions: None,
deletions: None,
+ comments: None,
+ checks: None,
},
GithubPullRequest {
github_key: "macro/macro/pull/20".to_string(),
@@ -1031,6 +1035,8 @@ async fn test_get_github_pull_request_keys_orders_and_parses(pool: Pool<Postgres
status: None,
additions: None,
deletions: None,
+ comments: None,
+ checks: None,
},
]
);
diff --git a/rust/cloud-storage/github/src/domain/models/mod.rs b/rust/cloud-storage/github/src/domain/models/mod.rs
index 87993d198d..1c016f7fa6 100644
--- a/rust/cloud-storage/github/src/domain/models/mod.rs
+++ b/rust/cloud-storage/github/src/domain/models/mod.rs
@@ -10,8 +10,8 @@ mod sync;
pub use link::{GithubAccessToken, GithubExchangeTokenResponse, GithubLink, GithubUserInfo};
pub use pull_request::{
EnrichGithubPullRequestsProxyRequest, EnrichGithubPullRequestsResponse,
- EnrichedGithubPullRequest, GithubPullRequestDetails, GithubPullRequestRef,
- GithubPullRequestStatus,
+ EnrichedGithubPullRequest, GithubPullRequestCheckRun, GithubPullRequestComment,
+ GithubPullRequestDetails, GithubPullRequestRef, GithubPullRequestStatus,
};
pub use sync::{
GithubAppInstallationSource, GithubInstallationAccessToken, GithubKey, GithubWebhookEventType,
diff --git a/rust/cloud-storage/github/src/domain/models/pull_request.rs b/rust/cloud-storage/github/src/domain/models/pull_request.rs
index 3fe6c5005b..d6f8c37d9f 100644
--- a/rust/cloud-storage/github/src/domain/models/pull_request.rs
+++ b/rust/cloud-storage/github/src/domain/models/pull_request.rs
@@ -66,6 +66,70 @@ impl fmt::Display for GithubPullRequestStatus {
}
}
+fn deserialize_optional_array<'de, D, T>(deserializer: D) -> Result<Option<Vec<T>>, D::Error>
+where
+ D: serde::Deserializer<'de>,
+ T: serde::de::DeserializeOwned,
+{
+ let value = serde_json::Value::deserialize(deserializer)?;
+
+ if value.is_null() {
+ return Ok(None);
+ }
+
+ if !value.is_array() {
+ return Ok(None);
+ }
+
+ Vec::<T>::deserialize(value)
+ .map(Some)
+ .map_err(serde::de::Error::custom)
+}
+
+/// A comment associated with a GitHub pull request.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GithubPullRequestComment {
+ /// The unique GitHub identifier for the comment or review.
+ pub id: u64,
+ /// The comment or review body text.
+ pub body: String,
+ /// The GitHub login for the comment author, when available.
+ pub author_login: Option<String>,
+ /// GitHub's relationship label for the author, when available.
+ pub author_association: Option<String>,
+ /// The public GitHub URL for the comment or review, when available.
+ pub url: Option<String>,
+ /// When the comment was created or the review was submitted.
+ pub created_at: Option<chrono::DateTime<chrono::Utc>>,
+ /// When the comment or review was last updated.
+ pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
+ /// The GitHub source for the comment, such as `issue_comment` or `review_comment`.
+ pub source: String,
+}
+
+/// A check run associated with a GitHub pull request.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GithubPullRequestCheckRun {
+ /// The unique GitHub identifier for the check run.
+ pub id: u64,
+ /// The check run name.
+ pub name: String,
+ /// The raw GitHub check run status.
+ pub status: String,
+ /// The raw GitHub check run conclusion, when the run has completed.
+ pub conclusion: Option<String>,
+ /// The public GitHub URL for the check run, when available.
+ pub url: Option<String>,
+ /// When the check run started, when available.
+ pub started_at: Option<chrono::DateTime<chrono::Utc>>,
+ /// When the check run completed, when available.
+ pub completed_at: Option<chrono::DateTime<chrono::Utc>>,
+}
+
/// GitHub API pull request details used to enrich a pull request reference.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "axum", derive(utoipa::ToSchema))]
@@ -80,6 +144,20 @@ pub struct GithubPullRequestDetails {
pub additions: u64,
/// The number of deleted lines reported by GitHub.
pub deletions: u64,
+ /// Comments collected from the pull request, when enrichment includes them.
+ #[serde(
+ default,
+ skip_serializing_if = "Option::is_none",
+ deserialize_with = "deserialize_optional_array"
+ )]
+ pub comments: Option<Vec<GithubPullRequestComment>>,
+ /// Check runs collected from the pull request head commit, when enrichment includes them.
+ #[serde(
+ default,
+ skip_serializing_if = "Option::is_none",
+ deserialize_with = "deserialize_optional_array"
+ )]
+ pub checks: Option<Vec<GithubPullRequestCheckRun>>,
}
impl GithubPullRequestDetails {
@@ -114,6 +192,12 @@ pub struct EnrichedGithubPullRequest {
pub additions: Option<u64>,
/// The number of deleted lines reported by GitHub, when enrichment succeeds.
pub deletions: Option<u64>,
+ /// Comments collected from the pull request, when enrichment includes them.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub comments: Option<Vec<GithubPullRequestComment>>,
+ /// Check runs collected from the pull request head commit, when enrichment includes them.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub checks: Option<Vec<GithubPullRequestCheckRun>>,
}
impl EnrichedGithubPullRequest {
@@ -130,6 +214,8 @@ impl EnrichedGithubPullRequest {
status: None,
additions: None,
deletions: None,
+ comments: None,
+ checks: None,
}
}
@@ -151,6 +237,8 @@ impl EnrichedGithubPullRequest {
status: Some(status),
additions: Some(details.additions),
deletions: Some(details.deletions),
+ comments: details.comments,
+ checks: details.checks,
}
}
}
diff --git a/rust/cloud-storage/github/src/domain/models/sync.rs b/rust/cloud-storage/github/src/domain/models/sync.rs
index ac4ae17b49..0da55454cb 100644
--- a/rust/cloud-storage/github/src/domain/models/sync.rs
+++ b/rust/cloud-storage/github/src/domain/models/sync.rs
@@ -131,7 +131,9 @@ impl ValidatedGithubWebhookEvent {
texts.push(s.to_string());
}
}
- GithubWebhookEventType::Installation | GithubWebhookEventType::Unknown(_) => {}
+ GithubWebhookEventType::CheckRun
+ | GithubWebhookEventType::Installation
+ | GithubWebhookEventType::Unknown(_) => {}
}
texts
}
@@ -183,7 +185,9 @@ impl ValidatedGithubWebhookEvent {
if is_open { Some("In Review") } else { None }
}
- GithubWebhookEventType::Installation | GithubWebhookEventType::Unknown(_) => None,
+ GithubWebhookEventType::CheckRun
+ | GithubWebhookEventType::Installation
+ | GithubWebhookEventType::Unknown(_) => None,
}
}
@@ -197,9 +201,35 @@ impl ValidatedGithubWebhookEvent {
.get("issue")
.and_then(|issue| issue.get("number"))
})
+ .or_else(|| {
+ self.payload
+ .get("check_run")
+ .and_then(|check_run| check_run.get("pull_requests"))
+ .and_then(|pull_requests| pull_requests.as_array())
+ .and_then(|pull_requests| pull_requests.first())
+ .and_then(|pull_request| pull_request.get("number"))
+ })
.and_then(|v| v.as_u64())
}
+ /// Returns whether this webhook payload is associated with a pull request.
+ pub fn is_associated_with_pull_request(&self) -> bool {
+ match self.parsed_event_type() {
+ GithubWebhookEventType::PullRequest => self.payload.get("pull_request").is_some(),
+ GithubWebhookEventType::IssueComment => self
+ .payload
+ .get("issue")
+ .and_then(|issue| issue.get("pull_request"))
+ .is_some(),
+ GithubWebhookEventType::PullRequestReview
+ | GithubWebhookEventType::PullRequestReviewComment => {
+ self.payload.get("pull_request").is_some()
+ }
+ GithubWebhookEventType::CheckRun => self.pull_number().is_some(),
+ GithubWebhookEventType::Installation | GithubWebhookEventType::Unknown(_) => false,
+ }
+ }
+
/// Extract the repository owner login from the webhook payload.
pub fn repo_owner(&self) -> Option<&str> {
self.payload
@@ -248,6 +278,7 @@ impl ValidatedGithubWebhookEvent {
let pr = match self.parsed_event_type() {
// For PR events, the event itself is the context — nothing to compare against.
GithubWebhookEventType::PullRequest
+ | GithubWebhookEventType::CheckRun
| GithubWebhookEventType::Installation
| GithubWebhookEventType::Unknown(_) => {
return texts;
@@ -290,6 +321,8 @@ pub enum GithubWebhookEventType {
PullRequestReview,
/// `pull_request_review_comment` events
PullRequestReviewComment,
+ /// `check_run` events
+ CheckRun,
/// `installation` events (app installed/uninstalled)
Installation,
/// Any event type we don't handle
@@ -304,6 +337,7 @@ impl GithubWebhookEventType {
"issue_comment" => Self::IssueComment,
"pull_request_review" => Self::PullRequestReview,
"pull_request_review_comment" => Self::PullRequestReviewComment,
+ "check_run" => Self::CheckRun,
"installation" => Self::Installation,
other => Self::Unknown(other.to_string()),
}
diff --git a/rust/cloud-storage/github/src/domain/models/test.rs b/rust/cloud-storage/github/src/domain/models/test.rs
index 90f2d27958..f20e8551d9 100644
--- a/rust/cloud-storage/github/src/domain/models/test.rs
+++ b/rust/cloud-storage/github/src/domain/models/test.rs
@@ -28,6 +28,39 @@ fn pull_request_details(
merged_at,
additions: 42,
deletions: 12,
+ comments: None,
+ checks: None,
+ }
+}
+
+fn utc_datetime(value: &str) -> chrono::DateTime<chrono::Utc> {
+ chrono::DateTime::parse_from_rfc3339(value)
+ .unwrap()
+ .with_timezone(&chrono::Utc)
+}
+
+fn pull_request_comment() -> GithubPullRequestComment {
+ GithubPullRequestComment {
+ id: 101,
+ body: "Looks good to me".to_string(),
+ author_login: Some("octocat".to_string()),
+ author_association: Some("MEMBER".to_string()),
+ url: Some("https://github.com/macro/app/pull/7#issuecomment-101".to_string()),
+ created_at: Some(utc_datetime("2026-05-25T18:54:21Z")),
+ updated_at: Some(utc_datetime("2026-05-25T19:00:00Z")),
+ source: "issue_comment".to_string(),
+ }
+}
+
+fn pull_request_check_run() -> GithubPullRequestCheckRun {
+ GithubPullRequestCheckRun {
+ id: 202,
+ name: "ci".to_string(),
+ status: "completed".to_string(),
+ conclusion: Some("success".to_string()),
+ url: Some("https://github.com/macro/app/actions/runs/202".to_string()),
+ started_at: Some(utc_datetime("2026-05-25T18:55:00Z")),
+ completed_at: Some(utc_datetime("2026-05-25T18:59:00Z")),
}
}
@@ -47,14 +80,29 @@ fn pull_request_status_maps_closed_unmerged_pr() {
#[test]
fn pull_request_status_maps_closed_merged_pr() {
- let merged_at = chrono::DateTime::parse_from_rfc3339("2026-05-25T18:54:21Z")
- .unwrap()
- .with_timezone(&chrono::Utc);
+ let merged_at = utc_datetime("2026-05-25T18:54:21Z");
let details = pull_request_details("closed", Some(merged_at));
assert_eq!(details.status(), GithubPullRequestStatus::Merged);
}
+#[test]
+fn pull_request_details_deserializes_github_comment_count() {
+ let details_json = serde_json::json!({
+ "title": "Add pull request enrichment",
+ "state": "open",
+ "merged_at": null,
+ "additions": 42,
+ "deletions": 12,
+ "comments": 3
+ });
+
+ let details: GithubPullRequestDetails = serde_json::from_value(details_json).unwrap();
+
+ assert_eq!(details.comments, None);
+ assert_eq!(details.checks, None);
+}
+
#[test]
fn pull_request_proxy_request_serializes_with_only_pull_requests() {
let reference = pull_request_reference();
@@ -101,6 +149,8 @@ fn pull_request_response_serializes_with_camel_case_fields() {
status: Some(GithubPullRequestStatus::Merged),
additions: Some(42),
deletions: Some(12),
+ comments: Some(vec![pull_request_comment()]),
+ checks: Some(vec![pull_request_check_run()]),
}],
};
@@ -120,7 +170,30 @@ fn pull_request_response_serializes_with_camel_case_fields() {
"name": "Add pull request enrichment",
"status": "merged",
"additions": 42,
- "deletions": 12
+ "deletions": 12,
+ "comments": [
+ {
+ "id": 101,
+ "body": "Looks good to me",
+ "authorLogin": "octocat",
+ "authorAssociation": "MEMBER",
+ "url": "https://github.com/macro/app/pull/7#issuecomment-101",
+ "createdAt": "2026-05-25T18:54:21Z",
+ "updatedAt": "2026-05-25T19:00:00Z",
+ "source": "issue_comment"
+ }
+ ],
+ "checks": [
+ {
+ "id": 202,
+ "name": "ci",
+ "status": "completed",
+ "conclusion": "success",
+ "url": "https://github.com/macro/app/actions/runs/202",
+ "startedAt": "2026-05-25T18:55:00Z",
+ "completedAt": "2026-05-25T18:59:00Z"
+ }
+ ]
}
]
})
@@ -131,6 +204,33 @@ fn pull_request_response_serializes_with_camel_case_fields() {
assert_eq!(decoded_response, response);
}
+#[test]
+fn pull_request_response_deserializes_without_comments_and_checks() {
+ let response_json = serde_json::json!({
+ "pullRequests": [
+ {
+ "githubKey": "macro/app/pull/7",
+ "owner": "macro",
+ "repo": "app",
+ "number": 7,
+ "url": "https://github.com/macro/app/pull/7",
+ "displayName": "macro/app#7",
+ "name": "Add pull request enrichment",
+ "status": "open",
+ "additions": 42,
+ "deletions": 12
+ }
+ ]
+ });
+
+ let decoded_response: EnrichGithubPullRequestsResponse =
+ serde_json::from_value(response_json).unwrap();
+ let pull_request = decoded_response.pull_requests.first().unwrap();
+
+ assert_eq!(pull_request.comments, None);
+ assert_eq!(pull_request.checks, None);
+}
+
#[test]
fn pull_request_enrichment_preserves_reference_fields() {
let reference = pull_request_reference();
@@ -146,6 +246,46 @@ fn pull_request_enrichment_preserves_reference_fields() {
assert_eq!(enriched.status, None);
assert_eq!(enriched.additions, None);
assert_eq!(enriched.deletions, None);
+ assert_eq!(enriched.comments, None);
+ assert_eq!(enriched.checks, None);
+
+ let enriched_json = serde_json::to_value(&enriched).unwrap();
+ assert!(enriched_json.get("comments").is_none());
+ assert!(enriched_json.get("checks").is_none());
+}
+
+#[test]
+fn pull_request_enrichment_copies_details_fields() {
+ let reference = pull_request_reference();
+ let comments = vec![pull_request_comment()];
+ let checks = vec![pull_request_check_run()];
+ let details = GithubPullRequestDetails {
+ title: "Add pull request enrichment".to_string(),
+ state: "closed".to_string(),
+ merged_at: Some(utc_datetime("2026-05-25T18:54:21Z")),
+ additions: 42,
+ deletions: 12,
+ comments: Some(comments.clone()),
+ checks: Some(checks.clone()),
+ };
+
+ let enriched = EnrichedGithubPullRequest::from_details(reference.clone(), details);
+
+ assert_eq!(enriched.github_key, reference.github_key);
+ assert_eq!(enriched.owner, reference.owner);
+ assert_eq!(enriched.repo, reference.repo);
+ assert_eq!(enriched.number, reference.number);
+ assert_eq!(enriched.url, reference.url);
+ assert_eq!(enriched.display_name, reference.display_name);
+ assert_eq!(
+ enriched.name,
+ Some("Add pull request enrichment".to_string())
+ );
+ assert_eq!(enriched.status, Some(GithubPullRequestStatus::Merged));
+ assert_eq!(enriched.additions, Some(42));
+ assert_eq!(enriched.deletions, Some(12));
+ assert_eq!(enriched.comments, Some(comments));
+ assert_eq!(enriched.checks, Some(checks));
}
// ---------------------------------------------------------------------------
diff --git a/rust/cloud-storage/github/src/domain/ports/sync.rs b/rust/cloud-storage/github/src/domain/ports/sync.rs
index d777a65d4e..573a229371 100644
--- a/rust/cloud-storage/github/src/domain/ports/sync.rs
+++ b/rust/cloud-storage/github/src/domain/ports/sync.rs
@@ -4,7 +4,7 @@ use std::future::Future;
use crate::domain::models::{
GithubAppInstallationSource, GithubError, GithubInstallationAccessToken, GithubKey,
- MacroTaskId, TeamTaskReference, ValidatedGithubWebhookEvent,
+ GithubPullRequestDetails, MacroTaskId, TeamTaskReference, ValidatedGithubWebhookEvent,
};
/// Repository for accessing github sync data from the database.
@@ -97,6 +97,15 @@ pub trait GithubSyncClient: Send + Sync + 'static {
pull_number: u64,
body: &str,
) -> impl Future<Output = Result<(), GithubError>> + Send;
+
+ /// Fetches enriched pull request details using a GitHub App installation token.
+ fn get_pull_request_details(
+ &self,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+ ) -> impl Future<Output = Result<GithubPullRequestDetails, GithubError>> + Send;
}
/// Service interface for github sync operations (webhooks and sync app).
diff --git a/rust/cloud-storage/github/src/domain/service/sync/mod.rs b/rust/cloud-storage/github/src/domain/service/sync/mod.rs
index a8dd2ac27d..da66c83252 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/mod.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/mod.rs
@@ -10,8 +10,8 @@ mod handle_pr;
use crate::domain::{
models::{
EnrichedGithubPullRequest, GithubError, GithubInstallationAccessToken, GithubKey,
- GithubPullRequestStatus, GithubWebhookEventType, MacroTaskId, TeamTaskReference,
- ValidatedGithubWebhookEvent,
+ GithubPullRequestDetails, GithubPullRequestStatus, GithubWebhookEventType, MacroTaskId,
+ TeamTaskReference, ValidatedGithubWebhookEvent,
},
ports::{GithubSyncClient, GithubSyncRepo, GithubSyncService},
};
@@ -111,7 +111,7 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
) {
(Some(i), Some(o), Some(r), Some(p)) => (i, o, r, p),
_ => {
- tracing::warn!("missing PR metadata, cannot post comments");
+ tracing::warn!("missing PR metadata, cannot access GitHub pull request");
return None;
}
};
@@ -140,7 +140,7 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
Err(e) => {
tracing::error!(
error=?e,
- "failed to generate installation access token for PR comment"
+ "failed to generate installation access token for GitHub pull request"
);
None
}
@@ -192,9 +192,107 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
deletions: pull_request
.and_then(|pr| pr.get("deletions"))
.and_then(|value| value.as_u64()),
+ comments: None,
+ checks: None,
})
}
+ /// Build pull request metadata from live GitHub details when possible,
+ /// falling back to the webhook payload if the live request fails.
+ async fn enriched_pull_request_metadata(
+ &self,
+ event: &ValidatedGithubWebhookEvent,
+ ) -> Option<EnrichedGithubPullRequest> {
+ let fallback = Self::enriched_pull_request_from_event(event)?;
+ let requires_live_metadata = event.parsed_event_type() == GithubWebhookEventType::CheckRun;
+ let Some(pr_meta) = self.acquire_pr_meta(event).await else {
+ return (!requires_live_metadata).then_some(fallback);
+ };
+
+ match self
+ .client
+ .get_pull_request_details(
+ &pr_meta.token.token,
+ &pr_meta.owner,
+ &pr_meta.repo,
+ pr_meta.pull_number,
+ )
+ .await
+ {
+ Ok(details) => Some(Self::enriched_pull_request_from_details(fallback, details)),
+ Err(error) if requires_live_metadata => {
+ tracing::warn!(
+ error=?error,
+ owner=%pr_meta.owner,
+ repo=%pr_meta.repo,
+ pull_number=pr_meta.pull_number,
+ "failed to fetch live PR metadata for check_run event"
+ );
+ None
+ }
+ Err(error) => {
+ tracing::warn!(
+ error=?error,
+ owner=%pr_meta.owner,
+ repo=%pr_meta.repo,
+ pull_number=pr_meta.pull_number,
+ "failed to fetch live PR metadata, falling back to webhook payload"
+ );
+ Some(fallback)
+ }
+ }
+ }
+
+ /// Build enriched pull request metadata from live GitHub pull request details.
+ fn enriched_pull_request_from_details(
+ fallback: EnrichedGithubPullRequest,
+ details: GithubPullRequestDetails,
+ ) -> EnrichedGithubPullRequest {
+ let status = details.status();
+
+ EnrichedGithubPullRequest {
+ github_key: fallback.github_key,
+ owner: fallback.owner,
+ repo: fallback.repo,
+ number: fallback.number,
+ url: fallback.url,
+ display_name: fallback.display_name,
+ name: Some(details.title),
+ status: Some(status),
+ additions: Some(details.additions),
+ deletions: Some(details.deletions),
+ comments: details.comments,
+ checks: details.checks,
+ }
+ }
+
+ /// Preserve existing metadata arrays when a partial refresh omits them.
+ fn metadata_with_preserved_partial_arrays(
+ mut metadata: serde_json::Value,
+ existing_metadata: Option<&serde_json::Value>,
+ ) -> serde_json::Value {
+ let Some(existing_object) = existing_metadata.and_then(|value| value.as_object()) else {
+ return metadata;
+ };
+ let Some(metadata_object) = metadata.as_object_mut() else {
+ return metadata;
+ };
+
+ for field in ["comments", "checks"] {
+ if metadata_object.contains_key(field) {
+ continue;
+ }
+
+ if let Some(existing_value) = existing_object.get(field)
+ && existing_value.is_array()
+ {
+ metadata_object.insert(field.to_string(), existing_value.clone());
+ }
+ }
+
+ metadata
+ }
+
/// Derive a normalized pull request status from the webhook payload.
fn pull_request_status_from_event(
event: &ValidatedGithubWebhookEvent,
@@ -250,12 +348,12 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
return;
}
- let Some(pull_request) = Self::enriched_pull_request_from_event(event) else {
+ let Some(pull_request) = self.enriched_pull_request_metadata(event).await else {
tracing::warn!("missing PR metadata, cannot upsert foreign entity");
return;
};
- let metadata = match serde_json::to_value(&pull_request) {
+ let base_metadata = match serde_json::to_value(&pull_request) {
Ok(metadata) => metadata,
Err(error) => {
tracing::error!(error=?error, "failed to serialize PR foreign entity metadata");
@@ -290,13 +388,20 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
entity.stored_for_id.as_str() == stored_for_id.as_str()
&& entity.stored_for_auth_entity.as_str() == stored_for_auth_entity.as_str()
});
+ let existing_metadata = existing_entity
+ .map(|entity| &entity.metadata)
+ .or_else(|| existing.first().map(|entity| &entity.metadata));
+ let metadata = Self::metadata_with_preserved_partial_arrays(
+ base_metadata.clone(),
+ existing_metadata,
+ );
if let Some(entity) = existing_entity {
self.foreign_entity_service
.patch_foreign_entity(
entity.id,
PatchForeignEntity {
- metadata: Some(metadata.clone()),
+ metadata: Some(metadata),
..PatchForeignEntity::default()
},
)
@@ -318,7 +423,7 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
.create_foreign_entity(CreateForeignEntity {
foreign_entity_id: pull_request.github_key.clone(),
foreign_entity_source: GITHUB_PULL_REQUEST_FOREIGN_ENTITY_SOURCE.to_string(),
- metadata: metadata.clone(),
+ metadata,
stored_for_id: stored_for_id.clone(),
stored_for_auth_entity: stored_for_auth_entity.clone(),
})
@@ -590,8 +695,23 @@ impl<D: DocumentService, R: GithubSyncRepo, C: GithubSyncClient, F: ForeignEntit
GithubWebhookEventType::IssueComment
| GithubWebhookEventType::PullRequestReview
| GithubWebhookEventType::PullRequestReviewComment => {
+ if webhook_event.is_associated_with_pull_request() {
+ self.upsert_pull_request_foreign_entities(webhook_event)
+ .await;
+ }
+
self.handle_comment_event(webhook_event).await
}
+ GithubWebhookEventType::CheckRun => {
+ if webhook_event.is_associated_with_pull_request() {
+ self.upsert_pull_request_foreign_entities(webhook_event)
+ .await;
+ } else {
+ tracing::debug!("skipping check_run event without an associated PR");
+ }
+
+ Ok(())
+ }
GithubWebhookEventType::Installation => match action {
Some("created") => self.handle_installation_created(webhook_event).await,
_ => {
diff --git a/rust/cloud-storage/github/src/domain/service/sync/test.rs b/rust/cloud-storage/github/src/domain/service/sync/test.rs
index 3681042aed..81a8f9d917 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/test.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/test.rs
@@ -4,7 +4,8 @@ use std::sync::{Arc, Mutex};
use crate::domain::{
models::{
EnrichedGithubPullRequest, GithubAppInstallationSource, GithubError,
- GithubInstallationAccessToken, GithubKey, GithubPullRequestStatus, MacroTaskId,
+ GithubInstallationAccessToken, GithubKey, GithubPullRequestCheckRun,
+ GithubPullRequestComment, GithubPullRequestDetails, GithubPullRequestStatus, MacroTaskId,
TeamTaskReference, ValidatedGithubWebhookEvent,
},
ports::{GithubSyncClient, GithubSyncRepo, GithubSyncService},
@@ -467,20 +468,53 @@ struct PrCommentCall {
body: String,
}
+/// Recorded pull request details call.
+#[derive(Debug, Clone)]
+struct PullRequestDetailsCall {
+ owner: String,
+ repo: String,
+ number: u64,
+}
+
struct StubSyncClient {
pr_comments: Mutex<Vec<PrCommentCall>>,
+ pull_request_details: Mutex<HashMap<String, GithubPullRequestDetails>>,
+ pull_request_details_calls: Mutex<Vec<PullRequestDetailsCall>>,
}
impl StubSyncClient {
fn new() -> Self {
Self {
pr_comments: Mutex::new(Vec::new()),
+ pull_request_details: Mutex::new(HashMap::new()),
+ pull_request_details_calls: Mutex::new(Vec::new()),
}
}
fn pr_comments(&self) -> Vec<PrCommentCall> {
self.pr_comments.lock().unwrap().clone()
}
+
+ fn pull_request_details_calls(&self) -> Vec<PullRequestDetailsCall> {
+ self.pull_request_details_calls.lock().unwrap().clone()
+ }
+
+ fn set_pull_request_details(
+ &self,
+ owner: &str,
+ repo: &str,
+ number: u64,
+ details: GithubPullRequestDetails,
+ ) {
+ self.pull_request_details
+ .lock()
+ .unwrap()
+ .insert(Self::pull_request_details_key(owner, repo, number), details);
+ }
+
+ fn pull_request_details_key(owner: &str, repo: &str, number: u64) -> String {
+ GithubKey::new(owner, repo, number).to_string()
+ }
}
impl GithubSyncClient for StubSyncClient {
@@ -511,6 +545,30 @@ impl GithubSyncClient for StubSyncClient {
});
Ok(())
}
+
+ async fn get_pull_request_details(
+ &self,
+ _access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+ ) -> Result<GithubPullRequestDetails, GithubError> {
+ self.pull_request_details_calls
+ .lock()
+ .unwrap()
+ .push(PullRequestDetailsCall {
+ owner: owner.to_string(),
+ repo: repo.to_string(),
+ number,
+ });
+
+ self.pull_request_details
+ .lock()
+ .unwrap()
+ .get(&Self::pull_request_details_key(owner, repo, number))
+ .cloned()
+ .ok_or_else(|| GithubError::Internal(anyhow::anyhow!("missing stub PR details")))
+ }
}
fn foreign_entity_id_from_receipt(
@@ -766,10 +824,77 @@ fn expected_pull_request_metadata(
status: Some(status),
additions,
deletions,
+ comments: None,
+ checks: None,
})
.unwrap()
}
+fn expected_pull_request_metadata_from_details(
+ details: &GithubPullRequestDetails,
+) -> serde_json::Value {
+ serde_json::to_value(EnrichedGithubPullRequest {
+ github_key: "my-org/my-repo/pull/42".to_string(),
+ owner: "my-org".to_string(),
+ repo: "my-repo".to_string(),
+ number: 42,
+ url: "https://github.com/my-org/my-repo/pull/42".to_string(),
+ display_name: "my-org/my-repo#42".to_string(),
+ name: Some(details.title.clone()),
+ status: Some(details.status()),
+ additions: Some(details.additions),
+ deletions: Some(details.deletions),
+ comments: details.comments.clone(),
+ checks: details.checks.clone(),
+ })
+ .unwrap()
+}
+
+fn pull_request_comment(id: u64, body: &str, source: &str) -> GithubPullRequestComment {
+ GithubPullRequestComment {
+ id,
+ body: body.to_string(),
+ author_login: Some("octocat".to_string()),
+ author_association: Some("MEMBER".to_string()),
+ url: Some(format!(
+ "https://github.com/my-org/my-repo/pull/42#comment-{id}"
+ )),
+ created_at: None,
+ updated_at: None,
+ source: source.to_string(),
+ }
+}
+
+fn pull_request_check_run(id: u64, name: &str, status: &str) -> GithubPullRequestCheckRun {
+ GithubPullRequestCheckRun {
+ id,
+ name: name.to_string(),
+ status: status.to_string(),
+ conclusion: Some("success".to_string()),
+ url: Some(format!("https://github.com/my-org/my-repo/runs/{id}")),
+ started_at: None,
+ completed_at: None,
+ }
+}
+
+fn pull_request_details(
+ title: &str,
+ additions: u64,
+ deletions: u64,
+ comments: Option<Vec<GithubPullRequestComment>>,
+ checks: Option<Vec<GithubPullRequestCheckRun>>,
+) -> GithubPullRequestDetails {
+ GithubPullRequestDetails {
+ title: title.to_string(),
+ state: "open".to_string(),
+ merged_at: None,
+ additions,
+ deletions,
+ comments,
+ checks,
+ }
+}
+
#[tokio::test]
async fn pr_with_task_id_in_title() {
let service = make_sync_service();
@@ -1799,6 +1924,329 @@ async fn unhandled_pr_action_still_upserts_foreign_entity() {
assert!(foreign_entity_service.patch_calls().is_empty());
}
+#[tokio::test]
+async fn foreign_entity_metadata_includes_comments_and_checks_from_sync_client() {
+ let (service, foreign_entity_service) = make_sync_service_with_foreign_entity_service();
+ let details = pull_request_details(
+ "live pull request title",
+ 30,
+ 8,
+ Some(vec![pull_request_comment(
+ 101,
+ "Looks good",
+ "issue_comment",
+ )]),
+ Some(vec![pull_request_check_run(201, "ci", "completed")]),
+ );
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, details.clone());
+
+ let event = ValidatedGithubWebhookEvent::new(
+ "pull_request".to_string(),
+ serde_json::json!({
+ "action": "opened",
+ "pull_request": {
+ "number": 42,
+ "title": "webhook title",
+ "body": null,
+ "head": { "ref": "feature/some-branch" },
+ "state": "open",
+ "merged": false,
+ "additions": 10,
+ "deletions": 2
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+
+ service.process_webhook_event(&event).await.unwrap();
+
+ let foreign_entities = foreign_entity_service.foreign_entities();
+ assert_eq!(foreign_entities.len(), 1);
+ assert_eq!(
+ foreign_entities[0].metadata,
+ expected_pull_request_metadata_from_details(&details)
+ );
+
+ let detail_calls = service.client.pull_request_details_calls();
+ assert_eq!(detail_calls.len(), 1);
+ assert_eq!(detail_calls[0].owner, "my-org");
+ assert_eq!(detail_calls[0].repo, "my-repo");
+ assert_eq!(detail_calls[0].number, 42);
+}
+
+#[tokio::test]
+async fn foreign_entity_metadata_comment_event_refreshes_without_task_id() {
+ let (service, foreign_entity_service) = make_sync_service_with_foreign_entity_service();
+ let initial_details = pull_request_details("initial title", 10, 2, None, None);
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, initial_details);
+
+ let opened_event = ValidatedGithubWebhookEvent::new(
+ "pull_request".to_string(),
+ serde_json::json!({
+ "action": "opened",
+ "pull_request": {
+ "number": 42,
+ "title": "initial title",
+ "body": null,
+ "head": { "ref": "feature/some-branch" },
+ "state": "open",
+ "merged": false,
+ "additions": 10,
+ "deletions": 2
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service.process_webhook_event(&opened_event).await.unwrap();
+
+ let refreshed_details = pull_request_details(
+ "refreshed title",
+ 12,
+ 3,
+ Some(vec![pull_request_comment(
+ 102,
+ "A new comment",
+ "issue_comment",
+ )]),
+ Some(vec![pull_request_check_run(202, "ci", "completed")]),
+ );
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, refreshed_details.clone());
+
+ let comment_event = ValidatedGithubWebhookEvent::new(
+ "issue_comment".to_string(),
+ serde_json::json!({
+ "action": "created",
+ "issue": {
+ "number": 42,
+ "title": "initial title",
+ "body": null,
+ "state": "open",
+ "pull_request": {
+ "url": "https://api.github.com/repos/my-org/my-repo/pulls/42"
+ }
+ },
+ "comment": {
+ "body": "No task reference in this comment"
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service.process_webhook_event(&comment_event).await.unwrap();
+
+ let expected_metadata = expected_pull_request_metadata_from_details(&refreshed_details);
+ let foreign_entities = foreign_entity_service.foreign_entities();
+ assert_eq!(foreign_entities.len(), 1);
+ assert_eq!(foreign_entities[0].metadata, expected_metadata);
+ assert!(service.client.pr_comments().is_empty());
+
+ let patch_calls = foreign_entity_service.patch_calls();
+ assert_eq!(patch_calls.len(), 1);
+ assert_eq!(patch_calls[0].1.metadata, Some(expected_metadata));
+}
+
+#[tokio::test]
+async fn foreign_entity_metadata_check_run_refreshes_pull_request() {
+ let (service, foreign_entity_service) = make_sync_service_with_foreign_entity_service();
+ let initial_details = pull_request_details("initial title", 10, 2, None, None);
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, initial_details);
+
+ let opened_event = ValidatedGithubWebhookEvent::new(
+ "pull_request".to_string(),
+ serde_json::json!({
+ "action": "opened",
+ "pull_request": {
+ "number": 42,
+ "title": "initial title",
+ "body": null,
+ "head": { "ref": "feature/some-branch" },
+ "state": "open",
+ "merged": false,
+ "additions": 10,
+ "deletions": 2
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service.process_webhook_event(&opened_event).await.unwrap();
+
+ let refreshed_details = pull_request_details(
+ "initial title",
+ 10,
+ 2,
+ None,
+ Some(vec![pull_request_check_run(203, "lint", "completed")]),
+ );
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, refreshed_details.clone());
+
+ let check_run_event = ValidatedGithubWebhookEvent::new(
+ "check_run".to_string(),
+ serde_json::json!({
+ "action": "completed",
+ "check_run": {
+ "pull_requests": [
+ { "number": 42 }
+ ]
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service
+ .process_webhook_event(&check_run_event)
+ .await
+ .unwrap();
+
+ let expected_metadata = expected_pull_request_metadata_from_details(&refreshed_details);
+ let foreign_entities = foreign_entity_service.foreign_entities();
+ assert_eq!(foreign_entities.len(), 1);
+ assert_eq!(foreign_entities[0].metadata, expected_metadata);
+
+ let patch_calls = foreign_entity_service.patch_calls();
+ assert_eq!(patch_calls.len(), 1);
+ assert_eq!(patch_calls[0].1.metadata, Some(expected_metadata));
+}
+
+#[tokio::test]
+async fn foreign_entity_metadata_preserves_existing_comments_when_refresh_omits_them() {
+ let (service, foreign_entity_service) = make_sync_service_with_foreign_entity_service();
+ let initial_details = pull_request_details(
+ "initial title",
+ 10,
+ 2,
+ Some(vec![pull_request_comment(
+ 103,
+ "Keep this comment",
+ "review",
+ )]),
+ Some(vec![pull_request_check_run(204, "ci", "completed")]),
+ );
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, initial_details.clone());
+
+ let opened_event = ValidatedGithubWebhookEvent::new(
+ "pull_request".to_string(),
+ serde_json::json!({
+ "action": "opened",
+ "pull_request": {
+ "number": 42,
+ "title": "initial title",
+ "body": null,
+ "head": { "ref": "feature/some-branch" },
+ "state": "open",
+ "merged": false,
+ "additions": 10,
+ "deletions": 2
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service.process_webhook_event(&opened_event).await.unwrap();
+
+ let mut partial_details = pull_request_details(
+ "partial refresh title",
+ 11,
+ 4,
+ None,
+ Some(vec![pull_request_check_run(205, "ci", "completed")]),
+ );
+ service
+ .client
+ .set_pull_request_details("my-org", "my-repo", 42, partial_details.clone());
+
+ let edited_event = ValidatedGithubWebhookEvent::new(
+ "pull_request".to_string(),
+ serde_json::json!({
+ "action": "edited",
+ "pull_request": {
+ "number": 42,
+ "title": "partial refresh title",
+ "body": null,
+ "head": { "ref": "feature/some-branch" },
+ "state": "open",
+ "merged": false,
+ "additions": 11,
+ "deletions": 4
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+ service.process_webhook_event(&edited_event).await.unwrap();
+
+ partial_details.comments = initial_details.comments.clone();
+ let expected_metadata = expected_pull_request_metadata_from_details(&partial_details);
+ let foreign_entities = foreign_entity_service.foreign_entities();
+ assert_eq!(foreign_entities.len(), 1);
+ assert_eq!(foreign_entities[0].metadata, expected_metadata);
+}
+
+#[tokio::test]
+async fn foreign_entity_metadata_non_pr_issue_comment_does_not_create_pull_request() {
+ let (service, foreign_entity_service) = make_sync_service_with_foreign_entity_service();
+ let event = ValidatedGithubWebhookEvent::new(
+ "issue_comment".to_string(),
+ serde_json::json!({
+ "action": "created",
+ "issue": {
+ "number": 42,
+ "title": "plain issue",
+ "body": null,
+ "state": "open"
+ },
+ "comment": {
+ "body": "No task reference in this issue comment"
+ },
+ "repository": {
+ "name": "my-repo",
+ "owner": { "login": "my-org" }
+ },
+ "installation": { "id": 12345 }
+ }),
+ );
+
+ service.process_webhook_event(&event).await.unwrap();
+
+ assert!(foreign_entity_service.foreign_entities().is_empty());
+ assert!(service.client.pull_request_details_calls().is_empty());
+}
+
// ---------------------------------------------------------------------------
// New behavioral tests
// ---------------------------------------------------------------------------
diff --git a/rust/cloud-storage/github/src/outbound.rs b/rust/cloud-storage/github/src/outbound.rs
index 9fba36a96e..60f27c0a3f 100644
--- a/rust/cloud-storage/github/src/outbound.rs
+++ b/rust/cloud-storage/github/src/outbound.rs
@@ -10,3 +10,5 @@ pub mod github_sync_client;
pub mod pg_github_repo;
#[cfg(feature = "sync")]
pub mod pg_github_sync_repo;
+#[cfg(any(feature = "link", feature = "sync"))]
+pub(crate) mod pull_request_metadata;
diff --git a/rust/cloud-storage/github/src/outbound/github_oauth_client.rs b/rust/cloud-storage/github/src/outbound/github_oauth_client.rs
index 6d9f64be61..b35d868b3b 100644
--- a/rust/cloud-storage/github/src/outbound/github_oauth_client.rs
+++ b/rust/cloud-storage/github/src/outbound/github_oauth_client.rs
@@ -2,6 +2,8 @@
use std::time::Duration;
+use super::pull_request_metadata::fetch_pull_request_metadata;
+
use crate::domain::{
models::{GithubExchangeTokenResponse, GithubPullRequestDetails, GithubUserInfo},
ports::GithubOauth,
@@ -189,37 +191,6 @@ impl GithubOauth for GithubOauthImpl {
repo: &str,
number: u64,
) -> Result<GithubPullRequestDetails, Self::Err> {
- let response = self
- .client
- .get(format!(
- "https://api.github.com/repos/{owner}/{repo}/pulls/{number}"
- ))
- .header("Authorization", format!("Bearer {}", access_token))
- .header("Accept", "application/vnd.github+json")
- .header("User-Agent", "Macro-Auth-Service")
- .header("X-GitHub-Api-Version", "2022-11-28")
- .timeout(Duration::from_secs(15))
- .send()
- .await?;
-
- let status = response.status();
-
- if !status.is_success() {
- let error_body = response
- .text()
- .await
- .unwrap_or_else(|_| "unknown error".to_string());
-
- if status.as_u16() == 401 {
- tracing::warn!(error_body=%error_body, "GitHub token expired or invalid");
- anyhow::bail!("unauthorized access")
- }
-
- anyhow::bail!("failed to get pull request details {}", error_body)
- }
-
- let details: GithubPullRequestDetails = response.json().await?;
-
- Ok(details)
+ fetch_pull_request_metadata(&self.client, access_token, owner, repo, number).await
}
}
diff --git a/rust/cloud-storage/github/src/outbound/github_sync_client.rs b/rust/cloud-storage/github/src/outbound/github_sync_client.rs
index c93579d2f8..3eaf5e92e2 100644
--- a/rust/cloud-storage/github/src/outbound/github_sync_client.rs
+++ b/rust/cloud-storage/github/src/outbound/github_sync_client.rs
@@ -1,7 +1,9 @@
//! Github Sync Client implementation of the [`GithubSyncClient`] port.
+use super::pull_request_metadata::fetch_pull_request_metadata;
+
use crate::domain::{
- models::{GithubError, GithubInstallationAccessToken},
+ models::{GithubError, GithubInstallationAccessToken, GithubPullRequestDetails},
ports::GithubSyncClient,
};
@@ -87,4 +89,17 @@ impl GithubSyncClient for GithubSyncClientImpl {
Ok(())
}
+
+ #[tracing::instrument(skip(self, access_token), err)]
+ async fn get_pull_request_details(
+ &self,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+ ) -> Result<GithubPullRequestDetails, GithubError> {
+ fetch_pull_request_metadata(&self.client, access_token, owner, repo, number)
+ .await
+ .map_err(GithubError::Internal)
+ }
}
diff --git a/rust/cloud-storage/github/src/outbound/pull_request_metadata.rs b/rust/cloud-storage/github/src/outbound/pull_request_metadata.rs
new file mode 100644
index 0000000000..a5e16a27ac
--- /dev/null
+++ b/rust/cloud-storage/github/src/outbound/pull_request_metadata.rs
@@ -0,0 +1,421 @@
+//! Shared GitHub pull request metadata fetcher.
+
+use std::time::Duration;
+
+use serde::de::DeserializeOwned;
+
+use crate::domain::models::{
+ GithubPullRequestCheckRun, GithubPullRequestComment, GithubPullRequestDetails,
+};
+
+const GITHUB_API_BASE_URL: &str = "https://api.github.com";
+const METADATA_PAGE_SIZE: u16 = 100;
+const REQUEST_TIMEOUT: Duration = Duration::from_secs(15);
+const USER_AGENT: &str = "Macro-Auth-Service";
+
+/// Fetch GitHub pull request details with comments and check runs when available.
+pub(crate) async fn fetch_pull_request_metadata(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Result<GithubPullRequestDetails, anyhow::Error> {
+ let pull_request = fetch_pull_request(client, access_token, owner, repo, number).await?;
+ let comments = fetch_comments(client, access_token, owner, repo, number).await;
+ let checks = fetch_check_runs(
+ client,
+ access_token,
+ owner,
+ repo,
+ pull_request.head.sha.as_str(),
+ )
+ .await;
+
+ Ok(GithubPullRequestDetails {
+ title: pull_request.title,
+ state: pull_request.state,
+ merged_at: pull_request.merged_at,
+ additions: pull_request.additions,
+ deletions: pull_request.deletions,
+ comments,
+ checks,
+ })
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubPullRequestResponse {
+ title: String,
+ state: String,
+ merged_at: Option<chrono::DateTime<chrono::Utc>>,
+ additions: u64,
+ deletions: u64,
+ head: GithubPullRequestHeadResponse,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubPullRequestHeadResponse {
+ sha: String,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubUserResponse {
+ login: Option<String>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubCommentResponse {
+ id: u64,
+ body: Option<String>,
+ user: Option<GithubUserResponse>,
+ author_association: Option<String>,
+ html_url: Option<String>,
+ created_at: Option<chrono::DateTime<chrono::Utc>>,
+ updated_at: Option<chrono::DateTime<chrono::Utc>>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubReviewResponse {
+ id: u64,
+ body: Option<String>,
+ user: Option<GithubUserResponse>,
+ author_association: Option<String>,
+ html_url: Option<String>,
+ submitted_at: Option<chrono::DateTime<chrono::Utc>>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubCheckRunsResponse {
+ check_runs: Vec<GithubCheckRunResponse>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+struct GithubCheckRunResponse {
+ id: u64,
+ name: String,
+ status: String,
+ conclusion: Option<String>,
+ html_url: Option<String>,
+ started_at: Option<chrono::DateTime<chrono::Utc>>,
+ completed_at: Option<chrono::DateTime<chrono::Utc>>,
+}
+
+async fn fetch_pull_request(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Result<GithubPullRequestResponse, anyhow::Error> {
+ let url = format!("{GITHUB_API_BASE_URL}/repos/{owner}/{repo}/pulls/{number}");
+ let response = github_get(client, access_token, url).send().await?;
+ let status = response.status();
+
+ if !status.is_success() {
+ let error_body = response
+ .text()
+ .await
+ .unwrap_or_else(|_| "unknown error".to_string());
+
+ if status.as_u16() == 401 {
+ tracing::warn!(error_body=%error_body, "GitHub token expired or invalid");
+ anyhow::bail!("unauthorized access")
+ }
+
+ anyhow::bail!("failed to get pull request details {}", error_body)
+ }
+
+ response.json().await.map_err(Into::into)
+}
+
+async fn fetch_comments(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Option<Vec<GithubPullRequestComment>> {
+ let mut comments = fetch_issue_comments(client, access_token, owner, repo, number).await?;
+
+ comments.extend(fetch_review_comments(client, access_token, owner, repo, number).await?);
+ comments.extend(fetch_reviews(client, access_token, owner, repo, number).await?);
+
+ Some(comments)
+}
+
+async fn fetch_issue_comments(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Option<Vec<GithubPullRequestComment>> {
+ match fetch_paginated_github_items(
+ client,
+ access_token,
+ |page| {
+ format!(
+ "{GITHUB_API_BASE_URL}/repos/{owner}/{repo}/issues/{number}/comments?per_page={METADATA_PAGE_SIZE}&page={page}"
+ )
+ },
+ "pull request issue comments",
+ |comments: Vec<GithubCommentResponse>| comments,
+ )
+ .await
+ {
+ Ok(comments) => Some(
+ comments
+ .into_iter()
+ .map(|comment| comment.into_pull_request_comment("issue_comment"))
+ .collect(),
+ ),
+ Err(error) => {
+ tracing::warn!(
+ error=?error,
+ owner=%owner,
+ repo=%repo,
+ number=number,
+ "failed to fetch GitHub pull request issue comments"
+ );
+ None
+ }
+ }
+}
+
+async fn fetch_review_comments(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Option<Vec<GithubPullRequestComment>> {
+ match fetch_paginated_github_items(
+ client,
+ access_token,
+ |page| {
+ format!(
+ "{GITHUB_API_BASE_URL}/repos/{owner}/{repo}/pulls/{number}/comments?per_page={METADATA_PAGE_SIZE}&page={page}"
+ )
+ },
+ "pull request review comments",
+ |comments: Vec<GithubCommentResponse>| comments,
+ )
+ .await
+ {
+ Ok(comments) => Some(
+ comments
+ .into_iter()
+ .map(|comment| comment.into_pull_request_comment("review_comment"))
+ .collect(),
+ ),
+ Err(error) => {
+ tracing::warn!(
+ error=?error,
+ owner=%owner,
+ repo=%repo,
+ number=number,
+ "failed to fetch GitHub pull request review comments"
+ );
+ None
+ }
+ }
+}
+
+async fn fetch_reviews(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ number: u64,
+) -> Option<Vec<GithubPullRequestComment>> {
+ match fetch_paginated_github_items(
+ client,
+ access_token,
+ |page| {
+ format!(
+ "{GITHUB_API_BASE_URL}/repos/{owner}/{repo}/pulls/{number}/reviews?per_page={METADATA_PAGE_SIZE}&page={page}"
+ )
+ },
+ "pull request reviews",
+ |reviews: Vec<GithubReviewResponse>| reviews,
+ )
+ .await
+ {
+ Ok(reviews) => Some(
+ reviews
+ .into_iter()
+ .filter_map(GithubReviewResponse::into_pull_request_comment)
+ .collect(),
+ ),
+ Err(error) => {
+ tracing::warn!(
+ error=?error,
+ owner=%owner,
+ repo=%repo,
+ number=number,
+ "failed to fetch GitHub pull request reviews"
+ );
+ None
+ }
+ }
+}
+
+async fn fetch_check_runs(
+ client: &reqwest::Client,
+ access_token: &str,
+ owner: &str,
+ repo: &str,
+ head_sha: &str,
+) -> Option<Vec<GithubPullRequestCheckRun>> {
+ match fetch_paginated_github_items(
+ client,
+ access_token,
+ |page| {
+ format!(
+ "{GITHUB_API_BASE_URL}/repos/{owner}/{repo}/commits/{head_sha}/check-runs?per_page={METADATA_PAGE_SIZE}&page={page}"
+ )
+ },
+ "check runs",
+ |response: GithubCheckRunsResponse| response.check_runs,
+ )
+ .await
+ {
+ Ok(check_runs) => Some(
+ check_runs
+ .into_iter()
+ .map(GithubCheckRunResponse::into_pull_request_check_run)
+ .collect(),
+ ),
+ Err(error) => {
+ tracing::warn!(
+ error=?error,
+ owner=%owner,
+ repo=%repo,
+ head_sha=%head_sha,
+ "failed to fetch GitHub pull request check runs"
+ );
+ None
+ }
+ }
+}
+
+async fn fetch_paginated_github_items<Response, Item, UrlForPage, ItemsFromResponse>(
+ client: &reqwest::Client,
+ access_token: &str,
+ mut url_for_page: UrlForPage,
+ description: &str,
+ mut items_from_response: ItemsFromResponse,
+) -> Result<Vec<Item>, anyhow::Error>
+where
+ Response: DeserializeOwned,
+ UrlForPage: FnMut(u32) -> String,
+ ItemsFromResponse: FnMut(Response) -> Vec<Item>,
+{
+ let mut all_items = Vec::new();
+ let mut page = 1;
+
+ loop {
+ let response =
+ fetch_github_json::<Response>(client, access_token, url_for_page(page), description)
+ .await?;
+ let page_items = items_from_response(response);
+ let is_last_page = page_items.len() < usize::from(METADATA_PAGE_SIZE);
+
+ all_items.extend(page_items);
+
+ if is_last_page {
+ break;
+ }
+
+ page += 1;
+ }
+
+ Ok(all_items)
+}
+
+async fn fetch_github_json<T>(
+ client: &reqwest::Client,
+ access_token: &str,
+ url: String,
+ description: &str,
+) -> Result<T, anyhow::Error>
+where
+ T: DeserializeOwned,
+{
+ let response = github_get(client, access_token, url).send().await?;
+ let status = response.status();
+
+ if !status.is_success() {
+ let error_body = response
+ .text()
+ .await
+ .unwrap_or_else(|_| "unknown error".to_string());
+ anyhow::bail!("failed to get {description} (status {status}): {error_body}")
+ }
+
+ response.json().await.map_err(Into::into)
+}
+
+fn github_get(
+ client: &reqwest::Client,
+ access_token: &str,
+ url: String,
+) -> reqwest::RequestBuilder {
+ client
+ .get(url)
+ .header("Authorization", format!("Bearer {access_token}"))
+ .header("Accept", "application/vnd.github+json")
+ .header("User-Agent", USER_AGENT)
+ .header("X-GitHub-Api-Version", "2022-11-28")
+ .timeout(REQUEST_TIMEOUT)
+}
+
+impl GithubCommentResponse {
+ fn into_pull_request_comment(self, source: &str) -> GithubPullRequestComment {
+ GithubPullRequestComment {
+ id: self.id,
+ body: self.body.unwrap_or_default(),
+ author_login: self.user.and_then(|user| user.login),
+ author_association: self.author_association,
+ url: self.html_url,
+ created_at: self.created_at,
+ updated_at: self.updated_at,
+ source: source.to_string(),
+ }
+ }
+}
+
+impl GithubReviewResponse {
+ fn into_pull_request_comment(self) -> Option<GithubPullRequestComment> {
+ let body = self.body.unwrap_or_default();
+
+ if body.trim().is_empty() {
+ return None;
+ }
+
+ Some(GithubPullRequestComment {
+ id: self.id,
+ body,
+ author_login: self.user.and_then(|user| user.login),
+ author_association: self.author_association,
+ url: self.html_url,
+ created_at: self.submitted_at,
+ updated_at: None,
+ source: "review".to_string(),
+ })
+ }
+}
+
+impl GithubCheckRunResponse {
+ fn into_pull_request_check_run(self) -> GithubPullRequestCheckRun {
+ GithubPullRequestCheckRun {
+ id: self.id,
+ name: self.name,
+ status: self.status,
+ conclusion: self.conclusion,
+ url: self.html_url,
+ started_at: self.started_at,
+ completed_at: self.completed_at,
+ }
+ }
+}