Skip to content

Commit

Permalink
feat: add deviceOs parameter message insteadof device and os
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanngocptn committed May 15, 2024
1 parent ca077b6 commit c2c1f43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ export type HookMessageDataType = {
mechanism?: string;
device?: string;
os?: string;
deviceOs?: string;
detailLink?: string;
};
29 changes: 24 additions & 5 deletions src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,35 @@ export class AppService {
);
}
async getIssueDetail(issueId): Promise<HookMessageDataType> {
const res = await axios({
const { data } = await axios({
method: 'get',
url: `https://sentry.io/api/0/organizations/${process.env.SENTRY_ORGANIZATION_SLUG}/issues/${issueId}/tags/`,
headers: {
Authorization: `Bearer ${process.env.SENTRY_INTEGRATION_TOKEN}`,
},
});
return res?.data?.reduce(
(cur, nex) => ({ ...cur, [nex.key]: nex?.topValues?.[0]?.value }),
{},
);

const device = data
?.find((item) => item?.key === 'device')
?.topValues?.map((item) => item?.value);

const os = data
?.find?.((item) => item?.key === 'os')
?.topValues?.map?.((item) => item?.value);

const deviceOs = device
?.map?.((item, index) => `${item} (${os?.[index]})`)
?.join?.(', ');

return data?.reduce(
(cur, nex) => ({
...cur,
[nex.key]: nex?.topValues
?.map?.((item) => item?.value)
?.filter((item) => !!item)
?.join(', '),
}),
{ deviceOs },
) as HookMessageDataType;
}
}
4 changes: 2 additions & 2 deletions src/app.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function generateHookMessageEn(data: HookMessageDataType) {
\\- *Position:* ${_data.errorPosition || 'none'}
\\- *Environment:* ${_data.environment || 'none'}
\\- *Version:* ${_data.release || 'none'}
\\- *Devices:* ${_data.device || 'none'} \\(${_data.os || 'none'}\\)
\\- *Devices:* ${_data.deviceOs || 'none'}
*Detail:* [HERE](${_data.detailLink})
`;
Expand All @@ -26,7 +26,7 @@ export function generateHookMessageVi(data: HookMessageDataType) {
\\- *Lỗi ở:* ${_data.errorPosition || 'none'}
\\- *Môi trường:* ${_data.environment || 'none'}
\\- *Phiên bản:* ${_data.release || 'none'}
\\- *Thiết bị:* ${_data.device || 'none'} \\(${_data.os || 'none'}\\)
\\- *Thiết bị:* ${_data.deviceOs || 'none'}
*Xem chi tiết:* [TẠI ĐÂY](${_data.detailLink})
`;
Expand Down

0 comments on commit c2c1f43

Please sign in to comment.