(cloudId: string)
| 87 | |
| 88 | transformResponse: async (response: Response, params?: JiraTransitionIssueParams) => { |
| 89 | const performTransition = async (cloudId: string) => { |
| 90 | // First, fetch available transitions to get the name and target status |
| 91 | const transitionsUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/issue/${params!.issueKey?.trim() ?? ''}/transitions` |
| 92 | const transitionsResp = await fetch(transitionsUrl, { |
| 93 | method: 'GET', |
| 94 | headers: { |
| 95 | Accept: 'application/json', |
| 96 | Authorization: `Bearer ${params!.accessToken}`, |
| 97 | }, |
| 98 | }) |
| 99 | |
| 100 | let transitionName: string | null = null |
| 101 | let toStatus: { id: string; name: string } | null = null |
| 102 | |
| 103 | if (transitionsResp.ok) { |
| 104 | const transitionsData = await transitionsResp.json() |
| 105 | const transition = (transitionsData?.transitions ?? []).find( |
| 106 | (t: any) => String(t.id) === String(params!.transitionId) |
| 107 | ) |
| 108 | if (transition) { |
| 109 | transitionName = transition.name ?? null |
| 110 | toStatus = transition.to |
| 111 | ? { id: transition.to.id ?? '', name: transition.to.name ?? '' } |
| 112 | : null |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Perform the transition |
| 117 | const transitionResponse = await fetch(transitionsUrl, { |
| 118 | method: 'POST', |
| 119 | headers: { |
| 120 | Accept: 'application/json', |
| 121 | 'Content-Type': 'application/json', |
| 122 | Authorization: `Bearer ${params!.accessToken}`, |
| 123 | }, |
| 124 | body: JSON.stringify(buildTransitionBody(params!)), |
| 125 | }) |
| 126 | |
| 127 | if (!transitionResponse.ok) { |
| 128 | let message = `Failed to transition Jira issue (${transitionResponse.status})` |
| 129 | try { |
| 130 | const err = await transitionResponse.json() |
| 131 | message = err?.errorMessages?.join(', ') || err?.message || message |
| 132 | } catch (_e) {} |
| 133 | throw new Error(message) |
| 134 | } |
| 135 | |
| 136 | return { transitionName, toStatus } |
| 137 | } |
| 138 | |
| 139 | let transitionName: string | null = null |
| 140 | let toStatus: { id: string; name: string } | null = null |
no test coverage detected