|
| 1 | +name: PR Label Notification |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, opened, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + # ════════════════════════════════════════════════════════════════════════ |
| 9 | + # JOB 1: Triggered when PR is labeled/opened — creates ADO work item |
| 10 | + # ════════════════════════════════════════════════════════════════════════ |
| 11 | + notify-on-label: |
| 12 | + name: Create ADO Work Item on Label |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: contains(github.event.pull_request.labels.*.name, 'ASIM') |
| 15 | + |
| 16 | + steps: |
| 17 | + # ── Step 1: Collect PR metadata ────────────────────────────────────── |
| 18 | + - name: Set PR Info |
| 19 | + id: pr_info |
| 20 | + run: | |
| 21 | + echo "pr_title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT |
| 22 | + echo "pr_url=${{ github.event.pull_request.html_url }}" >> $GITHUB_OUTPUT |
| 23 | + echo "pr_author=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT |
| 24 | + echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT |
| 25 | + echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT |
| 26 | + echo "label=${{ github.event.label.name }}" >> $GITHUB_OUTPUT |
| 27 | +
|
| 28 | + # ── Step 2: Create ADO Work Item ───────────────────────────────────── |
| 29 | + - name: Create ADO Work Item |
| 30 | + id: ado_task |
| 31 | + run: | |
| 32 | + RESPONSE=$(curl -s -X POST \ |
| 33 | + -u ":${{ secrets.ASIM_ADO_PAT }}" \ |
| 34 | + -H "Content-Type: application/json-patch+json" \ |
| 35 | + -d '[ |
| 36 | + { |
| 37 | + "op": "add", |
| 38 | + "path": "/fields/System.Title", |
| 39 | + "value": "PR #${{ steps.pr_info.outputs.pr_number }}: ${{ steps.pr_info.outputs.pr_title }}" |
| 40 | + }, |
| 41 | + { |
| 42 | + "op": "add", |
| 43 | + "path": "/fields/System.Description", |
| 44 | + "value": "<b>GitHub PR:</b> \"${{<br/><b>Author:</b> ${{ steps.pr_info.outputs.pr_author }}<br/><b>Label:</b> ${{ steps.pr_info.outputs.label }}<br/><b>Repo:</b> ${{ steps.pr_info.outputs.repo }}" |
| 45 | + }, |
| 46 | + { |
| 47 | + "op": "add", |
| 48 | + "path": "/fields/System.AssignedTo", |
| 49 | + "value": "${{ secrets.ASIM_ADO_ASSIGNED_TO }}" |
| 50 | + }, |
| 51 | + { |
| 52 | + "op": "add", |
| 53 | + "path": "/fields/System.AreaPath", |
| 54 | + "value": "${{ secrets.ASIM_ADO_AREA_PATH }}" |
| 55 | + }, |
| 56 | + { |
| 57 | + "op": "add", |
| 58 | + "path": "/fields/System.Tags", |
| 59 | + "value": "github-pr; ASIM" |
| 60 | + }, |
| 61 | + { |
| 62 | + "op": "add", |
| 63 | + "path": "/fields/Microsoft.VSTS.Common.Priority", |
| 64 | + "value": 2 |
| 65 | + }, |
| 66 | + { |
| 67 | + "op": "add", |
| 68 | + "path": "/relations/-", |
| 69 | + "value": { |
| 70 | + "rel": "Hyperlink", |
| 71 | + "url": "${{ steps.pr_info.outputs.pr_url }}", |
| 72 | + "attributes": { "comment": "Linked GitHub PR" } |
| 73 | + } |
| 74 | + }, |
| 75 | + { |
| 76 | + "op": "add", |
| 77 | + "path": "/relations/-", |
| 78 | + "value": { |
| 79 | + "rel": "System.LinkTypes.Hierarchy-Reverse", |
| 80 | + "url": "${{ secrets.ASIM_ADO_URL }}/${{ secrets.ASIM_ADO_PROJECT }}/_apis/wit/workitems/5177225", |
| 81 | + "attributes": { "comment": "Child of PBI #5177225" } |
| 82 | + } |
| 83 | + } |
| 84 | + ]' \ |
| 85 | + "${{ secrets.ASIM_ADO_URL }}/${{ secrets.ASIM_ADO_PROJECT }}/_apis/wit/workitems/\$Task?api-version=7.1") |
| 86 | +
|
| 87 | + ADO_ITEM_ID=$(echo $RESPONSE | python3 -c "import sys, json; print(json.load(sys.stdin)['id'])") |
0 commit comments