Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sentry_webhook): convert OS values to allowed picklist values #1467

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/sentry_webhook/post_sentry_event_to_salesforce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('postSentryEventToSalesforce', () => {
message: 'my message',
tags: [
['category', 'test category'],
['os.name', 'test os'],
['os.name', 'Mac OS X'],
['sentry:release', 'test version'],
['unknown:tag', 'foo'],
],
Expand All @@ -109,7 +109,7 @@ describe('postSentryEventToSalesforce', () => {
'&description=my%20message' +
'&type=Outline%20client' +
'&00N0b00000BqOA2=test%20category' +
'&00N0b00000BqOfW=test%20os' +
'&00N0b00000BqOfW=macOs' +
'&00N0b00000BqOfR=test%20version'
);
expect(mockRequest.end).toHaveBeenCalled();
Expand Down
29 changes: 28 additions & 1 deletion src/sentry_webhook/post_sentry_event_to_salesforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getSalesforceFormData(
if (event.tags) {
const tags = new Map<string, string>(event.tags);
form.push(encodeFormData(formFields.category, tags.get('category')));
form.push(encodeFormData(formFields.os, tags.get('os.name')));
form.push(encodeFormData(formFields.os, toOSPicklistValue(tags.get('os.name'))));
form.push(encodeFormData(formFields.version, tags.get('sentry:release')));
if (!isClient) {
form.push(encodeFormData(formFields.cloudProvider, tags.get('cloudProvider')));
Expand All @@ -151,6 +151,33 @@ function getSalesforceFormData(
return form.join('&');
}

// Returns a picklist value that is allowed by SalesForce for the OS record.
function toOSPicklistValue(value: string | undefined): string | undefined {
if (!value) {
console.warn('No OS found');
return undefined;
}

const normalizedValue = value.toLowerCase();
if (normalizedValue.includes('linux') || normalizedValue.includes('fedora')) {
return 'Linux';
}
if (normalizedValue.includes('android')) {
return 'Android';
}
if (normalizedValue.includes('ios')) {
return 'iOS';
}
if (normalizedValue.includes('windows')) {
return 'Windows';
}
if (normalizedValue.includes('mac')) {
return 'macOs';
}
console.warn('Unexpected OS:', value);
return value;
}

function encodeFormData(field: string, value?: string) {
return `${encodeURIComponent(field)}=${encodeURIComponent(value || '')}`;
}
Expand Down
Loading