Skip to content

Commit 5d6724d

Browse files
Saas 1465 (#335)
* added approve build * approve & deny * fixed some lint errors * moved files from ROOT to WORKFLOW * changed workflow to workflows * updated version
1 parent 3f88c46 commit 5d6724d

File tree

9 files changed

+238
-2
lines changed

9 files changed

+238
-2
lines changed

lib/interface/cli/codefresh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ if (process.argv.includes('--get-yargs-completions')) {
2222
process.exit(1);
2323
});
2424
}
25-

lib/interface/cli/commands/root/root.sdk.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ let createCmd = require('./create.cmd');
22
let replaceCmd = require('./replace.cmd');
33
let deleteCmd = require('./delete.cmd');
44
let versionCmd = require('./version.cmd');
5+
let approveCmd = require('../workflow/approve.cmd');
6+
let denyCmd = require('../workflow/approve.cmd');
57

68
createCmd.requiresAuthentication = false;
79
replaceCmd.requiresAuthentication = false;
810
deleteCmd.requiresAuthentication = false;
911
versionCmd.requiresAuthentication = false;
12+
approveCmd.requiresAuthentication = false;
13+
denyCmd.requiresAuthentication = false;
1014

1115
createCmd = createCmd.toCommand();
1216
replaceCmd = replaceCmd.toCommand();
1317
deleteCmd = deleteCmd.toCommand();
1418
versionCmd = versionCmd.toCommand();
19+
approveCmd = approveCmd.toCommand();
20+
denyCmd = denyCmd.toCommand();
1521

1622

