From 11f2e49fef93339d473337b53443cb5eb9770614 Mon Sep 17 00:00:00 2001 From: Tiffany K Date: Mon, 23 Aug 2021 10:16:19 -0700 Subject: [PATCH] feat(1961): Use screwdriver-request package (#32) * feat(1961): Use screwdriver-request package * fix: remove caller --- index.js | 67 +++++++++++++++++----------------------------- package.json | 5 ++-- test/index.test.js | 57 +++++++++++++++------------------------ 3 files changed, 47 insertions(+), 82 deletions(-) diff --git a/index.js b/index.js index e77f9e9..fc7b78a 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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 => { @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/package.json b/package.json index 6efde89..8a869b0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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, diff --git a/test/index.test.js b/test/index.test.js index 18f77ed..4f2c069 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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'); @@ -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 + } }); }); }); @@ -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 + } }); }); }); @@ -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 + } }); }); }); @@ -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' @@ -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' @@ -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 + } }); }); });