Skip to content

Commit b8437bb

Browse files
committed
CIHelper: offer a convenient method to parse a PR comment URL
This will be used in the upcoming `handle-pr-comment` GitHub Action. Note that the reason why this information needs to be passed to the respective GitHub Action is that the corresponding GitHub workflows will not run inside `gitgitgadget/git` and will therefore not automatically receive the comment ID and PR number as part of the `github` context. GitGitGadget's GitHub App will need to pass that information along when receiving the webhook event that a PR comment has been created or modified. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent e975b59 commit b8437bb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/ci-helper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ export class CIHelper {
152152
await unshallow(this.workDir);
153153
}
154154

155+
public parsePRCommentURLInput(): { owner: string; repo: string; prNumber: number; commentId: number } {
156+
const prCommentUrl = core.getInput("pr-comment-url");
157+
const [, owner, repo, prNumber, commentId] =
158+
prCommentUrl.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)#issuecomment-(\d+)$/) || [];
159+
if (!this.config.repo.owners.includes(owner) || repo !== this.config.repo.name) {
160+
throw new Error(`Invalid PR comment URL: ${prCommentUrl}`);
161+
}
162+
return { owner, repo, prNumber: parseInt(prNumber, 10), commentId: parseInt(commentId, 10) };
163+
}
164+
155165
public setAccessToken(repositoryOwner: string, token: string): void {
156166
this.github.setAccessToken(repositoryOwner, token);
157167
if (this.config.repo.owner === repositoryOwner) {

0 commit comments

Comments
 (0)