Skip to content

Commit

Permalink
fix: use rerun_url in rerun-pr-checks to ensure base url is correct (#…
Browse files Browse the repository at this point in the history
…171)

* fix: allow passing baseurl to request()

* chore: snake case

* just use rerun url instead

* no more defaults..

* only grab completed ones

* chore: comitting generated dist

Co-authored-by: aschwenn <[email protected]>
  • Loading branch information
aschwenn and aschwenn authored Mar 30, 2022
1 parent 4501c7a commit 721cd28
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
9 changes: 3 additions & 6 deletions dist/766.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/766.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/helpers/rerun-pr-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const rerunPrChecks = async () => {
...context.repo,
owner,
event,
per_page: 100
per_page: 100,
status: 'completed'
})
);
const workflowRuns = workflowRunResponses.map(response => response.data.workflow_runs).flat();
Expand All @@ -49,12 +50,9 @@ export const rerunPrChecks = async () => {
const latestWorkflowRuns = workflowRuns.filter(({ head_sha }) => head_sha === latestHash);
core.info(`There are ${latestWorkflowRuns.length} checks associated with the latest commit, triggering reruns...`);

return map(latestWorkflowRuns, async ({ id, name }) => {
return map(latestWorkflowRuns, async ({ id, name, rerun_url }) => {
core.info(`- Rerunning ${name} (${id})`);
await request('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: id,
await request(`POST ${rerun_url}`, {
headers: {
authorization: `token ${core.getInput('github_token')}`
}
Expand Down
54 changes: 22 additions & 32 deletions test/helpers/rerun-pr-checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ const prWorkflowRuns = {
{
id: 1001,
name: 'danger',
head_sha: 'aef123'
head_sha: 'aef123',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1001/rerun'
},
{
id: 1002,
name: 'build',
head_sha: 'aef123'
head_sha: 'aef123',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1002/rerun'
},
{
id: 1003,
name: 'danger',
head_sha: 'efc459'
head_sha: 'efc459',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1003/rerun'
}
]
};
Expand All @@ -52,17 +55,20 @@ const prTargetWorkflowRuns = {
{
id: 1004,
name: 'danger',
head_sha: 'aef123'
head_sha: 'aef123',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1004/rerun'
},
{
id: 1005,
name: 'build',
head_sha: 'aef123'
head_sha: 'aef123',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1005/rerun'
},
{
id: 1006,
name: 'danger',
head_sha: 'efc459'
head_sha: 'efc459',
rerun_url: 'https://api.github.com/repos/owner/repo/actions/runs/1006/rerun'
}
]
};
Expand Down Expand Up @@ -100,60 +106,44 @@ describe('rerunPrChecks', () => {
repo: context.repo.repo,
owner,
event: 'pull_request',
per_page: 100
per_page: 100,
status: 'completed'
});
expect(octokit.actions.listWorkflowRunsForRepo).toHaveBeenCalledWith({
branch,
repo: context.repo.repo,
owner,
event: 'pull_request_target',
per_page: 100
per_page: 100,
status: 'completed'
});

expect(request).toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1001,
expect(request).toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1001/rerun', {
headers: {
authorization: `token ${gh_token}`
}
});
expect(request).toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1002,
expect(request).toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1002/rerun', {
headers: {
authorization: `token ${gh_token}`
}
});
expect(request).not.toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1003,
expect(request).not.toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1003/rerun', {
headers: {
authorization: `token ${gh_token}`
}
});
expect(request).toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1004,
expect(request).toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1004/rerun', {
headers: {
authorization: `token ${gh_token}`
}
});
expect(request).toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1005,
expect(request).toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1005/rerun', {
headers: {
authorization: `token ${gh_token}`
}
});
expect(request).not.toHaveBeenCalledWith('POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun', {
owner,
repo: context.repo.repo,
run_id: 1006,
expect(request).not.toHaveBeenCalledWith('POST https://api.github.com/repos/owner/repo/actions/runs/1006/rerun', {
headers: {
authorization: `token ${gh_token}`
}
Expand Down

0 comments on commit 721cd28

Please sign in to comment.