Skip to content

Commit

Permalink
Add new trello action
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Nov 14, 2024
1 parent 1f7808a commit dc3787b
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 4 deletions.
126 changes: 126 additions & 0 deletions .github/workflows/traceability-comments-trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: traceability-comments-trigger

permissions:
checks: write
pull-requests: read

on:
issue_comment:
types:
- created
- edited
- deleted

jobs:
traceability-comments-trigger:
runs-on: ubuntu-latest
if: github.event.issue.pull_request
steps:
- name: "Get Pull Request for Comment"
uses: actions/github-script@v6
id: get-commit
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.rest.pulls.get(request)
core.debug(result)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: "Get Check Run For Pull Request"
uses: actions/github-script@v6
id: get-check-runs
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
ref: `${{ fromJSON(steps.get-commit.outputs.result).head.sha }}`,
check_name: 'traceability-comments',
filter: 'latest'
}
core.info(`Getting check-runs for ${request.ref} from ${request.owner}/${request.repo}`)
try {
const result = await github.rest.checks.listForRef(request)
core.debug(result)
if (result.data.check_runs.length > 0) {
return {
runs: JSON.stringify(result.data.check_runs),
continue: true
}
}
else {
return {
continue: false
}
}
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: "Cancel Check Runs"
uses: actions/github-script@v6
id: cancel-check-run
if: ${{ fromJSON(steps.get-check-runs.outputs.result).continue }}
with:
script: |
const checkRuns = ${{ fromJSON(steps.get-check-runs.outputs.result).runs }}
for (const checkRun of checkRuns) {
const checkRunId = checkRun.id
const checkRunStatus = checkRun.status
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: checkRunId,
conclusion: 'cancelled',
output: {
title: 'Cancelled.',
summary: 'Check Run cancelled by "traceability-comments-trigger.yaml".',
}
}
if (checkRunStatus !== 'completed') {
core.info(`Cancelling check-run ${checkRunId} from ${request.owner}/${request.repo}`)
try {
const result = await github.rest.checks.update(request)
core.debug(result)
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
} else {
core.info(`No need to cancel check-run ${checkRunId}`)
}
}
- name: "Re-request Check Suite"
uses: actions/github-script@v6
id: rerequest-check-suite
if: ${{ fromJSON(steps.get-check-runs.outputs.result).continue }}
with:
script: |
const checkRuns = ${{ fromJSON(steps.get-check-runs.outputs.result).runs }}
for (const checkRun of checkRuns) {
const checkSuiteId = checkRun.check_suite.id
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
check_suite_id: checkSuiteId
}
try {
core.info(`Re-requesting check-suite ${request.check_suite_id} from ${request.owner}/${request.repo}`)
const result = await github.rest.checks.rerequestSuite(request)
core.debug(result)
} catch (err) {
// we cancelled any running check-suite in the step before this one, so if we get an error here saying
// a check-suite is already re-running it means something else triggered it to rerun between this step
// and the last. That is what we wanted to do anyways, so we can ignore these errors.
if (err.response.data.message === 'This check suite is already re-running.') {
return
}
core.setFailed(`Request failed with error ${err}`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ jobs:
validate-pr:
runs-on: ubuntu-latest
steps:
- uses: neo4j/github-action-traceability@v1
- uses: neo4j/github-action-traceability@v2
with:
global_verification_strategy: commits_and_pr_title
short_link_verification_strategy: trello_or_noid
global_verification_strategy: comments
trello_api_key: ${{ secrets.TRELLO_API_KEY }}
trello_api_token: ${{ secrets.TRELLO_API_TOKEN }}
github_api_token: ${{ secrets.GITHUB_TOKEN }}
github_api_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit dc3787b

Please sign in to comment.