Skip to content

Commit

Permalink
AAP-35427 - Enforce jira item for ansible devs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzoneill committed Nov 22, 2024
1 parent 0bb17c4 commit d4ae3a6
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/jira-linker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: PR Validation for JIRA Issue and Public Membership

on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
validate-pr:
runs-on: ubuntu-latest

steps:
- name: Check if PR author is a public member
id: check_author_membership
run: |
org="ansible" # Replace with your organization name
author="${{ github.event.pull_request.user.login }}"
# Query the public members API
status=$(curl -o /dev/null -s -w "%{http_code}" "https://api.github.com/orgs/$org/public_members/$author")
# Determine membership based on HTTP status code
if [[ $status -eq 204 ]]; then
echo "::set-output name=is_member::true"
elif [[ $status -eq 404 ]]; then
echo "::set-output name=is_member::false"
else
echo "Unexpected HTTP status code: $status"
exit 1
fi
- name: Debug Membership Check Result
run: |
echo "Is member: ${{ steps.check_author_membership.outputs.is_member }}"
- name: Skip validation for non-members
if: steps.check_author_membership.outputs.is_member == 'false'
run: echo "Contributor is not a public member of the organization. Skipping validation."

- name: Validate PR title and branch name
if: steps.check_author_membership.outputs.is_member == 'true'
run: |
# Extract the PR title and source branch
pr_title="${{ github.event.pull_request.title }}"
pr_branch="${{ github.event.pull_request.head.ref }}"
# Define the JIRA issue regex pattern
jira_pattern="^AAP-[0-9]{3,6}"
# Validate the PR title
if [[ ! "$pr_title" =~ $jira_pattern ]]; then
echo "Error: PR title does not start with a valid JIRA issue key (e.g., AAP-123)."
exit 1
fi
# Validate the source branch
if [[ ! "$pr_branch" =~ $jira_pattern ]]; then
echo "Error: Source branch name does not start with a valid JIRA issue key (e.g., AAP-123)."
exit 1
fi
echo "PR title and branch name are valid."
- name: Finalize
run: echo "Validation completed successfully."

0 comments on commit d4ae3a6

Please sign in to comment.