Skip to content

Commit

Permalink
fix(sentry_webhook): convert OS values to allowed picklist values (Ji…
Browse files Browse the repository at this point in the history
…gsaw-Code#1467)

* fix(sentry_webhook): convert OS values to allowed picklist values

* Make `Linux` the fallback.
  • Loading branch information
sbruens authored Jan 4, 2024
1 parent 90e8e57 commit 6c433ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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
25 changes: 24 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,29 @@ 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('android')) {
return 'Android';
}
if (normalizedValue.includes('ios')) {
return 'iOS';
}
if (normalizedValue.includes('windows')) {
return 'Windows';
}
if (normalizedValue.includes('mac')) {
return 'macOs';
}
return 'Linux';
}

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

0 comments on commit 6c433ed

Please sign in to comment.