Skip to content

Commit 48e04c1

Browse files
committed
add: parameterize branch name
1 parent 9fd5a39 commit 48e04c1

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ jobs:
3232
3333
### Action inputs
3434
35-
| Name | Description | Required | Default |
36-
|----------------|----------------------------------------------|----------|---------|
37-
| `github-token` | Token that is used to create comments | ✅ | |
38-
| `check-names` | Comma-separated list of check names to rerun | ✅ | |
39-
35+
| Name | Description | Required | Default |
36+
|-----------------|----------------------------------------------|----------|--------------------------------------------------|
37+
| `github-token` | Token that is used to create comments | ✅ | |
38+
| `check-names` | Comma-separated list of check names to rerun | ✅ | |
39+
| `target-branch` | Branch for which checks should be rerun | ❌ | the head ref of the pull request, default branch |
4040
## Permissions
4141

4242
Depending on the permissions granted to your token, you may lack some rights.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ inputs:
1212
github-token:
1313
description: 'GitHub token'
1414
required: true
15+
target-branch:
16+
description: |
17+
Branch for which checks should be rerun.
18+
If not provided, the branch of the pull request that triggered
19+
the workflow is used
20+
required: false
1521

1622
runs:
1723
using: 'node20'

dist/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33746,7 +33746,16 @@ async function run() {
3374633746
try {
3374733747
const checkNames = core.getInput('check-names').split(', ');
3374833748
const { owner, repo } = github.context.repo;
33749-
const branch = github.context.payload.pull_request.head.ref;
33749+
let branch = null;
33750+
33751+
if (core.getInput('target-branch')) {
33752+
branch = core.getInput('target-branch');
33753+
} else if (github.context.payload.pull_request) {
33754+
branch = github.context.payload.pull_request.head.ref;
33755+
} else {
33756+
const repoInfo = await octokit.rest.repos.get({ owner, repo });
33757+
branch = repoInfo.data.default_branch; // default branch
33758+
}
3375033759

3375133760
const token = core.getInput('github-token');
3375233761
const octokit = github.getOctokit(token);

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ async function run() {
55
try {
66
const checkNames = core.getInput('check-names').split(', ');
77
const { owner, repo } = github.context.repo;
8-
const branch = github.context.payload.pull_request.head.ref;
8+
let branch = null;
9+
10+
if (core.getInput('target-branch')) {
11+
branch = core.getInput('target-branch');
12+
} else if (github.context.payload.pull_request) {
13+
branch = github.context.payload.pull_request.head.ref;
14+
} else {
15+
const repoInfo = await octokit.rest.repos.get({ owner, repo });
16+
branch = repoInfo.data.default_branch; // default branch
17+
}
918

1019
const token = core.getInput('github-token');
1120
const octokit = github.getOctokit(token);

0 commit comments

Comments
 (0)