Skip to content
Merged
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
54 changes: 9 additions & 45 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,13 @@ permissions:
pull-requests: write

jobs:
approve-and-merge:
runs-on: ubuntu-latest
if: ${{ github.event.state == 'success' && github.event.context == 'continuous-integration/jenkins/pr-merge' }}
steps:
- name: log jenkins context
run: |
echo "Context is: ${{ github.event.context }}"
auto-merge:
if: >-
${{ github.event.state == 'success' &&
(github.event.context == 'continuous-integration/jenkins/pr-head' ||
github.event.context == 'continuous-integration/jenkins/pr-merge') }}
uses: flowcommerce/code-steward/.github/workflows/auto-merge.yml@main
with:
sha: ${{ github.event.sha }}
secrets: inherit

- name: find pull request for this commit
id: find_pr
run: |
REPO="${{ github.repository }}"
SHA="${{ github.event.sha }}"

# find the PR associated with this commit
PR_JSON=$(gh pr list --repo "$REPO" --state open --json number,headRefName,labels,headRefOid)
PR_NUMBER=$(echo "$PR_JSON" | jq -r --arg sha "$SHA" '.[] | select(.headRefOid == $sha) | .number')

if [ -z "$PR_NUMBER" ]; then
echo "No open PR found for commit $SHA, exiting.."
exit 0
fi

# check for auto-merge label
HAS_LABEL=$(echo "$PR_JSON" | jq -r --arg sha "$SHA" '.[] | select(.headRefOid == $sha) | .labels[].name' | grep -i '^auto-merge$' || true)

if [ -z "$HAS_LABEL" ]; then
echo "PR #$PR_NUMBER has no 'auto-merge' label, exiting.."
exit 0
fi

echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: approve PR
if: ${{ steps.find_pr.outputs.pr_number != '' }}
run: gh pr review --approve "${{ steps.find_pr.outputs.pr_number }}" --repo "${{ github.repository }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: merge PR
if: ${{ steps.find_pr.outputs.pr_number != '' }}
run: gh pr merge --auto --squash "${{ steps.find_pr.outputs.pr_number }}" --repo "${{ github.repository }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 2 additions & 30 deletions .github/workflows/pr-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,7 @@ name: "PR Title and Description Check"
on:
pull_request:
types: [opened, edited, synchronize]

jobs:
check-title-and-description:
runs-on: ubuntu-latest
steps:
- name: Check PR title and description
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload;
const prTitle = payload.pull_request.title;

// The pattern for JIRA ticket format
// Must be at the beginning of the PR title
// Prefix must be at least 3 uppercase letters
// Excludes tickets with only zeros after the prefix (e.g., XXX-000, XXX-0000)
// Number must be 3 to 6 digits
const jiraPattern = /^[A-Z]{3,}-(?!0+\b)\d{3,6}\b/;

// Check PR title
const hasJiraTitle = jiraPattern.test(prTitle);
console.log(`PR title: ${hasJiraTitle ? 'Valid' : 'Invalid'}`);

if (hasJiraTitle) {
console.log('PR title format is correct.');
} else {
const errorMessage = 'The PR title must start with a valid JIRA ticket with 3-6 digits (e.g., ABC-123, DATAPLATFORM-12345). The ticket must be at the start, use at least 3 uppercase letters, and the number must not be all zeros.';
console.log(errorMessage);
validate:
uses: flowcommerce/code-steward/.github/workflows/pr-validator.yml@main

core.setFailed(errorMessage);
}