Skip to content
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/autocomment_jira_link.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: autocomment_jira_link

on:
pull_request:
paths:
- 'content/**'
types:
- opened
permissions:
pull-requests: write
contents: read

jobs:
auto-comment:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: 'actions/checkout@v3'

- name: Create Comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
run: |
set -e

CREATE_COMMENT_URL="https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/comments"

JIRA_TICKET=$(grep -Eo '^DOC-[0-9]+' <<< "$BRANCH_NAME")
JIRA_LINK="https://redislabs.atlassian.net/browse/${JIRA_TICKET}"
COMMENT="[${JIRA_TICKET}](${JIRA_LINK})"

generate_post_data()
{
cat <<EOF
{
"body": "$COMMENT"
EOF
}

if [[ "$BRANCH_NAME" == DOC-* ]]; then
# Write comment on pull request
curl -Ls \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: token ${GITHUB_TOKEN}" \
$CREATE_COMMENT_URL \
--data "$(generate_post_data)" 1>/dev/null

printf '%s\n' 'Comment written!'
fi