From ae54c22c9c97238d048db54d583a37bb76fde2a4 Mon Sep 17 00:00:00 2001 From: Laura Warr Date: Tue, 28 Mar 2023 15:25:57 -0700 Subject: [PATCH] [chore] Add dvc-referrer headers --- __tests__/action.test.ts | 3 ++- dist/index.js | 8 +++++--- src/action.ts | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/__tests__/action.test.ts b/__tests__/action.test.ts index 705f65f..572d20e 100644 --- a/__tests__/action.test.ts +++ b/__tests__/action.test.ts @@ -127,7 +127,8 @@ describe('postCodeUsages', () => { }), expect.objectContaining({ headers: { - Authorization: 'generated-token' + Authorization: 'generated-token', + 'dvc-referrer': 'github.code_usages' } }) ) diff --git a/dist/index.js b/dist/index.js index 328d624..4fbc87a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -46,6 +46,7 @@ const exec_1 = __nccwpck_require__(1514); const axios_1 = __importDefault(__nccwpck_require__(6545)); const API_URL = 'https://api.devcycle.com/'; const AUTH_URL = 'https://auth.devcycle.com/'; +const DVC_IDENTIFIER = 'github.code_usages'; function run() { return __awaiter(this, void 0, void 0, function* () { const requiredInputs = ['github-token', 'project-key', 'client-id', 'client-secret']; @@ -62,8 +63,8 @@ function run() { return; } try { - yield (0, exec_1.exec)('npm', ['install', '-g', '@devcycle/cli@4.2.8']); - const output = yield (0, exec_1.getExecOutput)('dvc', ['usages', '--format', 'json']); + yield (0, exec_1.exec)('npm', ['install', '-g', '@devcycle/cli@4.2.10']); + const output = yield (0, exec_1.getExecOutput)('dvc', ['usages', '--format', 'json', '--caller', DVC_IDENTIFIER]); const variables = JSON.parse(output.stdout); yield action.postCodeUsages(variables); } @@ -97,7 +98,8 @@ const postCodeUsages = (variables) => __awaiter(void 0, void 0, void 0, function const authToken = yield action.authenticate(clientId, clientSecret); const url = new URL(`/v1/projects/${projectKey}/codeUsages`, API_URL); const headers = { - Authorization: authToken + Authorization: authToken, + 'dvc-referrer': DVC_IDENTIFIER }; const { owner, repo } = github.context.repo; try { diff --git a/src/action.ts b/src/action.ts index 7a567c1..1e8c8ce 100644 --- a/src/action.ts +++ b/src/action.ts @@ -7,6 +7,8 @@ import axios from 'axios' const API_URL = 'https://api.devcycle.com/' const AUTH_URL = 'https://auth.devcycle.com/' +const DVC_IDENTIFIER = 'github.code_usages' + export async function run() { const requiredInputs = ['github-token', 'project-key', 'client-id', 'client-secret'] for (const inputKey of requiredInputs) { @@ -24,11 +26,11 @@ export async function run() { } try { - await exec('npm', ['install', '-g', '@devcycle/cli@4.2.8']) + await exec('npm', ['install', '-g', '@devcycle/cli@4.2.10']) const output = await getExecOutput( 'dvc', - ['usages', '--format', 'json'] + ['usages', '--format', 'json', '--caller', DVC_IDENTIFIER] ) const variables = JSON.parse(output.stdout) @@ -65,7 +67,8 @@ export const postCodeUsages = async (variables: any[]): Promise => { const url = new URL(`/v1/projects/${projectKey}/codeUsages`, API_URL) const headers = { - Authorization: authToken + Authorization: authToken, + 'dvc-referrer': DVC_IDENTIFIER } const { owner, repo } = github.context.repo