Skip to content

Commit 18ccb05

Browse files
committed
fix: set workflow status
1 parent c58d023 commit 18ccb05

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

src/api.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pretend, Get, Post } from 'pretend';
1+
import { Pretend, Get, Post, Interceptor, IPretendRequestInterceptor, IPretendDecoder } from 'pretend';
22

33
export interface Jira {
44
serverInfo(): Promise<ServerInfo>;
@@ -25,6 +25,9 @@ export interface Issue {
2525
fields: {
2626
summary: string;
2727
description?: string;
28+
status: {
29+
name: string;
30+
}
2831
};
2932
}
3033

@@ -48,16 +51,45 @@ export interface DoTransitionBody {
4851

4952
export function createClient(endpoint: string, username: string, password: string): Jira {
5053
return Pretend.builder()
54+
.interceptor(impl.logger())
5155
.basicAuthentication(username, password)
56+
.requestInterceptor(impl.contentType())
57+
.decode(impl.decoder())
5258
.target(impl.JiraBlueprint, endpoint);
5359
}
5460

5561
namespace impl {
5662

63+
export function logger(): Interceptor {
64+
return async(chain, request) => {
65+
// console.log('request: ', request);
66+
const response = await chain(request);
67+
// console.log('response', response);
68+
return response;
69+
};
70+
}
71+
72+
export function contentType(): IPretendRequestInterceptor {
73+
return request => {
74+
(request.options.headers as Headers).set('Content-Type', 'application/json');
75+
return request;
76+
};
77+
}
78+
79+
export function decoder(): IPretendDecoder {
80+
return response => {
81+
if (response.status === 204) {
82+
// no-content
83+
return Promise.resolve();
84+
}
85+
return response.json();
86+
};
87+
}
88+
5789
export class JiraBlueprint implements Jira {
5890
@Get('/rest/api/2/serverInfo')
5991
public serverInfo(): any {/* */}
60-
@Get('/rest/api/2/search', true)
92+
@Post('/rest/api/2/search')
6193
public search(): any {/* */}
6294
@Get('/rest/api/2/issue/:issue/transitions')
6395
public getTransitions(): any {/* */}

src/commands/activate-issue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export class ActivateIssueCommand implements Command {
1414
const issue = await this.selectIssue(preselected);
1515
if (issue !== undefined && state.workspaceState) {
1616
const activeIssue: ActiveIssue = {
17-
key: issue ? issue.key : undefined
17+
key: issue ? issue.key : undefined,
18+
status: issue ? issue.fields.status.name : undefined
1819
};
1920
state.workspaceState.update('vscode-jira:active-issue', activeIssue);
2021
state.update();

src/commands/transition-issue.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export class TransitionIssueCommand implements Command {
2222
if (selected === null) {
2323
vscode.commands.executeCommand('vscode-jira.activateIssues', null);
2424
} else if (selected !== undefined) {
25-
vscode.window.showInformationMessage(`Should exec transition ${selected.to.name}`);
25+
await state.jira.doTransition(activeIssue.key, {
26+
transition: {
27+
id: selected.id
28+
}
29+
});
30+
await this.deactivateWhenDone(activeIssue);
2631
}
2732
}
2833
}
@@ -64,4 +69,14 @@ export class TransitionIssueCommand implements Command {
6469
}
6570
}
6671

72+
private async deactivateWhenDone(activeIssue: ActiveIssue): Promise<void> {
73+
if (!state.jira || !activeIssue.key) {
74+
return;
75+
}
76+
const result = await state.jira.search({jql: `issue = "${activeIssue.key}" AND resolution = Resolved`});
77+
if (result.issues.length > 0) {
78+
vscode.commands.executeCommand('vscode-jira.activateIssues', null);
79+
}
80+
}
81+
6782
}

src/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface State {
1010

1111
export interface ActiveIssue {
1212
key?: string;
13+
status?: string;
1314
}
1415

1516
const state: State = {

src/status-bar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class StatusBarManager {
1818
public updateStatus(): void {
1919
const activeIssue = this.getActiveIssue();
2020
if (activeIssue && activeIssue.key) {
21-
this.item.text = `$(issue-opened) ${activeIssue.key}`;
21+
this.item.text = `$(issue-opened) ${activeIssue.key} ${activeIssue.status}`;
2222
this.item.command = 'vscode-jira.transitionIssues';
2323
} else {
2424
this.item.text = '$(issue-opened)';

0 commit comments

Comments
 (0)