Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/helpers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const yellow = chalk.bold.yellow;
// - DATADOG_APPS_INTAKE_URL
// - DD_APPS_UPLOAD_ASSETS
// - DATADOG_APPS_UPLOAD_ASSETS
// - DD_APPS_VERSION_NAME
// - DATADOG_APPS_VERSION_NAME
// - DD_SITE
// - DATADOG_SITE
const OVERRIDE_VARIABLES = [
Expand All @@ -28,6 +30,7 @@ const OVERRIDE_VARIABLES = [
'SOURCEMAP_INTAKE_URL',
'APPS_INTAKE_URL',
'APPS_UPLOAD_ASSETS',
'APPS_VERSION_NAME',
'SITE',
] as const;
type ENV_KEY = (typeof OVERRIDE_VARIABLES)[number];
Expand Down
47 changes: 47 additions & 0 deletions packages/plugins/apps/src/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ describe('Apps Plugin - upload', () => {
});
expect(data).toEqual({ data: 'data', headers: { 'x-custom': '1' } });
});

test('Should append version to form when APPS_VERSION_NAME env var is set', async () => {
const fakeFile = { name: 'archive' };
getFileMock.mockResolvedValue(fakeFile as any);
getDDEnvValueMock.mockImplementation((key) => {
if (key === 'APPS_VERSION_NAME') {
return '1.2.3';
}
return undefined;
});
let capturedGetForm: (() => FormData | Promise<FormData>) | undefined;
createRequestDataMock.mockImplementation(async (options) => {
capturedGetForm = options.getForm;
return { data: 'data' as any, headers: {} };
});

await getData('/tmp/archive.zip', {}, 'my-app')();

// Mock append to avoid Blob validation errors from the non-Blob archiveFile fixture.
const appendSpy = jest.spyOn(FormData.prototype, 'append').mockImplementation(() => {});
await capturedGetForm!();
expect(appendSpy).toHaveBeenCalledWith('version', '1.2.3');
appendSpy.mockRestore();
});

test('Should not append version to form when APPS_VERSION_NAME env var is only whitespace', async () => {
const fakeFile = { name: 'archive' };
getFileMock.mockResolvedValue(fakeFile as any);
getDDEnvValueMock.mockImplementation((key) => {
if (key === 'APPS_VERSION_NAME') {
return ' ';
}
return undefined;
});
let capturedGetForm: (() => FormData | Promise<FormData>) | undefined;
createRequestDataMock.mockImplementation(async (options) => {
capturedGetForm = options.getForm;
return { data: 'data' as any, headers: {} };
});

await getData('/tmp/archive.zip', {}, 'my-app')();

const appendSpy = jest.spyOn(FormData.prototype, 'append').mockImplementation(() => {});
await capturedGetForm!();
expect(appendSpy).not.toHaveBeenCalledWith('version', expect.anything());
appendSpy.mockRestore();
});
});

describe('uploadArchive', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/apps/src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export const getData =
const form = new FormData();
form.append('name', name);
form.append('bundle', archiveFile, ARCHIVE_FILENAME);
const versionName = getDDEnvValue('APPS_VERSION_NAME')?.trim();
if (versionName) {
form.append('version', versionName);
}
return form;
},
defaultHeaders,
Expand Down