Repository navigation
fix(gitcafe): authored lists, merge progress, and author reviews match git.cafe #23887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,11 @@ const Actor = Schema.Union([ | |
| actorId: Schema.String, | ||
| login: TrimmedNonEmptyString, | ||
| avatarUrl: Schema.NullOr(Schema.String), | ||
| linkedProfile: Schema.optional(Schema.NullOr(Schema.Struct({ handle: TrimmedNonEmptyString }))), | ||
| linkedProfile: Schema.optional( | ||
| Schema.NullOr( | ||
| Schema.Struct({ handle: TrimmedNonEmptyString, actorId: Schema.optional(Schema.String) }), | ||
| ), | ||
| ), | ||
| }), | ||
| Schema.Struct({ kind: Schema.Literal("unavailable"), actorId: Schema.String }), | ||
| ]); | ||
|
|
@@ -81,6 +85,10 @@ export const GitCafePullDetail = Schema.Struct({ | |
| observedBaseOid: Schema.optional(Schema.NullOr(Schema.String)), | ||
| mergeRoute: Schema.optional(Schema.Literals(["native", "provider", "unsupported"])), | ||
| lockedAt: Schema.optional(Schema.NullOr(IsoDateTime)), | ||
| viewerActorId: Schema.optional(Schema.NullOr(Schema.String)), | ||
| // Set once GitHub has merged a pull request GitCafe routed there, which can be before the | ||
| // sync brings the merged state back. | ||
| providerMerge: Schema.optional(Schema.NullOr(Schema.Struct({ mergedAt: IsoDateTime }))), | ||
| capabilities: Schema.Struct({ | ||
| comment: Schema.Boolean, | ||
| review: Schema.Boolean, | ||
|
|
@@ -334,6 +342,16 @@ export function toChangeRequest( | |
| }; | ||
| } | ||
|
|
||
| function isViewerAuthor(detail: GitCafePullDetail): boolean { | ||
| const viewer = detail.viewerActorId; | ||
| if (viewer == null) return false; | ||
| const { author } = detail; | ||
| return ( | ||
| author.actorId === viewer || | ||
| (author.kind === "github" && author.linkedProfile?.actorId === viewer) | ||
|
Comment on lines
+345
to
+351
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: set -eu
file='packages/source-control-gitcafe/src/server/gitCafePullRequestJson.ts'
printf '%s\n' '--- target source ---'
nl -ba "$file" | sed -n '1,90p;300,390p'
printf '%s\n' '--- related tests and references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'isViewerAuthor' -e 'viewerActorId' -e 'linkedProfile' -e 'approve' -e 'request-changes' packages/source-control-gitcafe | head -200Repository: pingdotgg/t3code Length of output: 9913 Handle missing viewer identity before granting non-author verdicts. If 🤖 Prompt for AI Agents |
||
| ); | ||
| } | ||
|
|
||
| export function toViewerPermissions(detail: GitCafePullDetail): PullRequestViewerPermissions { | ||
| const { comment, edit, review, merge, moderate } = detail.capabilities; | ||
| const open = comment && (detail.lockedAt == null || moderate); | ||
|
|
@@ -349,7 +367,12 @@ export function toViewerPermissions(detail: GitCafePullDetail): PullRequestViewe | |
| stackRebase: merge, | ||
| comment: open, | ||
| resolve: open, | ||
| verdicts: review ? ["approve", "request-changes", "comment"] : [], | ||
| // GitCafe refuses an author's approval and request for changes, as GitHub does. | ||
| verdicts: !review | ||
| ? [] | ||
| : isViewerAuthor(detail) | ||
| ? ["comment"] | ||
| : ["approve", "request-changes", "comment"], | ||
| requestReviewers: edit && detail.state === "open", | ||
| labels: edit && detail.state === "open", | ||
| editChangeRequest: edit, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Calculate permissions from the effective merged state.
If an open pull request has
providerMergeand no pending merge reason, this spread reportsstate: "merged".viewerPermissionsstill comes from the open pull request, so it can includemerge,close, and reviewer-edit actions. Calculate permissions from the effective state before returning the detail. Also make the merge action treatproviderMergeas settled.🤖 Prompt for AI Agents