Skip to content

Commit 7708801

Browse files
Fix triage_labelled GHA workflow (#18913)
1 parent d3fc638 commit 7708801

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# 1) Resolve project ID.
5+
PROJECT_ID=$(gh project view "$PROJECT_NUMBER" --owner "$PROJECT_OWNER" --format json | jq -r '.id')
6+
7+
# 2) Find existing item (project card) for this issue.
8+
ITEM_ID=$(
9+
gh project item-list "$PROJECT_NUMBER" --owner "$PROJECT_OWNER" --format json \
10+
| jq -r --arg url "$ISSUE_URL" '.items[] | select(.content.url==$url) | .id' | head -n1
11+
)
12+
13+
# 3) If one doesn't exist, add this issue to the project.
14+
if [ -z "${ITEM_ID:-}" ]; then
15+
ITEM_ID=$(gh project item-add "$PROJECT_NUMBER" --owner "$PROJECT_OWNER" --url "$ISSUE_URL" --format json | jq -r '.id')
16+
fi
17+
18+
# 4) Get Status field id + the option id for TARGET_STATUS.
19+
FIELDS_JSON=$(gh project field-list "$PROJECT_NUMBER" --owner "$PROJECT_OWNER" --format json)
20+
STATUS_FIELD=$(echo "$FIELDS_JSON" | jq -r '.fields[] | select(.name=="Status")')
21+
STATUS_FIELD_ID=$(echo "$STATUS_FIELD" | jq -r '.id')
22+
OPTION_ID=$(echo "$STATUS_FIELD" | jq -r --arg name "$TARGET_STATUS" '.options[] | select(.name==$name) | .id')
23+
24+
if [ -z "${OPTION_ID:-}" ]; then
25+
echo "No Status option named \"$TARGET_STATUS\" found"; exit 1
26+
fi
27+
28+
# 5) Set Status (moves item to the matching column in the board view).
29+
gh project item-edit --id "$ITEM_ID" --project-id "$PROJECT_ID" --field-id "$STATUS_FIELD_ID" --single-select-option-id "$OPTION_ID"

.github/workflows/triage_labelled.yml

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,26 @@ on:
66

77
jobs:
88
move_needs_info:
9-
name: Move X-Needs-Info on the triage board
109
runs-on: ubuntu-latest
1110
if: >
1211
contains(github.event.issue.labels.*.name, 'X-Needs-Info')
12+
permissions:
13+
contents: read
14+
env:
15+
# This token must have the following scopes: ["repo:public_repo", "admin:org->read:org", "user->read:user", "project"]
16+
GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }}
17+
PROJECT_OWNER: matrix-org
18+
# Backend issue triage board.
19+
# https://github.com/orgs/matrix-org/projects/67/views/1
20+
PROJECT_NUMBER: 67
21+
ISSUE_URL: ${{ github.event.issue.html_url }}
22+
# This field is case-sensitive.
23+
TARGET_STATUS: Needs info
1324
steps:
14-
- uses: actions/add-to-project@4515659e2b458b27365e167605ac44f219494b66 # v1.0.2
15-
id: add_project
25+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1626
with:
17-
project-url: "https://github.com/orgs/matrix-org/projects/67"
18-
github-token: ${{ secrets.ELEMENT_BOT_TOKEN }}
19-
# This action will error if the issue already exists on the project. Which is
20-
# common as `X-Needs-Info` will often be added to issues that are already in
21-
# the triage queue. Prevent the whole job from failing in this case.
22-
continue-on-error: true
23-
- name: Set status
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }}
26-
run: |
27-
gh api graphql -f query='
28-
mutation(
29-
$project: ID!
30-
$item: ID!
31-
$fieldid: ID!
32-
$columnid: String!
33-
) {
34-
updateProjectV2ItemFieldValue(
35-
input: {
36-
projectId: $project
37-
itemId: $item
38-
fieldId: $fieldid
39-
value: {
40-
singleSelectOptionId: $columnid
41-
}
42-
}
43-
) {
44-
projectV2Item {
45-
id
46-
}
47-
}
48-
}' -f project="PVT_kwDOAIB0Bs4AFDdZ" -f item=${{ steps.add_project.outputs.itemId }} -f fieldid="PVTSSF_lADOAIB0Bs4AFDdZzgC6ZA4" -f columnid=ba22e43c --silent
27+
# Only clone the script file we care about, instead of the whole repo.
28+
sparse-checkout: .ci/scripts/triage_labelled_issue.sh
29+
30+
- name: Ensure issue exists on the board, then set Status
31+
run: .ci/scripts/triage_labelled_issue.sh

changelog.d/18913.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the GitHub Actions workflow that moves issues labeled "X-Needs-Info" to the "Needs info" column on the team's internal triage board.

0 commit comments

Comments
 (0)