Skip to content

Commit 5d17633

Browse files
fix: #24 add User-Agent for GitHub api
1 parent 13fd0c0 commit 5d17633

File tree

9 files changed

+1401
-1227
lines changed

9 files changed

+1401
-1227
lines changed

.github/workflows/node-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [16.x, 18.x]
16+
node-version: [18.x, 19.x]
1717

1818
steps:
1919
- uses: actions/checkout@v2

package-lock.json

Lines changed: 1353 additions & 1189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-devops-bicep-task",
3-
"version": "0.3.8",
3+
"version": "0.4.1",
44
"description": "Tasks for installing Bicep CLI and running Bicep CLI build commands",
55
"main": "index.js",
66
"scripts": {
@@ -38,25 +38,25 @@
3838
"homepage": "https://github.com/piraces/azure-devops-bicep-task#readme",
3939
"dependencies": {
4040
"axios": "^0.27.2",
41-
"azure-pipelines-tool-lib": "^2.0.0-preview",
42-
"glob": "^7.1.7"
41+
"azure-pipelines-tool-lib": "^2.0.0-preview"
4342
},
4443
"devDependencies": {
45-
"@types/glob": "^8.0.0",
46-
"@types/jest": "^29.0.2",
47-
"@types/node": "^18.7.17",
44+
"@types/glob": "^8.0.1",
45+
"@types/jest": "^29.4.0",
46+
"@types/node": "^18.13.0",
4847
"@types/q": "^1.5.5",
49-
"@typescript-eslint/eslint-plugin": "^5.37.0",
50-
"@typescript-eslint/parser": "^5.37.0",
51-
"azure-pipelines-task-lib": "^4.0.0-preview",
52-
"eslint": "^8.23.1",
53-
"eslint-config-prettier": "^8.5.0",
48+
"@typescript-eslint/eslint-plugin": "^5.51.0",
49+
"@typescript-eslint/parser": "^5.51.0",
50+
"azure-pipelines-task-lib": "^4.2.0",
51+
"eslint": "^8.34.0",
52+
"eslint-config-prettier": "^8.6.0",
5453
"eslint-plugin-prettier": "^4.2.1",
55-
"husky": "^8.0.1",
56-
"jest": "^29.0.3",
57-
"lint-staged": "^13.0.3",
58-
"prettier": "^2.7.1",
59-
"ts-jest": "^29.0.0",
60-
"typescript": "^4.8.3"
54+
"glob": "^8.1.0",
55+
"husky": "^8.0.3",
56+
"jest": "^29.4.2",
57+
"lint-staged": "^13.1.1",
58+
"prettier": "^2.8.4",
59+
"ts-jest": "^29.0.5",
60+
"typescript": "^4.9.5"
6161
}
6262
}

