Add support for linking work items in PR title/body #67
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pr_check | |
on: | |
pull_request: | |
branches: main | |
env: | |
# update this | |
azure_devops_org: jjohanning0798 | |
jobs: | |
pr-issues-validation: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: npm install | |
shell: bash | |
run: npm install | |
- name: pr-issues-validation | |
id: pr-issues-validation | |
shell: bash | |
run: | | |
PULL_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") | |
COMMITS=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -H "Accept: application/vnd.github.v3+json" "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PULL_NUMBER}/commits") | |
echo $COMMITS | jq -c '.[]' | while read commit; do | |
COMMIT_SHA=$(echo $commit | jq '.sha') | |
COMMIT_MESSAGE=$(echo $commit | jq '.commit.message') | |
echo "Validating new commit: ${COMMIT_SHA} - ${COMMIT_MESSAGE}" | |
if [[ "$COMMIT_MESSAGE" != *"AB"\#""[0-9]""* ]] && [[ "$COMMIT_MESSAGE" != *"ab"\#""[0-9]""* ]]; then | |
echo "" | |
echo "" | |
echo "Pull request contains invalid commit: ${COMMIT_SHA}. This commit lacks an AB#xxx in the message, in the expected format: AB#xxx -- failing operation." | |
exit 1 | |
else | |
echo "valid commit" | |
# set WORKITEM equal to the number after the # in the commit message | |
WORKITEM=`echo $COMMIT_MESSAGE | cut -d'#' -f2 | cut -d' ' -f1 | tr -d '"'` | |
echo "Workitem = $WORKITEM" | |
# make the call to main.js to do the linking | |
REPO_TOKEN=${{ github.token }} AZURE_DEVOPS_ORG=${{ env.azure_devops_org }} AZURE_DEVOPS_PAT=${{ secrets.AZURE_DEVOPS_PAT }} WORKITEMID=$WORKITEM PULLREQUESTID=${{ github.event.number }} REPO=${{ github.repository }} node main.js | |
fi | |
done |