Skip to content

Commit 650039d

Browse files
authored
add ref inputs (#4)
1 parent 81bb51b commit 650039d

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ with:
1919

2020
The action supports the following inputs:
2121
- token - (required) The GitHub token to use for making API requests. Typically, this would be set to ${{ secrets.GITHUB_TOKEN }}.
22+
- ref - (optional) The git ref of the commit you want to check. Default is `github.event.pull_request.head.sha`.
2223
- public-key - (required) The public key of TiDB Cloud api. Generate it from [TiDB Cloud](https://tidbcloud.com/).
2324
- private-key - (required) The private key of TiDB Cloud api. Generate it from [TiDB Cloud](https://tidbcloud.com/).
2425
- interval-seconds - (optional) The interval seconds to check the status of TiDB Cloud Branch check. Default is 10.

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ inputs:
88
token:
99
description: 'The GitHub token to use for making API requests.'
1010
required: true
11+
ref:
12+
description: 'The git ref of the commit you want to check.'
1113
timeout-seconds:
1214
description: 'The number of seconds to wait for the branch ready.'
1315
default: '300'

dist/index.js

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {sqluser} from './sqluser'
55

66
async function run(): Promise<void> {
77
const token = core.getInput('token', {required: true})
8+
let gitRef = core.getInput('ref')
89
const publicKey = core.getInput('public-key', {required: true})
910
const privateKey = core.getInput('private-key', {required: true})
1011
// defensive programming
@@ -18,8 +19,13 @@ async function run(): Promise<void> {
1819
throw new Error('privateKey is empty')
1920
}
2021
try {
21-
if (context.payload.pull_request === undefined) {
22-
throw new Error('This action only works on pull_request events now')
22+
if (gitRef === '' || gitRef === undefined) {
23+
if (context.payload.pull_request === undefined) {
24+
throw new Error(
25+
'This action only works on pull_request events if you do not specify ref'
26+
)
27+
}
28+
gitRef = context.payload.pull_request.head.sha
2329
}
2430
const result = await poll({
2531
client: getOctokit(token),
@@ -28,7 +34,7 @@ async function run(): Promise<void> {
2834
checkName: 'TiDB Cloud Branch',
2935
owner: context.repo.owner,
3036
repo: context.repo.repo,
31-
ref: context.payload.pull_request.head.sha,
37+
ref: gitRef,
3238

3339
timeoutSeconds: parseInt(core.getInput('timeout-seconds')),
3440
intervalSeconds: parseInt(core.getInput('interval-seconds'))

0 commit comments

Comments
 (0)