Skip to content

Commit

Permalink
Fix group (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex authored Dec 24, 2020
1 parent c1ab22d commit 44598ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Auto-update is a simple [JavaScript GitHub action](https://help.github.com/en/articles/about-actions#javascript-actions) to keep pull requests [up to date with their base branch](https://developer.github.com/changes/2019-05-29-update-branch-api/).
Auto-update is a minimalist [JavaScript GitHub action](https://help.github.com/en/articles/about-actions#javascript-actions) to keep pull requests [up to date with their base branch](https://developer.github.com/changes/2019-05-29-update-branch-api/).

It is the missing piece to really [automatically merge pull requests](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/automatically-merging-a-pull-request) when [strict status checks](https://help.github.com/en/articles/types-of-required-status-checks) are set up to protect against [semantic conflicts](https://bors.tech/essay/2017/02/02/pitch/).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-update",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"files": [
"action.yml",
Expand Down
90 changes: 44 additions & 46 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,53 @@ const run = async () => {
)}`,
);

await Promise.all(
pullRequests
.filter((pullRequest) => {
if (
label !== undefined &&
!pullRequest.labels.some(({ name }) => name === label)
) {
info(
`Pull request #${pullRequest.number} does not have the "${label}" label`,
);
return false;
}
const pullRequestsToUpdate = pullRequests.filter((pullRequest) => {
if (pullRequest.base.sha === payload.after) {
info(`Pull request #${pullRequest.number} is already up to date`);
return false;
}

if (pullRequest.draft) {
info(`Pull request #${pullRequest.number} is still a draft`);
return false;
}
if (pullRequest.draft) {
info(`Pull request #${pullRequest.number} is still a draft`);
return false;
}

if (pullRequest.base.sha === payload.after) {
info(`Pull request #${pullRequest.number} is already up to date`);
return false;
}
if (
label !== undefined &&
!pullRequest.labels.some(({ name }) => name === label)
) {
info(
`Pull request #${pullRequest.number} does not have the "${label}" label`,
);
return false;
}

return true;
})
.map(async (pullRequest) => {
await group(
`Attempting to update pull request #${pullRequest.number}`,
async () => {
try {
await octokit.request(
"PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch",
{
...context.repo,
// See https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#update-a-pull-request-branch-preview-notices.
mediaType: {
previews: ["lydian"],
},
pull_number: pullRequest.number,
},
);
info("Updated!");
} catch (error: unknown) {
handleError(error, { handle: warning });
}
},
);
}),
);
return true;
});

for (const pullRequest of pullRequestsToUpdate) {
await group(
`Attempting to update pull request #${pullRequest.number}`,
async () => {
try {
await octokit.request(
"PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch",
{
...context.repo,
// See https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#update-a-pull-request-branch-preview-notices.
mediaType: {
previews: ["lydian"],
},
pull_number: pullRequest.number,
},
);
info("Updated!");
} catch (error: unknown) {
handleError(error, { handle: warning });
}
},
);
}
} catch (error: unknown) {
handleError(error, { handle: setFailed });
}
Expand Down

0 comments on commit 44598ac

Please sign in to comment.