Skip to content

Commit 3a84ca1

Browse files
committed
CIHelper: offer a convenient method to parse a PR URL
This will be used in the upcoming `handle-pr-push` GitHub Action. Just like the `handle-pr-comment` Action, this Action will be used in a GitHub workflow that runs in a different repository than the one where the PR lives that is to be processed, therefore the information cannot be passed in via the `github` context, and combined with ease of debugging, I settled on the full PR URL as the unit of information that the Action input should accept. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7bdd196 commit 3a84ca1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"CIsmtphost",
9797
"CIsmtppass",
9898
"CIsmtpopts",
99+
"parsePRURLInput",
99100
"users\\.noreply\\.github\\.com",
100101
],
101102
"cSpell.language": "en-US",

lib/ci-helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ export class CIHelper {
162162
return { owner, repo, prNumber: parseInt(prNumber, 10), commentId: parseInt(commentId, 10) };
163163
}
164164

165+
public parsePRURLInput(): { owner: string; repo: string; prNumber: number } {
166+
const prCommentUrl = core.getInput("pr-url");
167+
168+
const [, owner, repo, prNumber] =
169+
prCommentUrl.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)$/) || [];
170+
if (!this.config.repo.owners.includes(owner) || repo !== this.config.repo.name) {
171+
throw new Error(`Invalid PR comment URL: ${prCommentUrl}`);
172+
}
173+
return { owner, repo, prNumber: parseInt(prNumber, 10) };
174+
}
175+
165176
public setAccessToken(repositoryOwner: string, token: string): void {
166177
this.github.setAccessToken(repositoryOwner, token);
167178
if (this.config.repo.owner === repositoryOwner) {

0 commit comments

Comments
 (0)