1723
jest.mock('../../helpers/validation', () => { // eslint-disable-line
@@ -152,4 +158,24 @@ describe('root commands', () => {
152158
});
153159
});
154160
});
161+
162+
describe('Approve pending-approval workflow', () => {
163+
it('should handle approve from spec', async () => {
164+
const argv = {
165+
buildId: 'buildId'
166+
};
167+
await approveCmd.handler(argv);
168+
await verifyResponsesReturned([DEFAULT_RESPONSE, DEFAULT_RESPONSE]); // eslint-disable-line
169+
});
170+
});
171+
172+
describe('Deny pending-approval workflow', () => {
173+
it('should handle deny from spec', async () => {
174+
const argv = {
175+
buildId: 'buildId'
176+
};
177+
await denyCmd.handler(argv);
178+
await verifyResponsesReturned([DEFAULT_RESPONSE, DEFAULT_RESPONSE]); // eslint-disable-line
179+
});
180+
});
155181
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const Command = require('../../Command');
2+
const yargs = require('yargs');
3+
const _ = require('lodash');
4+
const { sdk } = require('../../../../logic');
5+
6+
const approveBuildCmd = new Command({
7+
root: true,
8+
command: 'approve <buildId>',
9+
description: 'Approve a pending-approval workflow',
10+
usage: 'approve <$BUILD_ID>',
11+
webDocs: {
12+
category: 'Builds',
13+
title: 'Approve',
14+
weight: 100,
15+
},
16+
builder: (yargs) => {
17+
return yargs
18+
.positional('buildId', {
19+
describe: 'Build\'s id',
20+
required: true,
21+
});
22+
},
23+
handler: async (argv) => {
24+
const { buildId } = argv;
25+
await sdk.workflows.get({ id: buildId });
26+
await sdk.workflows.approve({ buildId });
27+
console.log(`Workflow ${buildId} has been approved.`);
28+
},
29+
});
30+
31+
module.exports = approveBuildCmd;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
let approveCmd = require('./approve.cmd');
2+
3+
approveCmd.requiresAuthentication = false;
4+
5+
approveCmd = approveCmd.toCommand();
6+
7+
8+
jest.mock('../../helpers/validation', () => { // eslint-disable-line
9+
return {
10+
validatePipelineSpec: () => ({ valid: true }),
11+
};
12+
});
13+
14+
const request = require('requestretry');
15+
16+
const DEFAULT_RESPONSE = request.__defaultResponse();
17+
18+
describe('Approve pending-approval workflow', () => {
19+
beforeEach(async () => {
20+
request.__reset();
21+
request.mockClear();
22+
await configureSdk(); // eslint-disable-line
23+
});
24+
25+
describe('Positive', () => {
26+
it('should approve a pending-approval workflow', async () => {
27+
const argv = {
28+
buildId: 'buildId',
29+
};
30+
const response = { statusCode: 200, body: [DEFAULT_RESPONSE.body] };
31+
request.__setResponse(response);
32+
await approveCmd.handler(argv);
33+
await verifyResponsesReturned([response, response]); // eslint-disable-line
34+
});
35+
});
36+
37+
describe('Negative', () => {
38+
it('should approve a pending-approval workflow', async () => {
39+
const argv = {
40+
buildId: 'buildId',
41+
};
42+
const response = { statusCode: 404, body: [DEFAULT_RESPONSE.body] };
43+
request.__setResponse(response);
44+
await expect(approveCmd.handler(argv)).rejects.toThrow();
45+
});
46+
});
47+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const Command = require('../../Command');
2+
const yargs = require('yargs');
3+
const _ = require('lodash');
4+
const { sdk } = require('../../../../logic');
5+
6+
const denyBuildCmd = new Command({
7+
root: true,
8+
command: 'deny <buildId>',
9+
description: 'Deny a pending-approval workflow',
10+
usage: 'deny <$BUILD_ID>',
11+
webDocs: {
12+
category: 'Builds',
13+
title: 'Deny',
14+
weight: 100,
15+
},
16+
builder: (yargs) => {
17+
return yargs
18+
.positional('buildId', {
19+
describe: 'Build\'s id',
20+
required: true,
21+
});
22+
},
23+
handler: async (argv) => {
24+
const { buildId } = argv;
25+
await sdk.workflows.get({ id: buildId });
26+
await sdk.workflows.deny({ buildId });
27+
console.log(`Workflow ${buildId} has been denied.`);
28+
},
29+
});
30+
31+
module.exports = denyBuildCmd;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
let denyCmd = require('./deny.cmd');
2+
3+
denyCmd.requiresAuthentication = false;
4+
5+
denyCmd = denyCmd.toCommand();
6+
7+
8+
jest.mock('../../helpers/validation', () => { // eslint-disable-line
9+
return {
10+
validatePipelineSpec: () => ({ valid: true }),
11+
};
12+
});
13+
14+
const request = require('requestretry');
15+
16+
const DEFAULT_RESPONSE = request.__defaultResponse();
17+
18+
describe('Deny pending-approval workflow', () => {
19+
beforeEach(async () => {
20+
request.__reset();
21+
request.mockClear();
22+
await configureSdk(); // eslint-disable-line
23+
});
24+
25+
describe('Positive', () => {
26+
it('should deny a pending-approval workflow', async () => {
27+
const argv = {
28+
buildId: 'buildId',
29+
};
30+
const response = { statusCode: 200, body: [DEFAULT_RESPONSE.body] };
31+
request.__setResponse(response);
32+
await denyCmd.handler(argv);
33+
await verifyResponsesReturned([response, response]); // eslint-disable-line
34+
});
35+
});
36+
37+
describe('Negative', () => {
38+
it('should deny a pending-approval workflow', async () => {
39+
const argv = {
40+
buildId: 'buildId',
41+
};
42+
const response = { statusCode: 404, body: [DEFAULT_RESPONSE.body] };
43+
request.__setResponse(response);
44+
await expect(denyCmd.handler(argv)).rejects.toThrow();
45+
});
46+
});
47+
});

lib/interface/cli/commands/workflow/workflow.sdk.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('workflow commands', () => {
3939
const argv = { id: ['some id'] };
4040
const response = { statusCode: 200, body: [DEFAULT_RESPONSE.body] };
4141
request.__setResponse(response);
42+
4243
await getCmd.handler(argv);
4344
await verifyResponsesReturned([response]); // eslint-disable-line
4445
});

openapi.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6588,6 +6588,60 @@
65886588
"summary": "Get server version",
65896589
"x-sdk-interface": "version.getServerVersion"
65906590
}
6591+
},
6592+
"/workflow/{buildId}/pending-approval/approve": {
6593+
"get": {
6594+
"responses": {
6595+
"200": {
6596+
"description": "ok"
6597+
}
6598+
},
6599+
"tags": [
6600+
"workflow",
6601+
"build",
6602+
"approve"
6603+
],
6604+
"parameters": [
6605+
{
6606+
"in": "path",
6607+
"name": "buildId",
6608+
"schema": {
6609+
"type": "string"
6610+
},
6611+
"required": true
6612+
}
6613+
],
6614+
"operationId": "workflow-approve",
6615+
"summary": "Approve a pending-approval workflow",
6616+
"x-sdk-interface": "workflows.approve"
6617+
}
6618+
},
6619+
"/workflow/{buildId}/pending-approval/deny": {
6620+
"get": {
6621+
"responses": {
6622+
"200": {
6623+
"description": "ok"
6624+
}
6625+
},
6626+
"tags": [
6627+
"workflow",
6628+
"build",
6629+
"deny"
6630+
],
6631+
"parameters": [
6632+
{
6633+
"in": "path",
6634+
"name": "buildId",
6635+
"schema": {
6636+
"type": "string"
6637+
},
6638+
"required": true
6639+
}
6640+
],
6641+
"operationId": "workflow-deny",
6642+
"summary": "Deny a pending-approval workflow",
6643+
"x-sdk-interface": "workflows.deny"
6644+
}
65916645
}
65926646
},
65936647
"components": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.19.7",
3+
"version": "0.20.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)