Skip to content

Commit

Permalink
feat(1961): Use screwdriver-request package (#32)
Browse files Browse the repository at this point in the history
* feat(1961): Use screwdriver-request package

* fix: remove caller
  • Loading branch information
tkyi authored Aug 23, 2021
1 parent 7fbf9ac commit 11f2e49
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 82 deletions.
67 changes: 24 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const request = require('request-promise-native');
const request = require('screwdriver-request');
const fs = require('fs');
const URL = require('url');
const Yaml = require('js-yaml');
Expand Down Expand Up @@ -28,11 +28,10 @@ function validateTemplate(config) {
return request({
method: 'POST',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
yaml: JSON.stringify(config)
}
}).then(response => {
Expand Down Expand Up @@ -67,15 +66,12 @@ function publishTemplate(config) {
return request({
method: 'POST',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
yaml: JSON.stringify(config)
},
resolveWithFullResponse: true,
simple: false
}
}).then(response => {
const { body } = response;

Expand Down Expand Up @@ -111,12 +107,9 @@ function removeTemplate(name) {
return request({
method: 'DELETE',
url,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
}).then(response => {
const { body } = response;

Expand All @@ -142,12 +135,9 @@ function getLatestVersion(name) {
return request({
method: 'GET',
url,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
}).then(response => {
const { body, statusCode } = response;

Expand Down Expand Up @@ -175,12 +165,9 @@ function getVersionFromTag({ name, tag }) {
return request({
method: 'GET',
url,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
}).then(response => {
const { body, statusCode } = response;

Expand Down Expand Up @@ -214,15 +201,12 @@ function tagTemplate({ name, tag, version }) {
return request({
method: 'PUT',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
version
},
resolveWithFullResponse: true,
simple: false
}
}).then(response => {
const { body, statusCode } = response;

Expand Down Expand Up @@ -255,12 +239,9 @@ function removeTag({ name, tag }) {
return request({
method: 'DELETE',
url,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
}).then(response => {
const { body, statusCode } = response;

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],
"devDependencies": {
"chai": "^4.3.4",
"eslint": "^7.5.0",
"eslint": "^7.31.0",
"eslint-config-screwdriver": "^5.0.1",
"mocha": "^8.2.1",
"mocha-multi-reporters": "^1.5.1",
Expand All @@ -55,8 +55,7 @@
"dependencies": {
"js-yaml": "^3.14.1",
"nomnom": "^1.8.1",
"request": "^2.88.2",
"request-promise-native": "^1.0.9"
"screwdriver-request": "^1.0.1"
},
"release": {
"debug": false,
Expand Down
57 changes: 21 additions & 36 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('index', () => {

mockery.registerMock('fs', fsMock);
mockery.registerMock('js-yaml', YamlMock);
mockery.registerMock('request-promise-native', requestMock);
mockery.registerMock('screwdriver-request', requestMock);

// eslint-disable-next-line global-require
index = require('../index');
Expand Down Expand Up @@ -317,15 +317,12 @@ describe('index', () => {
assert.calledWith(requestMock, {
method: 'PUT',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
version: '1.0.0'
},
resolveWithFullResponse: true,
simple: false
}
});
});
});
Expand All @@ -347,15 +344,12 @@ describe('index', () => {
assert.calledWith(requestMock, {
method: 'PUT',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
version: '1.0.0'
},
resolveWithFullResponse: true,
simple: false
}
});
});
});
Expand Down Expand Up @@ -407,15 +401,12 @@ describe('index', () => {
assert.calledWith(requestMock, {
method: 'PUT',
url,
auth: {
bearer: process.env.SD_TOKEN
context: {
token: process.env.SD_TOKEN
},
json: true,
body: {
json: {
version: '1.0.0'
},
resolveWithFullResponse: true,
simple: false
}
});
});
});
Expand Down Expand Up @@ -447,7 +438,7 @@ describe('index', () => {
});
});

describe('Get version from a tag', () => {
describe('get version from a tag', () => {
const config = {
name: 'template/test',
tag: 'stable'
Expand Down Expand Up @@ -481,18 +472,15 @@ describe('index', () => {
assert.calledWith(requestMock, {
method: 'GET',
url: versionUrl,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
});
});
});
});

describe('Delete a tag', () => {
describe('delete a tag', () => {
const config = {
name: 'template/test',
tag: 'stable'
Expand Down Expand Up @@ -548,12 +536,9 @@ describe('index', () => {
assert.calledWith(requestMock, {
method: 'DELETE',
url,
auth: {
bearer: process.env.SD_TOKEN
},
json: true,
resolveWithFullResponse: true,
simple: false
context: {
token: process.env.SD_TOKEN
}
});
});
});
Expand Down

0 comments on commit 11f2e49

Please sign in to comment.