Skip to content

Commit ee395f3

Browse files
authored
Merge pull request #46 from dtschiffman/main
Support for on push events if you can provide the pr number
2 parents 6213dcf + 5f9e475 commit ee395f3

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ inputs:
1818
endpoint:
1919
description: 'Your Graphite API endpoint'
2020
default: 'https://api.graphite.dev'
21+
pr_number:
22+
description: 'The pull request number to optimize'
23+
default: ''
2124
timeout:
2225
description: 'Timeout for the network request to Graphite (in seconds)'
2326
default: '30'

dist/index.js

Lines changed: 11 additions & 5 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: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ export async function run(): Promise<void> {
1111
const graphite_token: string = core.getInput('graphite_token')
1212
const endpoint: string = core.getInput('endpoint')
1313
const timeout: string = core.getInput('timeout')
14+
const pr_number_input: string = core.getInput('pr_number')
1415

1516
await requestWorkflow({
1617
graphite_token,
1718
endpoint,
18-
timeout
19+
timeout,
20+
pr_number_input
1921
})
2022
} catch (error) {
2123
// Fail the workflow run if an error occurs
@@ -26,16 +28,23 @@ export async function run(): Promise<void> {
2628
async function requestWorkflow({
2729
graphite_token,
2830
endpoint,
29-
timeout
31+
timeout,
32+
pr_number_input
3033
}: {
3134
graphite_token: string
3235
endpoint: string
3336
timeout: string
37+
pr_number_input: string
3438
}): Promise<void> {
3539
const {
3640
repo: { owner, repo }
3741
} = github.context
3842

43+
// Use pr_number input if provided, otherwise fall back to pull_request context
44+
const prNumber = pr_number_input
45+
? parseInt(pr_number_input, 10)
46+
: github.context.payload.pull_request?.number
47+
3948
const result = await fetch(`${endpoint}/api/v1/ci/optimizer`, {
4049
method: 'POST',
4150
body: JSON.stringify({
@@ -50,7 +59,7 @@ async function requestWorkflow({
5059
owner,
5160
name: repo
5261
},
53-
pr: github.context.payload.pull_request?.number,
62+
pr: prNumber,
5463
sha: github.context.sha,
5564
ref: github.context.ref,
5665
head_ref: process.env.GITHUB_HEAD_REF,
@@ -97,7 +106,7 @@ async function requestWorkflow({
97106
owner,
98107
name: repo
99108
},
100-
pr: github.context.payload.pull_request?.number,
109+
pr: prNumber,
101110
sha: github.context.sha,
102111
ref: github.context.ref,
103112
head_ref: process.env.GITHUB_HEAD_REF,
@@ -110,9 +119,7 @@ async function requestWorkflow({
110119
})
111120
core.warning(`Request body: ${body}`)
112121
core.warning(`Response status: ${result.status}`)
113-
core.warning(
114-
`${owner}/${repo}/${github.context.payload.pull_request?.number}`
115-
)
122+
core.warning(`${owner}/${repo}/${prNumber}`)
116123
core.warning(
117124
'Response returned a non-200 status. Skipping Graphite checks.'
118125
)

0 commit comments

Comments
 (0)