src/decompile/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"category": "Azure Pipelines",
1616
"version": {
1717
"Major": 0,
18-
"Minor": 3,
19-
"Patch": 8
18+
"Minor": 4,
19+
"Patch": 1
2020
},
2121
"instanceNameFormat": "Run Bicep CLI decompile command",
2222
"inputs": [

src/install/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as fs from 'fs';
33
import { platform, arch } from 'os';
44
import * as taskLib from 'azure-pipelines-task-lib/task';
55
import * as toolLib from 'azure-pipelines-tool-lib/tool';
6-
7-
const axios = require('axios');
6+
import { ClientRequest } from 'http';
7+
import axios from 'axios';
88

99
export function getDownloadUrl(version: string): string {
1010
const agentPlatform = platform();
@@ -35,12 +35,24 @@ export function getDownloadUrl(version: string): string {
3535

3636
export async function getLatestVersionTag(): Promise<string> {
3737
return await axios
38-
.get('https://api.github.com/repos/Azure/Bicep/releases/latest')
38+
.get('https://api.github.com/repos/Azure/Bicep/releases/latest', {
39+
headers: {
40+
'User-Agent': 'piraces'
41+
}
42+
})
3943
.then(function (response: { data: { tag_name: string } }) {
4044
return response.data.tag_name.replace('v', '');
4145
})
42-
.catch(function (error: { message: string }) {
43-
throw new Error(`[FATAL] Error while retrieving latest version tag: '${error.message}'`);
46+
.catch(function (error: { message: string, response?: { data: string, status: string, headers: string}, request: ClientRequest, config: string }) {
47+
if (error.response) {
48+
// The request was made and the server responded with a status code
49+
// that falls out of the range of 2xx
50+
throw new Error(`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nResponse: \n-Data: '${error.response.data}' \n-Status: '${error.response.status}' \n-Headers: '${error.response.headers}'`);
51+
} else if (error.request) {
52+
throw new Error(`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nRequest: '${error.request}'\nConfig: '${error.config}'`);
53+
} else {
54+
throw new Error(`[FATAL] Error while retrieving latest version tag: '${error.message}'.\nConfig: '${error.config}'`);
55+
}
4456
});
4557
}
4658

src/install/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"category": "Azure Pipelines",
1616
"version": {
1717
"Major": 0,
18-
"Minor": 3,
19-
"Patch": 8
18+
"Minor": 4,
19+
"Patch": 1
2020
},
2121
"instanceNameFormat": "Install Bicep CLI",
2222
"inputs": [

src/run/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"category": "Azure Pipelines",
1616
"version": {
1717
"Major": 0,
18-
"Minor": 3,
19-
"Patch": 8
18+
"Minor": 4,
19+
"Patch": 1
2020
},
2121
"instanceNameFormat": "Run Bicep CLI build command",
2222
"inputs": [

test/install/index.spec.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as os from 'os';
22
import { getDownloadUrl, getLatestVersionTag } from '../../src/install/index';
3-
4-
const axios = require('axios');
3+
import axios from 'axios';
54

65
jest.mock('os');
76
jest.mock('axios');
@@ -17,22 +16,21 @@ const InvalidPlatform = 'android';
1716

1817
const archMock = jest.spyOn(os, 'arch');
1918
const platformMock = jest.spyOn(os, 'platform');
19+
const axiosMock = jest.spyOn(axios, 'get');
2020

2121
function prepareMocks(architecture: string, platform: any, version = '0.2.328', axiosFail = false) {
2222
archMock.mockImplementation(() => architecture);
2323
platformMock.mockImplementation(() => platform);
2424

2525
if (axiosFail) {
26-
axios.get.mockRejectedValue({ message: 'Just Testing' });
26+
axiosMock.mockRejectedValue({ message: 'Just Testing', config: 'Test config' });
2727
} else {
28-
axios.get.mockResolvedValue({ data: { tag_name: version } });
28+
axiosMock.mockResolvedValue({ data: { tag_name: version } });
2929
}
3030
}
3131

3232
function restoreMocks() {
33-
archMock.mockRestore();
34-
platformMock.mockRestore();
35-
axios.mockRestore();
33+
jest.restoreAllMocks();
3634
}
3735

3836
describe('getDownloadUrl returns a valid URL', () => {
@@ -79,7 +77,7 @@ describe('getLatestVersionTag returns a valid tag', () => {
7977
try {
8078
await getLatestVersionTag();
8179
} catch (err) {
82-
expect(err).toEqual(new Error(`[FATAL] Error while retrieving latest version tag: 'Just Testing'`));
80+
expect(err).toEqual(new Error(`[FATAL] Error while retrieving latest version tag: 'Just Testing'.\nConfig: 'Test config'`));
8381
}
8482
});
8583
});

vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifestVersion": 1,
33
"id": "bicep-tasks",
4-
"version": "0.3.8",
4+
"version": "0.4.1",
55
"name": "Bicep Tasks",
66
"publisher": "piraces",
77
"description": "Provides Azure DevOps tasks to install and run Microsoft Bicep CLI commands (cross-platform)",

0 commit comments

Comments
 (0)