Skip to content

Commit

Permalink
feat: comment on the original pull/merge request when on error
Browse files Browse the repository at this point in the history
A comment is added to the original PR when a backport fails. The
developers watching the PR will be notified even if they are not
watching the CI.

Fixes: #123
  • Loading branch information
earl-warren committed Apr 8, 2024
1 parent fc5dba6 commit ef940d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/service/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/

// WRITE

/**
* Add a comment about a failed backport.
*/
commentError(prUrl: string, message: string): Promise<void>;

/**
* Create a new pull request on the underneath git service
* @param backport backport pull request data
Expand Down
10 changes: 10 additions & 0 deletions src/service/git/github/github-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ export default class GitHubClient implements GitClient {
return data.html_url;
}

async commentError(prUrl: string, message: string): Promise<void> {
const { owner, project, id } = this.extractPullRequestData(prUrl);
await this.octokit.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: id,
body: message,
});
}

// UTILS

/**
Expand Down
6 changes: 5 additions & 1 deletion src/service/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export default class Runner {
gitCli: git,
});
} catch(error) {
this.logger.error(`Something went wrong backporting to ${pr.base}: ${error}`);
const error = `Something went wrong backporting to ${pr.base}: ${error}`;
if (!args.dryRun) {
gitApi.commentError(configs.originalPullRequest.url, error)
}
this.logger.error(error);
failures.push(error as string);
}
}
Expand Down

0 comments on commit ef940d1

Please sign in to comment.