Skip to content

Commit

Permalink
[chore] Add dvc-referrer headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Warr authored and laurawarr committed Mar 29, 2023
1 parent c57e760 commit ae54c22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ describe('postCodeUsages', () => {
}),
expect.objectContaining({
headers: {
Authorization: 'generated-token'
Authorization: 'generated-token',
'dvc-referrer': 'github.code_usages'
}
})
)
Expand Down
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -62,8 +63,8 @@ function run() {
return;
}
try {
yield (0, exec_1.exec)('npm', ['install', '-g', '@devcycle/[email protected].8']);
const output = yield (0, exec_1.getExecOutput)('dvc', ['usages', '--format', 'json']);
yield (0, exec_1.exec)('npm', ['install', '-g', '@devcycle/[email protected].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);
}
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,11 +26,11 @@ export async function run() {
}

try {
await exec('npm', ['install', '-g', '@devcycle/[email protected].8'])
await exec('npm', ['install', '-g', '@devcycle/[email protected].10'])

const output = await getExecOutput(
'dvc',
['usages', '--format', 'json']
['usages', '--format', 'json', '--caller', DVC_IDENTIFIER]
)
const variables = JSON.parse(output.stdout)

Expand Down Expand Up @@ -65,7 +67,8 @@ export const postCodeUsages = async (variables: any[]): Promise<void> => {
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

Expand Down

0 comments on commit ae54c22

Please sign in to comment.