Skip to content

Hello, this is an amazing title, Fixes AB#1234 #26

Hello, this is an amazing title, Fixes AB#1234

Hello, this is an amazing title, Fixes AB#1234 #26

Workflow file for this run

# This workflow detects if the AB validation check has succeeded.
# If a success message has been posted, the workflow will extract the AB ID from the message and create an empty commit with the next message Fixed AB#ID.
# This action will mark the PR to automatically resolve the associated ADO item when the PR is completed.
# For more details about the AB validation, see: https://github.com/marketplace/actions/azure-boards-check-for-ab
# if the message has been posted the action will ex
name: "Commit message 'Fix AB#ID' on branch"
# Triggers the workflow when a new issue comment is created
on:
issue_comment:
types: [created]
jobs:
commit_push_AB_ID:
# Checks if the comment is on a pull request and contains the string 'lcc-200'
runs-on: ubuntu-latest
if: github.event.issue.pull_request && contains(github.event.comment.body, 'lcc-200')
steps:
- name: Check if comment with approval has been generated
run: |
echo "PR ready"
# Extracts the AB ID from the comment body using regex and sets it as an environment variable
- name: Set enviroment variable with AB ID
run: |
result=$(echo "${{ github.event.comment.body }}" | grep -oP '(?<=#)\d+')
echo "AB_ID=${result}" >> $GITHUB_ENV
# Extracts the pull request number
- name: Extract pull request number
id: pr
run: echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
# Get current PR title
- name: Get the current PR title
id: current-title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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_NUMBER }} \
| jq -r .title)
echo "CURRENT_PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
# Generate new PR title
- name: Generate new PR title
id: new-title
run: |
NEW_TITLE="$CURRENT_PR_TITLE, Fixes AB#$AB_ID"
echo "NEW_TITLE=${NEW_TITLE}" >> $GITHUB_ENV
# check point
- name: Print envs
run: |
echo "Check env.vars"
echo "$AB_ID"
echo "$PR_TITLE"
echo "$PR_NUMBER"
echo "$CURRENT_PR_TITLE"
echo "$NEW_TITLE"
# Retrieves the branch name associated with the pull request
# Then checks out the PR branch to make a commits and push it
- name: Get PR branch
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
fetch-depth: 0
- name: Commit tag
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit --allow-empty -m "Fixed AB#$AB_ID"
# This requires read and write Workflow permissions
# see: https://github.com/ad-m/github-push-action
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: ${{ steps.comment-branch.outputs.head_ref }}