@@ -23,23 +23,30 @@ export async function getGitifySubjectDetails(
23
23
notification : Notification ,
24
24
token : string ,
25
25
) : Promise < GitifySubject > {
26
- switch ( notification . subject . type ) {
27
- case 'CheckSuite' :
28
- return getGitifySubjectForCheckSuite ( notification ) ;
29
- case 'Commit' :
30
- return getGitifySubjectForCommit ( notification , token ) ;
31
- case 'Discussion' :
32
- return await getGitifySubjectForDiscussion ( notification , token ) ;
33
- case 'Issue' :
34
- return await getGitifySubjectForIssue ( notification , token ) ;
35
- case 'PullRequest' :
36
- return await getGitifySubjectForPullRequest ( notification , token ) ;
37
- case 'Release' :
38
- return await getGitifySubjectForRelease ( notification , token ) ;
39
- case 'WorkflowRun' :
40
- return getGitifySubjectForWorkflowRun ( notification ) ;
41
- default :
42
- return null ;
26
+ try {
27
+ switch ( notification . subject . type ) {
28
+ case 'CheckSuite' :
29
+ return getGitifySubjectForCheckSuite ( notification ) ;
30
+ case 'Commit' :
31
+ return getGitifySubjectForCommit ( notification , token ) ;
32
+ case 'Discussion' :
33
+ return await getGitifySubjectForDiscussion ( notification , token ) ;
34
+ case 'Issue' :
35
+ return await getGitifySubjectForIssue ( notification , token ) ;
36
+ case 'PullRequest' :
37
+ return await getGitifySubjectForPullRequest ( notification , token ) ;
38
+ case 'Release' :
39
+ return await getGitifySubjectForRelease ( notification , token ) ;
40
+ case 'WorkflowRun' :
41
+ return getGitifySubjectForWorkflowRun ( notification ) ;
42
+ default :
43
+ return null ;
44
+ }
45
+ } catch ( err ) {
46
+ console . error (
47
+ `Error occurred while fetching details for ${ notification . subject . type } notification: ${ notification . subject . title } ` ,
48
+ err ,
49
+ ) ;
43
50
}
44
51
}
45
52
@@ -106,33 +113,29 @@ async function getGitifySubjectForCommit(
106
113
notification : Notification ,
107
114
token : string ,
108
115
) : Promise < GitifySubject > {
109
- try {
110
- let user : User ;
116
+ let user : User ;
111
117
112
- if ( notification . subject . latest_comment_url ) {
113
- const commitComment = (
114
- await getCommitComment ( notification . subject . latest_comment_url , token )
115
- ) . data ;
118
+ if ( notification . subject . latest_comment_url ) {
119
+ const commitComment = (
120
+ await getCommitComment ( notification . subject . latest_comment_url , token )
121
+ ) . data ;
116
122
117
- user = commitComment . user ;
118
- } else {
119
- const commit = ( await getCommit ( notification . subject . url , token ) ) . data ;
123
+ user = commitComment . user ;
124
+ } else {
125
+ const commit = ( await getCommit ( notification . subject . url , token ) ) . data ;
120
126
121
- user = commit . author ;
122
- }
123
-
124
- return {
125
- state : null ,
126
- user : {
127
- login : user . login ,
128
- html_url : user . html_url ,
129
- avatar_url : user . avatar_url ,
130
- type : user . type ,
131
- } ,
132
- } ;
133
- } catch ( err ) {
134
- console . error ( 'Commit subject retrieval failed' ) ;
127
+ user = commit . author ;
135
128
}
129
+
130
+ return {
131
+ state : null ,
132
+ user : {
133
+ login : user . login ,
134
+ html_url : user . html_url ,
135
+ avatar_url : user . avatar_url ,
136
+ type : user . type ,
137
+ } ,
138
+ } ;
136
139
}
137
140
138
141
async function getGitifySubjectForDiscussion (
@@ -181,73 +184,65 @@ async function getGitifySubjectForIssue(
181
184
notification : Notification ,
182
185
token : string ,
183
186
) : Promise < GitifySubject > {
184
- try {
185
- const issue = ( await getIssue ( notification . subject . url , token ) ) . data ;
186
-
187
- let issueCommentUser : User ;
188
-
189
- if ( notification . subject . latest_comment_url ) {
190
- const issueComment = (
191
- await getIssueOrPullRequestComment (
192
- notification . subject . latest_comment_url ,
193
- token ,
194
- )
195
- ) . data ;
196
- issueCommentUser = issueComment . user ;
197
- }
198
-
199
- return {
200
- state : issue . state_reason ?? issue . state ,
201
- user : {
202
- login : issueCommentUser ?. login ?? issue . user . login ,
203
- html_url : issueCommentUser ?. html_url ?? issue . user . html_url ,
204
- avatar_url : issueCommentUser ?. avatar_url ?? issue . user . avatar_url ,
205
- type : issueCommentUser ?. type ?? issue . user . type ,
206
- } ,
207
- } ;
208
- } catch ( err ) {
209
- console . error ( 'Issue subject retrieval failed' ) ;
187
+ const issue = ( await getIssue ( notification . subject . url , token ) ) . data ;
188
+
189
+ let issueCommentUser : User ;
190
+
191
+ if ( notification . subject . latest_comment_url ) {
192
+ const issueComment = (
193
+ await getIssueOrPullRequestComment (
194
+ notification . subject . latest_comment_url ,
195
+ token ,
196
+ )
197
+ ) . data ;
198
+ issueCommentUser = issueComment . user ;
210
199
}
200
+
201
+ return {
202
+ state : issue . state_reason ?? issue . state ,
203
+ user : {
204
+ login : issueCommentUser ?. login ?? issue . user . login ,
205
+ html_url : issueCommentUser ?. html_url ?? issue . user . html_url ,
206
+ avatar_url : issueCommentUser ?. avatar_url ?? issue . user . avatar_url ,
207
+ type : issueCommentUser ?. type ?? issue . user . type ,
208
+ } ,
209
+ } ;
211
210
}
212
211
213
212
async function getGitifySubjectForPullRequest (
214
213
notification : Notification ,
215
214
token : string ,
216
215
) : Promise < GitifySubject > {
217
- try {
218
- const pr = ( await getPullRequest ( notification . subject . url , token ) ) . data ;
219
-
220
- let prState : PullRequestStateType = pr . state ;
221
- if ( pr . merged ) {
222
- prState = 'merged' ;
223
- } else if ( pr . draft ) {
224
- prState = 'draft' ;
225
- }
216
+ const pr = ( await getPullRequest ( notification . subject . url , token ) ) . data ;
226
217
227
- let prCommentUser : User ;
218
+ let prState : PullRequestStateType = pr . state ;
219
+ if ( pr . merged ) {
220
+ prState = 'merged' ;
221
+ } else if ( pr . draft ) {
222
+ prState = 'draft' ;
223
+ }
228
224
229
- if ( notification . subject . latest_comment_url ) {
230
- const prComment = (
231
- await getIssueOrPullRequestComment (
232
- notification . subject . latest_comment_url ,
233
- token ,
234
- )
235
- ) . data ;
236
- prCommentUser = prComment . user ;
237
- }
225
+ let prCommentUser : User ;
238
226
239
- return {
240
- state : prState ,
241
- user : {
242
- login : prCommentUser ?. login ?? pr . user . login ,
243
- html_url : prCommentUser ?. html_url ?? pr . user . html_url ,
244
- avatar_url : prCommentUser ?. avatar_url ?? pr . user . avatar_url ,
245
- type : prCommentUser ?. type ?? pr . user . type ,
246
- } ,
247
- } ;
248
- } catch ( err ) {
249
- console . error ( 'Pull Request subject retrieval failed' ) ;
227
+ if ( notification . subject . latest_comment_url ) {
228
+ const prComment = (
229
+ await getIssueOrPullRequestComment (
230
+ notification . subject . latest_comment_url ,
231
+ token ,
232
+ )
233
+ ) . data ;
234
+ prCommentUser = prComment . user ;
250
235
}
236
+
237
+ return {
238
+ state : prState ,
239
+ user : {
240
+ login : prCommentUser ?. login ?? pr . user . login ,
241
+ html_url : prCommentUser ?. html_url ?? pr . user . html_url ,
242
+ avatar_url : prCommentUser ?. avatar_url ?? pr . user . avatar_url ,
243
+ type : prCommentUser ?. type ?? pr . user . type ,
244
+ } ,
245
+ } ;
251
246
}
252
247
253
248
async function getGitifySubjectForRelease (
0 commit comments