Skip to content

Commit d5ad64c

Browse files
chore: assign user to vulnerability issues
1 parent 7e589fc commit d5ad64c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/vulnerability-triage.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ jobs:
546546
STRUCTURED_OUTPUT: ${{ steps.claude.outputs.structured_output }}
547547
REPOSITORY: ${{ github.repository }}
548548
run: |
549-
# Look up the "CVE" label ID and "Triage" state ID for the team
550-
METADATA_QUERY='query($teamId: String!) { team(id: $teamId) { id labels(filter: { name: { eq: "CVE" } }) { nodes { id } } states(filter: { name: { eq: "Triage" } }) { nodes { id } } } }'
549+
# Look up the "CVE" label ID, "Triage" state ID, and the API key owner's user ID
550+
METADATA_QUERY='query($teamId: String!) { team(id: $teamId) { id labels(filter: { name: { eq: "CVE" } }) { nodes { id } } states(filter: { name: { eq: "Triage" } }) { nodes { id } } } viewer { id } }'
551551
METADATA_PAYLOAD=$(jq -n --arg query "$METADATA_QUERY" --arg teamId "$LINEAR_TEAM_ID" \
552552
'{query: $query, variables: {teamId: $teamId}}')
553553
METADATA_RESPONSE=$(curl -s -X POST https://api.linear.app/graphql \
@@ -559,6 +559,7 @@ jobs:
559559
TEAM_UUID=$(echo "$METADATA_RESPONSE" | jq -r '.data.team.id // empty')
560560
LABEL_ID=$(echo "$METADATA_RESPONSE" | jq -r '.data.team.labels.nodes[0].id // empty')
561561
STATE_ID=$(echo "$METADATA_RESPONSE" | jq -r '.data.team.states.nodes[0].id // empty')
562+
VIEWER_ID=$(echo "$METADATA_RESPONSE" | jq -r '.data.viewer.id // empty')
562563
563564
if [ -z "$TEAM_UUID" ]; then
564565
echo "::error::Could not resolve team UUID from LINEAR_TEAM_ID. Check the secret value."
@@ -571,6 +572,9 @@ jobs:
571572
if [ -z "$STATE_ID" ]; then
572573
echo "::warning::Could not find 'Triage' state in Linear team. Using default state."
573574
fi
575+
if [ -z "$VIEWER_ID" ]; then
576+
echo "::warning::Could not resolve Linear API key owner. Issues will be created unassigned."
577+
fi
574578
575579
# Map severity to Linear priority
576580
severity_to_priority() {
@@ -594,7 +598,7 @@ jobs:
594598
# Write CVEs to temp file so the while loop doesn't run in a pipe subshell
595599
echo "$STRUCTURED_OUTPUT" | jq -c '.cves[]' > /tmp/cves.jsonl
596600
597-
MUTATION='mutation CreateIssue($teamId: String!, $title: String!, $description: String, $priority: Int, $labelIds: [String!], $stateId: String) { issueCreate(input: { teamId: $teamId, title: $title, description: $description, priority: $priority, labelIds: $labelIds, stateId: $stateId }) { success issue { id identifier url } } }'
601+
MUTATION='mutation CreateIssue($teamId: String!, $title: String!, $description: String, $priority: Int, $labelIds: [String!], $stateId: String, $assigneeId: String) { issueCreate(input: { teamId: $teamId, title: $title, description: $description, priority: $priority, labelIds: $labelIds, stateId: $stateId, assigneeId: $assigneeId }) { success issue { id identifier url } } }'
598602
599603
while IFS= read -r cve; do
600604
CVE_ID=$(echo "$cve" | jq -r '.cveId')
@@ -624,11 +628,14 @@ jobs:
624628
continue
625629
fi
626630
627-
REOPEN_MUTATION='mutation($issueId: String!, $stateId: String!) { issueUpdate(id: $issueId, input: { stateId: $stateId }) { success issue { id identifier url } } }'
631+
REOPEN_MUTATION='mutation($issueId: String!, $stateId: String!, $assigneeId: String) { issueUpdate(id: $issueId, input: { stateId: $stateId, assigneeId: $assigneeId }) { success issue { id identifier url } } }'
628632
REOPEN_VARIABLES=$(jq -n \
629633
--arg issueId "$LINEAR_ISSUE_ID" \
630634
--arg stateId "$STATE_ID" \
631635
'{issueId: $issueId, stateId: $stateId}')
636+
if [ -n "$VIEWER_ID" ]; then
637+
REOPEN_VARIABLES=$(echo "$REOPEN_VARIABLES" | jq --arg aid "$VIEWER_ID" '. + {assigneeId: $aid}')
638+
fi
632639
REOPEN_PAYLOAD=$(jq -n --arg query "$REOPEN_MUTATION" --argjson vars "$REOPEN_VARIABLES" '{query: $query, variables: $vars}')
633640
634641
REOPEN_RESPONSE=$(curl -s -X POST https://api.linear.app/graphql \
@@ -669,6 +676,9 @@ jobs:
669676
if [ -n "$STATE_ID" ]; then
670677
VARIABLES=$(echo "$VARIABLES" | jq --arg sid "$STATE_ID" '. + {stateId: $sid}')
671678
fi
679+
if [ -n "$VIEWER_ID" ]; then
680+
VARIABLES=$(echo "$VARIABLES" | jq --arg aid "$VIEWER_ID" '. + {assigneeId: $aid}')
681+
fi
672682
673683
PAYLOAD=$(jq -n --arg query "$MUTATION" --argjson vars "$VARIABLES" '{query: $query, variables: $vars}')
674684

0 commit comments

Comments
 (0)