Skip to content

Commit

Permalink
add: parameterize branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
shqear93 committed Apr 30, 2024
1 parent 9fd5a39 commit 48e04c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jobs:
### Action inputs
| Name | Description | Required | Default |
|----------------|----------------------------------------------|----------|---------|
| `github-token` | Token that is used to create comments | ✅ | |
| `check-names` | Comma-separated list of check names to rerun | ✅ | |

| Name | Description | Required | Default |
|-----------------|----------------------------------------------|----------|--------------------------------------------------|
| `github-token` | Token that is used to create comments | ✅ | |
| `check-names` | Comma-separated list of check names to rerun | ✅ | |
| `target-branch` | Branch for which checks should be rerun | ❌ | the head ref of the pull request, default branch |
## Permissions

Depending on the permissions granted to your token, you may lack some rights.
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ inputs:
github-token:
description: 'GitHub token'
required: true
target-branch:
description: |
Branch for which checks should be rerun.
If not provided, the branch of the pull request that triggered
the workflow is used
required: false

runs:
using: 'node20'
Expand Down
11 changes: 10 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33746,7 +33746,16 @@ async function run() {
try {
const checkNames = core.getInput('check-names').split(', ');
const { owner, repo } = github.context.repo;
const branch = github.context.payload.pull_request.head.ref;
let branch = null;

if (core.getInput('target-branch')) {
branch = core.getInput('target-branch');
} else if (github.context.payload.pull_request) {
branch = github.context.payload.pull_request.head.ref;
} else {
const repoInfo = await octokit.rest.repos.get({ owner, repo });
branch = repoInfo.data.default_branch; // default branch
}

const token = core.getInput('github-token');
const octokit = github.getOctokit(token);
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ async function run() {
try {
const checkNames = core.getInput('check-names').split(', ');
const { owner, repo } = github.context.repo;
const branch = github.context.payload.pull_request.head.ref;
let branch = null;

if (core.getInput('target-branch')) {
branch = core.getInput('target-branch');
} else if (github.context.payload.pull_request) {
branch = github.context.payload.pull_request.head.ref;
} else {
const repoInfo = await octokit.rest.repos.get({ owner, repo });
branch = repoInfo.data.default_branch; // default branch
}

const token = core.getInput('github-token');
const octokit = github.getOctokit(token);
Expand Down

0 comments on commit 48e04c1

Please sign in to comment.