Skip to content

Commit b574b07

Browse files
authored
Merge pull request #101 from angaduom/fix-branch-targeting-per-repo-type
feat: create separate PRs per branch for downstream repos in cve.fix
2 parents 89473ac + 4de3e64 commit b574b07

File tree

2 files changed

+325
-83
lines changed

2 files changed

+325
-83
lines changed

workflows/cve-fixer/.claude/commands/cve.find.md

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Report: artifacts/cve-fixer/find/cve-issues-20260226-145018.md
3333
1. **Parse Arguments and Flags**
3434
- Parse the command arguments for the component name, optional subcomponent, and optional flags
3535
- **Supported flags:**
36-
- `--ignore-resolved` — Exclude issues with Jira status "Resolved" from results
36+
- `--ignore-resolved` — Exclude issues with status "Resolved" from results
37+
- `--ignore-vex` — Exclude issues already closed as "Not a Bug" with a VEX justification
3738
- The component name is the first argument that is not a flag
3839
- The subcomponent is the second positional argument that is not a flag (optional)
3940
- If component is not provided, ask the user to type the component name
@@ -51,62 +52,52 @@ Report: artifacts/cve-fixer/find/cve-issues-20260226-145018.md
5152
/cve.find "AI Evaluations" trustyai-ragas
5253
```
5354

54-
2. **Check JIRA API Token (REQUIRED - User Setup)**
55-
- **This is the ONLY thing the user must configure manually before proceeding**
55+
2. **Verify Jira Access**
5656

57-
- Check if JIRA_API_TOKEN and JIRA_EMAIL are set:
58-
```bash
59-
if [ -z "$JIRA_API_TOKEN" ]; then
60-
echo "ERROR: JIRA_API_TOKEN is not set"
61-
else
62-
echo "JIRA_API_TOKEN is set"
63-
fi
64-
if [ -z "$JIRA_EMAIL" ]; then
65-
echo "ERROR: JIRA_EMAIL is not set"
66-
else
67-
echo "JIRA_EMAIL is set"
68-
fi
69-
```
70-
71-
- **If JIRA_API_TOKEN or JIRA_EMAIL is NOT set or empty**:
72-
- **STOP here and inform the user they need to set up both variables first**
73-
- Provide instructions:
74-
75-
**Step 1: Generate a Jira API Token**
76-
- Go to https://id.atlassian.com/manage-profile/security/api-tokens
77-
- Click "Create API token"
78-
- Give it a name and copy the token
79-
80-
**Step 2: Export both environment variables**
81-
```bash
82-
export JIRA_API_TOKEN="your-token-here"
83-
export JIRA_EMAIL="your-email@redhat.com"
84-
```
85-
To make it persistent, add to `~/.bashrc` or `~/.zshrc`:
86-
```bash
87-
echo 'export JIRA_API_TOKEN="your-token-here"' >> ~/.bashrc
88-
echo 'export JIRA_EMAIL="your-email@redhat.com"' >> ~/.bashrc
89-
source ~/.bashrc
90-
```
91-
92-
- **After user sets the variables, verify they're exported correctly** using the check script above
93-
- Should output: "JIRA_API_TOKEN is set" and "JIRA_EMAIL is set"
94-
95-
- **Only proceed to the next steps if both JIRA_API_TOKEN and JIRA_EMAIL are set**
57+
Secrets may be injected by the Ambient session, a secrets manager, or an MCP server — do NOT rely solely on bash env var checks. Instead, attempt a lightweight test API call and let the response determine whether credentials are available.
58+
59+
```bash
60+
JIRA_BASE_URL="https://redhat.atlassian.net"
61+
AUTH=$(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64)
62+
63+
# Retry once on network failure (curl exit code 000 = timeout/no response)
64+
for ATTEMPT in 1 2; do
65+
TEST_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X GET \
66+
--connect-timeout 10 --max-time 15 \
67+
-H "Authorization: Basic ${AUTH}" \
68+
-H "Content-Type: application/json" \
69+
"${JIRA_BASE_URL}/rest/api/3/myself")
70+
[ "$TEST_RESPONSE" != "000" ] && break
71+
echo "⚠️ Network timeout on attempt ${ATTEMPT}, retrying..."
72+
sleep 3
73+
done
74+
```
75+
76+
- **HTTP 200** → credentials valid, proceed
77+
- **HTTP 401** → credentials missing or invalid. Note: `/rest/api/3/myself` returns 401 for all authentication failures — there is no separate 403 for this endpoint. Only now inform the user:
78+
- Check if `JIRA_API_TOKEN` and `JIRA_EMAIL` are configured as Ambient session secrets
79+
- If not, generate a token at https://id.atlassian.com/manage-profile/security/api-tokens and export:
80+
81+
```bash
82+
export JIRA_API_TOKEN="your-token-here"
83+
export JIRA_EMAIL="your-email@redhat.com"
84+
```
85+
- **HTTP 000 after retry** → persistent network issue — inform user and stop
86+
87+
**Do NOT pre-check env vars with `[ -z "$JIRA_API_TOKEN" ]` and stop.** The variables may be available to the API call even if not visible to the shell check (e.g. Ambient secrets injection).
9688

9789
3. **Query Jira for CVE Issues**
9890

99-
a. Set up variables:
91+
a. Set up variables (AUTH already set from Step 2):
92+
10093
```bash
10194
COMPONENT_NAME="[from step 1]"
10295
JIRA_BASE_URL="https://redhat.atlassian.net"
103-
JIRA_EMAIL="${JIRA_EMAIL}"
104-
JIRA_API_TOKEN="${JIRA_API_TOKEN}"
105-
# Jira Cloud uses Basic Auth: base64(email:api-token)
106-
AUTH=$(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64)
96+
# AUTH already constructed in Step 2 — reuse it
10797
```
10898

10999
b. Construct JQL query and execute API call:
100+
110101
```bash
111102
# Normalize component name with case-insensitive lookup against mapping file
112103
# Try relative to cwd (workflow root), then repo-relative fallback
@@ -156,6 +147,12 @@ Report: artifacts/cve-fixer/find/cve-issues-20260226-145018.md
156147
JQL="${JQL} AND status not in (\"Resolved\")"
157148
fi
158149
150+
# Append VEX filter if --ignore-vex flag was provided
151+
# Excludes issues closed as "Not a Bug" (VEX justified) or "Obsolete" or "Won't Fix"
152+
if [ "$IGNORE_VEX" = "true" ]; then
153+
JQL="${JQL} AND NOT (status = \"Closed\" AND resolution in (\"Not a Bug\", \"Obsolete\", \"Won't Fix\"))"
154+
fi
155+
159156
# URL-encode the JQL query for the GET request
160157
ENCODED_JQL=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''${JQL}'''))")
161158

0 commit comments

Comments
 (0)