Repository navigation
fix(triage): delegate Jira close transitions to fullsend CLI #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
247584d
1ac67d3
e459281
a274b35
20bebaa
f7716a7
711a39e
fbdff0b
f1af399
32c489e
dcf84f2
f34c039
8907b96
6260e21
55da9d7
d7c5c6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,13 @@ | |
| # jira-triage-ops.lib.sh — Jira Cloud tracker operations for triage scripts. | ||
| # | ||
| # Bundled into pre-triage.sh and post-triage.sh via triage-ops.lib.sh. | ||
| # Labels, transitions, and cross-project issue creation use curl against | ||
| # the Jira Cloud REST API v3. Comment posting shells out to | ||
| # `fullsend issues post-comment --tracker jira`, which handles Jira's | ||
| # markdown-to-ADF conversion and marker-based find-and-update semantics | ||
| # that raw REST calls would otherwise have to reimplement. | ||
| # Labels, components, read-only status/transition pre-flight checks, and | ||
| # cross-project issue creation use curl against the Jira Cloud REST API v3. | ||
| # Comment posting shells out to `fullsend issues post-comment --tracker jira`, | ||
| # which handles Jira's markdown-to-ADF conversion and marker-based | ||
| # find-and-update semantics, and close transitions shell out to | ||
| # `fullsend issues transition --tracker jira` (Fullsend v0.56.1+) so triage | ||
| # and core fullsend share one transition and resolution policy. | ||
| # | ||
| # Jira Cloud only (v1): the issue host must match *.atlassian.net. Jira | ||
| # Server/Data Center is not supported. | ||
|
|
@@ -49,11 +51,12 @@ | |
| # `fullsend` shell-outs below. | ||
| # | ||
| # Optional env vars: | ||
| # JIRA_COMPLETED_TRANSITION — transition name for the "completed" action | ||
| # (no default; falls back to | ||
| # JIRA_SPLIT_TRANSITION when unset) | ||
| # JIRA_DUPLICATE_TRANSITION — transition name for the "duplicate" action | ||
| # JIRA_NOT_PLANNED_TRANSITION — transition name for the "not planned" action | ||
| # JIRA_SPLIT_TRANSITION — transition name for the "split" and | ||
| # "completed" actions (both close with | ||
| # GitHub reason "completed") | ||
| # JIRA_SPLIT_TRANSITION — transition name for the "split" action | ||
| # JIRA_CREATE_ISSUE_TYPE — issue type name for cross-project issue | ||
| # creation (default: "Task") | ||
|
|
||
|
|
@@ -378,6 +381,20 @@ _jira_post_comment() { | |
| --marker "${marker}" --result - | ||
| } | ||
|
|
||
| # Execute a Jira workflow transition through the fullsend CLI (v0.56.1+), | ||
| # which reads the Jira site and API gateway from tracker.jira in FULLSEND_DIR | ||
| # and shares the upstream transition and resolution policy. | ||
| _jira_transition() { | ||
| _jira_require_vars || return 1 | ||
| if [[ -z "${FULLSEND_DIR:-}" ]]; then | ||
| echo "ERROR: FULLSEND_DIR is not set; the fullsend CLI needs it for the tracker.jira settings" >&2 | ||
| return 1 | ||
| fi | ||
| jira_auth_fullsend fullsend "${JIRA_TOKEN:-}" "${JIRA_USER_EMAIL:-}" \ | ||
| issues transition --tracker jira --fullsend-dir "${FULLSEND_DIR}" \ | ||
| --project "${REPO}" --number "${JIRA_ISSUE_NUM}" "$@" | ||
| } | ||
|
|
||
| # --- Issues --- | ||
|
|
||
| tracker_close_issue() { | ||
|
|
@@ -386,37 +403,91 @@ tracker_close_issue() { | |
| case "${reason}" in | ||
| duplicate) transition_var="JIRA_DUPLICATE_TRANSITION" ;; | ||
| "not planned") transition_var="JIRA_NOT_PLANNED_TRANSITION" ;; | ||
| completed) transition_var="JIRA_SPLIT_TRANSITION" ;; | ||
| completed) transition_var="JIRA_COMPLETED_TRANSITION" ;; | ||
| split) transition_var="JIRA_SPLIT_TRANSITION" ;; | ||
|
qodo-code-review[bot] marked this conversation as resolved.
Resolved
qodo-code-review[bot] marked this conversation as resolved.
Resolved
|
||
| *) | ||
| echo "ERROR: unknown close reason '${reason}' — no Jira transition mapping" >&2 | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
| local transition_name="${!transition_var:-}" | ||
| if [[ -z "${transition_name}" && "${reason}" == "completed" && -n "${JIRA_SPLIT_TRANSITION:-}" ]]; then | ||
| transition_var="JIRA_SPLIT_TRANSITION" | ||
| transition_name="${JIRA_SPLIT_TRANSITION}" | ||
| echo "NOTICE: JIRA_COMPLETED_TRANSITION is not set; falling back to JIRA_SPLIT_TRANSITION ('$(_gha_sanitize "${transition_name}")')" | ||
| fi | ||
|
|
||
| if [[ -z "${transition_name}" ]]; then | ||
| echo "ERROR: ${transition_var} is not set — cannot close issue ${ISSUE_NUMBER} via Jira transition for reason '${reason}'" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| # Idempotency pre-flight: skip when the issue is already in the configured | ||
| # terminal status (matching the configured transition name directly). | ||
| local current_status_json current_category="" current_status_name="" | ||
| current_status_json=$(_jira_api GET "/issue/${ISSUE_NUMBER}?fields=status" 2>/dev/null) || true | ||
| if [[ -n "${current_status_json}" ]]; then | ||
| current_category=$(echo "${current_status_json}" | jq -r '.fields.status.statusCategory.key // empty' 2>/dev/null) || current_category="" | ||
| current_status_name=$(echo "${current_status_json}" | jq -r '.fields.status.name // empty' 2>/dev/null) || current_status_name="" | ||
| if [[ "${current_category}" == "done" && -n "${current_status_name}" && "${current_status_name,,}" == "${transition_name,,}" ]]; then | ||
| echo "Issue ${ISSUE_NUMBER} is already in status '$(_gha_sanitize "${current_status_name}")' (${current_category}); skipping transition for reason '${reason}'" | ||
| return 0 | ||
| fi | ||
| fi | ||
|
|
||
| local transitions | ||
| transitions=$(_jira_api GET "/issue/${ISSUE_NUMBER}/transitions" 2>/dev/null) || { | ||
| echo "ERROR: failed to list transitions for issue ${ISSUE_NUMBER}" >&2 | ||
| return 1 | ||
| } | ||
| local transition_id | ||
| transition_id=$(echo "${transitions}" | jq -r --arg name "${transition_name}" \ | ||
| '[.transitions[] | select(.name == $name)][0].id // empty') | ||
| if [[ -z "${transition_id}" ]]; then | ||
| echo "ERROR: transition '${transition_name}' (from ${transition_var}) is not available on issue ${ISSUE_NUMBER}" >&2 | ||
| local matching_count target_status_name="" | ||
| matching_count=$(echo "${transitions}" | jq -r --arg name "${transition_name}" \ | ||
| 'if (type == "object" and (.transitions | type) == "array") then [.transitions[] | select(.name == $name)] | length else error("expected transitions array") end' 2>/dev/null) || { | ||
| echo "ERROR: unexpected transitions response for issue ${ISSUE_NUMBER}" >&2 | ||
| return 1 | ||
| } | ||
| if [[ ! "${matching_count}" =~ ^[0-9]+$ ]]; then | ||
| echo "ERROR: unexpected transitions response for issue ${ISSUE_NUMBER}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| if ! _jira_api POST "/issue/${ISSUE_NUMBER}/transitions" \ | ||
| --data "$(jq -cn --arg id "${transition_id}" '{transition:{id:$id}}')" > /dev/null; then | ||
| echo "ERROR: failed to transition issue ${ISSUE_NUMBER} via '${transition_name}'" >&2 | ||
| return 1 | ||
| if [[ "${matching_count}" -eq 1 && "${current_category:-}" == "done" && -n "${current_status_name:-}" ]]; then | ||
| target_status_name=$(echo "${transitions}" | jq -r --arg name "${transition_name}" \ | ||
| '[.transitions[] | select(.name == $name)][0].to.name // empty' 2>/dev/null) || target_status_name="" | ||
| if [[ -n "${target_status_name}" && "${target_status_name,,}" == "${current_status_name,,}" ]]; then | ||
| echo "Issue ${ISSUE_NUMBER} is already in target status '$(_gha_sanitize "${current_status_name}")' (done); skipping transition for reason '${reason}'" | ||
| return 0 | ||
| fi | ||
| fi | ||
|
|
||
| if [[ "${matching_count}" -gt 0 ]]; then | ||
| if ! _jira_transition --transition "${transition_name}"; then | ||
| echo "ERROR: failed to transition issue ${ISSUE_NUMBER} via '$(_gha_sanitize "${transition_name}")'" >&2 | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| fi | ||
|
|
||
| # Fall back to `--state closed` only when the transition name came from the | ||
| # un-overridden harness default (JIRA_SPLIT_TRANSITION="Obsolete" in | ||
| # harness/triage.yaml, including when `completed` fell back to it because | ||
| # JIRA_COMPLETED_TRANSITION was unset). Any operator-configured transition | ||
| # name that Jira does not offer fails loudly below. | ||
| local default_split_transition="Obsolete" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MEDIUM: The
Impact:
Suggestion: Pass the fallback signal from the harness, for example a runner env flag next to Verified: read code at head (lib.sh:472-487, harness/triage.yaml:191); grep shows harness-jira-test.sh has no Obsolete assertion at 55da9d7; raised by: Claude, DeepSeek
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d7c5c6e: Added |
||
| if [[ ( "${reason}" == "completed" || "${reason}" == "split" ) \ | ||
| && "${transition_var}" == "JIRA_SPLIT_TRANSITION" \ | ||
| && "${transition_name}" == "${default_split_transition}" ]]; then | ||
| echo "::warning::Transition '$(_gha_sanitize "${transition_name}")' (from ${transition_var}) is not available on issue ${ISSUE_NUMBER}; falling back to 'fullsend issues transition --state closed'" | ||
| if ! _jira_transition --state closed; then | ||
| echo "ERROR: failed to close issue ${ISSUE_NUMBER} via 'fullsend issues transition --state closed'" >&2 | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "ERROR: transition '$(_gha_sanitize "${transition_name}")' (from ${transition_var}) is not available on issue ${ISSUE_NUMBER}" >&2 | ||
| return 1 | ||
| } | ||
|
|
||
| _text_to_adf() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MEDIUM: Header comment and PR body still say
JIRA_COMPLETED_TRANSITIONdefaults to "Closed"; the shipped harness has no defaultCommit a274b35 removed
JIRA_COMPLETED_TRANSITION: "Closed"fromharness/triage.yaml, andharness/triage.yamlis no longer in the diff. This header (lines 46-48) still says(default: "Closed"; falls back to JIRA_SPLIT_TRANSITION when unset), and the rebuilt bundles carry the same text (scripts/post-triage.sh,scripts/pre-code-jira.sh,scripts/pre-triage.sh). The PR body also still says it "Adds JIRA_COMPLETED_TRANSITION (defaulting to "Closed") in harness/triage.yaml" and liststriage.yamlunder Changes.With the shipped harness,
completedfalls back toJIRA_SPLIT_TRANSITION="Obsolete". Socompletedis decoupled fromsplitonly for operators who set the variable, and the reported failure is fixed by the name fallback, not by decoupling.LOCAL.mdanddocs/triage.mdare correct; this header, which operators read first, is wrong. (The earlier header thread asked to add a "Closed" default; that default was later removed, so this is a new mismatch.)Suggestion: Change the header to "no default; falls back to JIRA_SPLIT_TRANSITION when unset" and run
make script-buildso all four copies match. Update the PR title and body to say that, by default,completedstill routes throughJIRA_SPLIT_TRANSITION(with the Done-name fallback) and thatharness/triage.yamlis unchanged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 20bebaa (20bebaa): updated the
JIRA_COMPLETED_TRANSITIONheader comment inscripts/lib/jira-triage-ops.lib.sh(and rebuilt the bundles) to state(no default; falls back to JIRA_SPLIT_TRANSITION when unset), and updated the PR body to remove the stale"Closed"default /harness/triage.yamlreferences and note that validation used mocked workflow responses (linkingfullsend-ai/fullsend#6704).