Skip to content

check if repo is public AB#239971 #24

check if repo is public AB#239971

check if repo is public AB#239971 #24

name: Validate Work Item in PR
on:
pull_request:
types: [opened, reopened, synchronize, edited]
jobs:
check-work-item:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout Workflows Repository
uses: actions/checkout@v3
with:
repository: optimove-tech/workflows
path: org-workflows
ref: 'main'
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install requests
- name: Get PR title
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PULL_REQUEST=$(gh api ${{ github.event.pull_request.url }})
PR_TITLE=$(echo $PULL_REQUEST | jq --raw-output .title | tr '\n' ' ' | tr -d "[]'")
#PR_BODY=$(echo $PULL_REQUEST | jq --raw-output .body | tr '\n' ' ' | tr -d "[]'")
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
#echo "PR_BODY=$PR_BODY" >> $GITHUB_ENV
- name: Check for Work Item in PR Title
id: ifLinked
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "PR Title: $PR_TITLE"
#echo "PR Body: $PR_BODY"
python3 org-workflows/.github/workflows/validate-ado-wi/validate-pattern.py -checklist "['$PR_TITLE']"
- name: Check Work Item in PR Title is exist
id: ifExists
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADO_PAT: ${{ secrets.ADO_PAT }}
run: |
echo "PR Title: $PR_TITLE"
#echo "PR Body: $PR_BODY"
python3 org-workflows/.github/workflows/validate-ado-wi/validate-wi-exists.py -checklist "['$PR_TITLE']" -organization 'mobius' -project 'Backstage'
- name: Ping PR Author to link Work Item
if: ${{ failure() && steps.ifLinked.conclusion == 'failure' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `πŸ‘‹ Hey @${{ github.event.pull_request.user.login }},
❗️ Work Item link check failed: There is no Work Item linked to this PR.
🧩 Please add the Work Item ID to the PR title using the "Edit" option in the format below:
AB#XXXXX - replace X with a valid Work Item ID.
🟒 Once added, please use "Re-run jobs" in PR check or proceed with "Close pull request" and "Reopen pull request" options below to restart the validation.`
})
- name: Ping PR Author to verify Work Item ID
if: ${{ failure() && steps.ifExists.conclusion == 'failure' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `πŸ‘‹ Hey @${{ github.event.pull_request.user.login }},
πŸ—Ώ The specified Work Item ID could not be found.
πŸ”Ž Make sure the Work Item ID exists in the PR title, and correct it using the "Edit" option in the format below:
AB#XXXXX - replace X with a valid Work Item ID.
🟒 Once corrected, please use "Re-run jobs" in PR check or proceed with "Close pull request" and "Reopen pull request" options below to restart the validation.`
})