Skip to content

Commit

Permalink
Added notification on error (#9)
Browse files Browse the repository at this point in the history
Added the ability to comment in a PR when it fails to update it.

It will link to the logs and inform the user on what they can do.

This resolves #8
  • Loading branch information
Bullrich authored Feb 5, 2024
1 parent 7d8f7ff commit faa840c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/up-to-date.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
updatePullRequests:
name: Keep PRs up to date
runs-on: ubuntu-latest
steps:
- name: Update all the PRs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:

jobs:
updatePullRequests:
name: Keep PRs up to date
runs-on: ubuntu-latest
steps:
- name: Update all the PRs
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/up-to-date-action/action:0.1.0'
image: 'docker://ghcr.io/paritytech/up-to-date-action/action:0.2.0'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "up-to-date-action",
"version": "0.1.0",
"version": "0.2.0",
"description": "Keep all your PRs up to date when a new commit is pushed to the main branch",
"main": "src/index.ts",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/github/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ export class PullRequestApi {

return data.message;
}

async comment(number: number, msg: string): Promise<void> {
await this.api.rest.issues.createComment({
...this.repo,
issue_number: number,
body: msg,
});
}
}
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const logger = generateCoreLogger();
const action = async () => {
const token = getInput("GITHUB_TOKEN", { required: true });
const repoInfo = getRepo(context);
const actionUrl = `${context.serverUrl}/${repoInfo.owner}/${repoInfo.repo}/actions/runs/${context.runId}`;
const requireAutoMerge: boolean =
getInput("REQUIRE_AUTO_MERGE", { required: false }) !== "false";
const api = new PullRequestApi(getOctokit(token), repoInfo, logger);
Expand Down Expand Up @@ -54,6 +55,13 @@ const action = async () => {
} catch (error) {
logger.error(error as string | Error);
rows.push([repoTxt, title, "Fail ❌"]);
await api.comment(
number,
"# Failed to update PR ❌\n\n" +
"There was an error while trying to keep this PR `up-to-date`\n\n" +
"You may have conflicts ‼️ or may have to manually sync it with the target branch 👉❇️\n\n" +
`More info in the [logs 📋](${actionUrl})`,
);
}
}
logger.info("🪄 - Finished updating PRs");
Expand Down

0 comments on commit faa840c

Please sign in to comment.