Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/reusable-build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ on:
GSSA_AWS_SECRET_ACCESS_KEY:
description: GSSA AWS secret access key
required: true
ATLASSIAN_EMAIL:
description: Email of the Atlassian user used to post Jira ticket comments
required: true
ATLASSIAN_TOKEN:
description: API token for the Atlassian user used to post Jira ticket comments
required: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new workflow_call secrets are required, but existing callers use explicit secrets: maps and do not pass them. Upgrading a caller to this workflow version will fail validation before any jobs run.

Please update the repository template/callers as part of this rollout, or make these secrets optional until that rollout is complete.

permissions:
contents: read
packages: read
Expand Down Expand Up @@ -373,6 +379,77 @@ jobs:
validateSingleCommit: true
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Validate ADDON Jira ticket in PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
if [[ ! "$PR_TITLE" =~ ADDON-[0-9]{5,6}([^0-9]|$) ]]; then
echo "::error::PR title must contain a Jira ticket in the format ADDON-XXXXX (5-6 digits). Got: $PR_TITLE"
exit 1
fi
Comment thread
mkolasinski-splunk marked this conversation as resolved.

comment-on-jira:
name: Comment on Jira ticket
if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'develop') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Comment on referenced ADDON ticket(s)
env:
GH_TOKEN: ${{ github.token }}
COMMITS: ${{ toJson(github.event.commits) }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}
JIRA_BASE_URL: https://splunk.atlassian.net
ATLASSIAN_EMAIL: ${{ secrets.ATLASSIAN_EMAIL }}
ATLASSIAN_TOKEN: ${{ secrets.ATLASSIAN_TOKEN }}
run: |
SEEN=""
echo "$COMMITS" | jq -c '.[]' | while read -r commit; do
MESSAGE=$(jq -r '.message' <<<"$commit")
SHA=$(jq -r '.id' <<<"$commit")
AUTHOR=$(jq -r '.author.username // .author.name' <<<"$commit")
TICKETS=$(grep -oP 'ADDON-[0-9]{5,6}(?![0-9])' <<<"$MESSAGE" | sort -u)
if [[ -z "$TICKETS" ]]; then
continue
fi
while read -r TICKET; do
if [[ " $SEEN " == *" $TICKET "* ]]; then
continue
fi
SEEN="$SEEN $TICKET"

COMMIT_URL="https://github.com/$REPO/commit/$SHA"
if ! PR_URL=$(gh api "repos/$REPO/commits/$SHA/pulls" --jq '.[0].html_url // ""' 2>/dev/null); then
PR_URL=""
fi
BODY=$(jq -n \
--arg author "$AUTHOR" --arg branch "$BRANCH" --arg repo "$REPO" \
--arg commit_url "$COMMIT_URL" --arg sha "${SHA:0:7}" --arg pr_url "$PR_URL" \
'{body: {type: "doc", version: 1, content: [
{type: "paragraph", content: [
{type: "text", text: ($author + " mentioned this issue in a commit of " + $repo + " on branch " + $branch + ":")}
]},
{type: "paragraph", content: (
[{type: "text", text: $sha, marks: [{type: "link", attrs: {href: $commit_url}}]}]
+ (if $pr_url != "" then
[{type: "text", text: " (via "},
{type: "text", text: "PR", marks: [{type: "link", attrs: {href: $pr_url}}]},
{type: "text", text: ")"}]
else [] end)
)}
]}}')

echo "Commenting on $TICKET for commit ${SHA:0:7}"
curl --fail --silent --show-error \
-u "$ATLASSIAN_EMAIL:$ATLASSIAN_TOKEN" \
-H "Content-Type: application/json" \
-X POST "$JIRA_BASE_URL/rest/api/3/issue/$TICKET/comment" \
-d "$BODY" || echo "::warning::Failed to comment on $TICKET for commit ${SHA:0:7}"
done <<<"$TICKETS"
done

meta:
runs-on: ubuntu-latest
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [[Job] check-docs-changes](#job-check-docs-changes)
* [[Job] setup-workflow](#job-setup-workflow)
* [[Job] validate-pr-title](#job-validate-pr-title)
* [[Job] comment-on-jira](#job-comment-on-jira)
* [[Job] meta](#job-meta)
* [[Job] fossa-scan](#job-fossa-scan)
* [[Job] fossa-test](#job-fossa-test)
Expand Down Expand Up @@ -285,6 +286,23 @@ gitGraph
- No additional artifacts.


## [Job] comment-on-jira

**Description:**

- Runs only on push events to `main` or `develop`.
- Scans the commit messages in the push for an `ADDON-XXXXX` Jira ticket reference (5-6 digits) and posts a comment on each referenced ticket (e.g. "*author* mentioned this issue in a commit of *repo* on branch *branch*:") linking back to the commit (and originating PR, if found).
- Requires the `ATLASSIAN_EMAIL` and `ATLASSIAN_TOKEN` secrets to be configured; the Atlassian user needs comment permission on the referenced tickets in `https://splunk.atlassian.net`.

**Pass/fail behaviour:**

- Never fails the workflow: a failed Jira API call only logs a warning.

**Artifacts:**

- No additional artifacts.


## [Job] meta

**Description:**
Expand Down
Loading