This GitHub action checks if a valid JIRA ticket ID exists in the commit message of a pull request. It uses Atlassian JIRA APIs to authenticate and search for the JIRA ticket ID in the pull request title.
To use this action, add the following code to your GitHub repository under .github/workflows/check-jira-ticket-id.yml
:
on:
pull_request:
types: [opened, reopened, edited]
name: Check JIRA ticket ID
jobs:
build:
runs-on: ubuntu-latest
name: Check JIRA ticket ID
steps:
- name: Login to JIRA
uses: atlassian/gajira-login@v3
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
- name: Find in commit messages for JIRA ticket
uses: atlassian/gajira-find-issue-key@v3
with:
string: ${{ github.event.pull_request.title }}
from: ""
- name: Logic to check JIRA ID exists
run: |
#!/bin/bash
# Find the value of my_key in the YAML file
my_key_value=$(grep "issue:" /home/runner/jira/config.yml | cut -d " " -f 2-)
# Check if the value is empty
if [ -z "$my_key_value" ]; then
echo "JIRA id could not found or invalid. Exiting with status code 1."
exit 1
else
echo "JIRA id is: $my_key_value"
fi
This action does not have any inputs.
This action does not have any outputs.
This action requires the following secrets:
JIRA_BASE_URL
: The base URL of your JIRA instance.JIRA_USER_EMAIL
: The email address of a JIRA user with access to the project.JIRA_API_TOKEN
: An API token generated for the JIRA user.
This action is licensed under the MIT License.