Skip to content

Commit 381e591

Browse files
authored
Add new trello action (#687)
1 parent d499fa3 commit 381e591

File tree

2 files changed

+129
-4
lines changed

2 files changed

+129
-4
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: traceability-trigger
2+
3+
permissions:
4+
checks: write
5+
pull-requests: read
6+
7+
on:
8+
issue_comment:
9+
types:
10+
- created
11+
- edited
12+
- deleted
13+
14+
jobs:
15+
traceability-trigger:
16+
runs-on: ubuntu-latest
17+
if: github.event.issue.pull_request
18+
steps:
19+
- name: "Get Pull Request for Comment"
20+
uses: actions/github-script@v6
21+
id: get-commit
22+
with:
23+
script: |
24+
const request = {
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
pull_number: context.issue.number
28+
}
29+
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
30+
try {
31+
const result = await github.rest.pulls.get(request)
32+
core.debug(result)
33+
return result.data
34+
} catch (err) {
35+
core.setFailed(`Request failed with error ${err}`)
36+
}
37+
- name: "Get Check Run For Pull Request"
38+
uses: actions/github-script@v6
39+
id: get-check-runs
40+
with:
41+
script: |
42+
const request = {
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
ref: `${{ fromJSON(steps.get-commit.outputs.result).head.sha }}`,
46+
check_name: 'traceability',
47+
filter: 'latest'
48+
}
49+
core.info(`Getting check-runs for ${request.ref} from ${request.owner}/${request.repo}`)
50+
try {
51+
const result = await github.rest.checks.listForRef(request)
52+
core.debug(result)
53+
if (result.data.check_runs.length > 0) {
54+
return {
55+
runs: JSON.stringify(result.data.check_runs),
56+
continue: true
57+
}
58+
}
59+
else {
60+
return {
61+
continue: false
62+
}
63+
}
64+
} catch (err) {
65+
core.setFailed(`Request failed with error ${err}`)
66+
}
67+
- name: "Cancel Check Runs"
68+
uses: actions/github-script@v6
69+
id: cancel-check-run
70+
if: ${{ fromJSON(steps.get-check-runs.outputs.result).continue }}
71+
with:
72+
script: |
73+
const checkRuns = ${{ fromJSON(steps.get-check-runs.outputs.result).runs }}
74+
for (const checkRun of checkRuns) {
75+
const checkRunId = checkRun.id
76+
const checkRunStatus = checkRun.status
77+
const request = {
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
check_run_id: checkRunId,
81+
conclusion: 'cancelled',
82+
output: {
83+
title: 'Cancelled.',
84+
summary: 'Check Run cancelled by "traceability-trigger.yaml".',
85+
}
86+
}
87+
if (checkRunStatus !== 'completed') {
88+
core.info(`Cancelling check-run ${checkRunId} from ${request.owner}/${request.repo}`)
89+
try {
90+
const result = await github.rest.checks.update(request)
91+
core.debug(result)
92+
} catch (err) {
93+
core.setFailed(`Request failed with error ${err}`)
94+
}
95+
} else {
96+
core.info(`No need to cancel check-run ${checkRunId}`)
97+
}
98+
}
99+
- name: "Re-request Check Suite"
100+
uses: actions/github-script@v6
101+
id: rerequest-check-suite
102+
if: ${{ fromJSON(steps.get-check-runs.outputs.result).continue }}
103+
with:
104+
script: |
105+
const checkRuns = ${{ fromJSON(steps.get-check-runs.outputs.result).runs }}
106+
for (const checkRun of checkRuns) {
107+
const checkSuiteId = checkRun.check_suite.id
108+
const request = {
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
check_suite_id: checkSuiteId
112+
}
113+
try {
114+
core.info(`Re-requesting check-suite ${request.check_suite_id} from ${request.owner}/${request.repo}`)
115+
const result = await github.rest.checks.rerequestSuite(request)
116+
core.debug(result)
117+
} catch (err) {
118+
// we cancelled any running check-suite in the step before this one, so if we get an error here saying
119+
// a check-suite is already re-running it means something else triggered it to rerun between this step
120+
// and the last. That is what we wanted to do anyways, so we can ignore these errors.
121+
if (err.response.data.message === 'This check suite is already re-running.') {
122+
return
123+
}
124+
core.setFailed(`Request failed with error ${err}`)
125+
}
126+
}

.github/workflows/traceability.yml renamed to .github/workflows/traceability-comments.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ jobs:
1414
validate-pr:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: neo4j/github-action-traceability@v1
17+
- uses: neo4j/github-action-traceability@v2
1818
with:
19-
global_verification_strategy: commits_and_pr_title
20-
short_link_verification_strategy: trello_or_noid
19+
global_verification_strategy: comments
2120
trello_api_key: ${{ secrets.TRELLO_API_KEY }}
2221
trello_api_token: ${{ secrets.TRELLO_API_TOKEN }}
23-
github_api_token: ${{ secrets.GITHUB_TOKEN }}
22+
github_api_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)