-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update course-schedule PR comments in-place (#1856)
Instead of always adding a new comment, just update the existing comment if one exists. This fixes #1834.
- Loading branch information
Showing
1 changed file
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,9 +60,32 @@ jobs: | |
var pr_number = Number(fs.readFileSync('pr-number')); | ||
var upstream = fs.readFileSync('upstream-schedule').toString(); | ||
var schedule = fs.readFileSync('schedule').toString(); | ||
if (upstream != schedule) { | ||
schedule = schedule + "# New Course Schedule\n"; | ||
schedule = schedule + "This PR changes the course schedule. The new schedule is shown below."; | ||
schedule = "<!-- course-schedule -->\n" + | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
errge
Contributor
|
||
"# Changes to Course Schedule\n" + | ||
"This PR changes the course schedule. The new schedule is shown below.\n\n" + | ||
schedule; | ||
// Look for existing comments | ||
var existing_comment; | ||
for await ({ data: comments } of github.paginate.iterator(github.rest.issues.listComments, { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: pr_number | ||
})) { | ||
existing_comment = comments.find((c) => c.body.includes("<!-- course-schedule -->")); | ||
if (existing_comment) { | ||
break; | ||
} | ||
} | ||
if (existing_comment) { | ||
await github.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: existing_comment.id, | ||
body: schedule, | ||
}); | ||
} else if (upstream != schedule) { | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
|
@djmitche This actually a breaking regression.
The unluckiness comes from the fact, that previously the same if statement of
upstream != schedule
was evaluated right away, and in the new code, the schedule variable changes before the if is evaluated as anelse if
later.