Skip to content

Commit 68bbf96

Browse files
Implement commenting on PRs to explain conflict (#31)
1 parent b7e19ee commit 68bbf96

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/autoupdater.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export class AutoUpdater {
483483
return false;
484484
}
485485

486-
if (e.message === 'Merge conflict') {
486+
if (e.message.includes('Merge conflict')) {
487487
setOutputFn(Output.Conflicted, true);
488488

489489
if (mergeConflictAction === 'ignore') {
@@ -504,14 +504,37 @@ export class AutoUpdater {
504504
const currentLabels = prData.labels
505505
.map((l: any) => l.name)
506506
.filter(Boolean);
507+
ghCore.info(
508+
`Current labels on PR #${prNumber}: ${currentLabels.join(', ')}`,
509+
);
510+
// If the label is not already present, add it, and remove the filter label if it exists.
507511
if (!currentLabels.includes(mergeConflictLabel)) {
508-
const newLabels = [...currentLabels, mergeConflictLabel];
512+
const labelSet = new Set([
513+
...currentLabels,
514+
mergeConflictLabel,
515+
]);
516+
517+
if (this.config.pullRequestFilter() === 'labelled') {
518+
this.config
519+
.pullRequestLabels()
520+
.forEach((label) => labelSet.delete(label));
521+
}
522+
523+
const newLabels = Array.from(labelSet);
524+
509525
await this.octokit.rest.issues.update({
510526
owner: mergeOpts.owner as string,
511527
repo: mergeOpts.repo as string,
512528
issue_number: prNumber,
513529
labels: newLabels,
514530
});
531+
532+
await this.octokit.rest.issues.createComment({
533+
owner: mergeOpts.owner as string,
534+
repo: mergeOpts.repo as string,
535+
issue_number: prNumber,
536+
body: `This pull request has a merge conflict with the base branch! Please resolve the conflict manually, remove the conflict label and re-add the filter label (if applicable).`,
537+
});
515538
ghCore.info(
516539
`Added merge conflict label '${mergeConflictLabel}' to PR #${prNumber}.`,
517540
);

0 commit comments

Comments
 (0)