Skip to content

Commit 6cd2daa

Browse files
committed
fix(source-control): pin Origin mergeability to its head and keep copy headers
1 parent 707e7ab commit 6cd2daa

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎packages/source-control-cursor-origin/src/server/OriginPullRequestProvider.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,30 @@ export const make = Effect.gen(function* () {
397397
// against the rate limit, so a definite answer is kept for that pair of commits.
398398
const mergeabilities = yield* Cache.makeWith(
399399
(key: string) => {
400-
const [cwd = "", repository = "", number = ""] = key.split("\n");
400+
const [cwd = "", repository = "", number = "", head = ""] = key.split("\n");
401401
return cli
402402
.api(
403403
{
404404
cwd,
405405
operation: "getMergeability",
406-
path: pullPath(repository, Number(number), "/mergeability"),
406+
path: pullPath(
407+
repository,
408+
Number(number),
409+
`/mergeability?${new URLSearchParams({ expectedHeadSha: head })}`,
410+
),
407411
},
408412
OriginMergeabilitySchema,
409413
)
410414
.pipe(
411415
Effect.map((answer): PullRequestMergeability =>
412-
(answer.blockers ?? []).some((blocker) => blocker.kind === "merge_conflict")
413-
? "conflicting"
414-
: answer.verdict === "mergeable"
415-
? "mergeable"
416-
: "unknown",
416+
// A head pushed since the key was made answers for other commits.
417+
answer.headSha && answer.headSha !== head
418+
? "unknown"
419+
: (answer.blockers ?? []).some((blocker) => blocker.kind === "merge_conflict")
420+
? "conflicting"
421+
: answer.verdict === "mergeable"
422+
? "mergeable"
423+
: "unknown",
417424
),
418425
);
419426
},

‎packages/source-control-cursor-origin/src/server/originPullRequests.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export function preparedMergeability(pullRequest: OriginPullRequest): PullReques
271271

272272
export const OriginMergeabilitySchema = Schema.Struct({
273273
verdict: OptionalString,
274+
headSha: OptionalString,
274275
blockers: Schema.optional(Schema.NullOr(Schema.Array(Schema.Struct({ kind: OptionalString })))),
275276
});
276277

@@ -364,6 +365,7 @@ export function originFilesPatch(
364365
const oldPath = file.previousFilename || file.filename;
365366
const added = file.status === "added";
366367
const removed = file.status === "removed" || file.status === "deleted";
368+
const action = file.status === "copied" ? "copy" : "rename";
367369
const before = quoteGitPatchPath(`a/${oldPath}`);
368370
const after = quoteGitPatchPath(`b/${file.filename}`);
369371
const header = [
@@ -372,8 +374,8 @@ export function originFilesPatch(
372374
...(oldPath !== file.filename
373375
? [
374376
`similarity index ${file.patch ? 0 : 100}%`,
375-
`rename from ${quoteGitPatchPath(oldPath)}`,
376-
`rename to ${quoteGitPatchPath(file.filename)}`,
377+
`${action} from ${quoteGitPatchPath(oldPath)}`,
378+
`${action} to ${quoteGitPatchPath(file.filename)}`,
377379
]
378380
: []),
379381
];

0 commit comments

Comments
 (0)