Skip to content

Commit ad75e59

Browse files
feat(MORG-46): show only valid Jira transitions when changing ticket status (#34)
getStatuses() now accepts an optional ticketId. When provided, it fetches ticket-specific transitions via /issue/{key}/transitions instead of the global status list, so the "Change status" menu only shows transitions valid for the ticket's current workflow state.
1 parent 3b8e1f5 commit ad75e59

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/commands/tickets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async function runTicketActions(
221221
}
222222

223223
if (action === 'status') {
224-
const statuses = await provider.getStatuses?.();
224+
const statuses = await provider.getStatuses?.(ticket.key);
225225
let newStatus: string;
226226
if (statuses && statuses.length > 0) {
227227
newStatus = await select({

src/integrations/providers/tickets/implementations/jira-tickets-provider.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,19 @@ export class JiraClient implements TicketsProvider {
253253
});
254254
}
255255

256-
async getStatuses(): Promise<string[]> {
256+
async getStatuses(ticketId?: string): Promise<string[]> {
257+
// When a ticket ID is provided, return only the valid transitions for that specific ticket
258+
if (ticketId) {
259+
const res = await fetch(this.url(`/issue/${ticketId}/transitions`), {
260+
headers: this.headers,
261+
signal: AbortSignal.timeout(10_000),
262+
});
263+
if (res.ok) {
264+
const data = (await res.json()) as { transitions: { name: string }[] };
265+
return data.transitions.map((t) => t.name);
266+
}
267+
}
268+
// Fallback: global project statuses
257269
if (this.projectConfig?.projectKey) {
258270
const res = await fetch(this.url(`/project/${this.projectConfig.projectKey}/statuses`), {
259271
headers: this.headers,

src/integrations/providers/tickets/tickets-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export interface TicketsProvider {
2323
getTicket(ticketId: string): Promise<Ticket>;
2424
listTickets(opts?: { status?: string }): Promise<Ticket[]>;
2525
transitionTicket(ticketId: string, transitionName: string): Promise<void>;
26-
getStatuses?(): Promise<string[]>;
26+
getStatuses?(ticketId?: string): Promise<string[]>;
2727
}

0 commit comments

Comments
 (0)