Skip to content

Feature Orchestrator Plugin: Skills (2/5), Fixes AB#3545054 #221

Feature Orchestrator Plugin: Skills (2/5), Fixes AB#3545054

Feature Orchestrator Plugin: Skills (2/5), Fixes AB#3545054 #221

# This workflow checks if an ADO ID (AB#ID) has been set successfully (https://github.com/marketplace/actions/azure-boards-check-for-ab)
# If so, the workflow will extract the AB ID from the message
# then it will update the PR title adding ',Fixed AB#ID' at the end.
# Why?
# Adding ',Fixed AB#ID' to the PR title will make the PR to automatically resolve the associated ADO item when the PR is completed.
name: 'AB#ID Check'
on:
pull_request:
types: [opened, reopened, edited, labeled, synchronize]
jobs:
check-and-apply-abid:
name: Check and apply AB#ID to PR title
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip AB ID validation')"
steps:
- name: Validate PR is linked to a work item
uses: danhellem/github-actions-pr-is-linked-to-work-item@main
continue-on-error: true
- name: Prepare environment
id: env
run: |
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "pr_body<<EOF" >> $GITHUB_OUTPUT
echo "${{ github.event.pull_request.body }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Extract AB ID from PR body
id: extract-ab
shell: bash
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
clean=$(printf "%s" "$PR_BODY" | tr -d '`')
# Get first AB ID if multiple are present
abid=$(printf "%s" "$clean" | grep -oP '(?<=AB#)\d+' | head -n1 || true)
echo "abid=${abid}" >> $GITHUB_OUTPUT
- name: Abort if no AB ID found
if: steps.extract-ab.outputs.abid == ''
run: |
echo "No AB ID found in PR body; failing the workflow."
exit 1
- name: Get current PR title
id: get-title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_ID: ${{ github.event.pull_request.number }}
run: |
PR_TITLE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls/${{ env.PR_ID }} | jq -r .title)
echo "title=$PR_TITLE" >> $GITHUB_OUTPUT
- name: Decide if title needs update
id: decide
shell: bash
env:
PR_TITLE: ${{ steps.get-title.outputs.title }}
AB_ID: ${{ steps.extract-ab.outputs.abid }}
run: |
if [ -z "${AB_ID}" ]; then
echo "update_required=false" >> $GITHUB_OUTPUT
exit 0
fi
if echo "$PR_TITLE" | grep -i -qE '\bfix(es|ed)?\b.*AB#[0-9]'; then
echo "update_required=false" >> $GITHUB_OUTPUT
else
NEW_TITLE="$PR_TITLE, Fixes AB#${AB_ID}"
echo "update_required=true" >> $GITHUB_OUTPUT
echo "new_title=${NEW_TITLE}" >> $GITHUB_OUTPUT
fi
- name: Update PR title (if required)
if: steps.decide.outputs.update_required == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_ID: ${{ github.event.pull_request.number }}
NEW_TITLE: ${{ steps.decide.outputs.new_title }}
run: |
curl -s -X PATCH -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls/${{ env.PR_ID }} -d '{"title":"'"${{ env.NEW_TITLE }}"'"}'
- name: Final status reporting
if: always()
run: |
# Consider the run successful if either title was updated or the PR was skipped due to missing AB ID
if [ "${{ steps.decide.outputs.update_required }}" == "true" ]; then
echo "PR title updated to include AB ID."
exit 0
fi
if [ "${{ steps.extract-ab.outputs.abid }}" == "" ]; then
echo "No AB ID found; validation skipped by design."
exit 0
fi
echo "No change required or validation passed."