Skip to content

Commit 1a24d89

Browse files
committed
fix sonar issues
Signed-off-by: Adam Setch <[email protected]>
1 parent c3783e8 commit 1a24d89

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/renderer/utils/notifications/handlers/checkSuite.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,25 @@ export const checkSuiteHandler = new CheckSuiteHandler();
6363
export function getCheckSuiteAttributes(
6464
notification: Notification,
6565
): CheckSuiteAttributes | null {
66-
const regexPattern =
66+
const regex =
6767
/^(?<workflowName>.*?) workflow run(, Attempt #(?<attemptNumber>\d+))? (?<statusDisplayName>.*?) for (?<branchName>.*?) branch$/;
6868

69-
const matches = regexPattern.exec(notification.subject.title);
69+
const match = regex.exec(notification.subject.title);
7070

71-
if (matches) {
72-
const { groups } = matches;
73-
74-
return {
75-
workflowName: groups.workflowName,
76-
attemptNumber: groups.attemptNumber
77-
? Number.parseInt(groups.attemptNumber)
78-
: null,
79-
status: getCheckSuiteStatus(groups.statusDisplayName),
80-
statusDisplayName: groups.statusDisplayName,
81-
branchName: groups.branchName,
82-
};
71+
if (!match?.groups) {
72+
return null;
8373
}
8474

85-
return null;
75+
const { workflowName, attemptNumber, statusDisplayName, branchName } =
76+
match.groups;
77+
78+
return {
79+
workflowName,
80+
attemptNumber: attemptNumber ? Number.parseInt(attemptNumber) : null,
81+
status: getCheckSuiteStatus(statusDisplayName),
82+
statusDisplayName,
83+
branchName,
84+
};
8685
}
8786

8887
function getCheckSuiteStatus(statusDisplayName: string): CheckSuiteStatus {

src/renderer/utils/notifications/handlers/workflowRun.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ export const workflowRunHandler = new WorkflowRunHandler();
4646
export function getWorkflowRunAttributes(
4747
notification: Notification,
4848
): WorkflowRunAttributes | null {
49-
const regexPattern =
49+
const regex =
5050
/^(?<user>.*?) requested your (?<statusDisplayName>.*?) to deploy to an environment$/;
5151

52-
const matches = regexPattern.exec(notification.subject.title);
52+
const match = regex.exec(notification.subject.title);
5353

54-
if (matches) {
55-
const { groups } = matches;
56-
57-
return {
58-
user: groups.user,
59-
status: getWorkflowRunStatus(groups.statusDisplayName),
60-
statusDisplayName: groups.statusDisplayName,
61-
};
54+
if (!match?.groups) {
55+
return null;
6256
}
6357

64-
return null;
58+
const { user, statusDisplayName } = match.groups;
59+
60+
return {
61+
user: user,
62+
status: getWorkflowRunStatus(statusDisplayName),
63+
statusDisplayName: statusDisplayName,
64+
};
6565
}
6666

6767
function getWorkflowRunStatus(statusDisplayName: string): CheckSuiteStatus {

0 commit comments

Comments
 (0)