@@ -88,7 +88,7 @@ export class GitHub {
88
88
}
89
89
}
90
90
91
- static checkEventType ( ) : string | null {
91
+ checkEventType ( ) : string | null {
92
92
switch ( env [ 'GITHUB_EVENT_NAME' ] ?. toLowerCase ( ) ) {
93
93
case 'push' :
94
94
return env [ 'PR_NUMBER' ] ? 'diff' : 'main'
@@ -112,7 +112,7 @@ export class GitHub {
112
112
}
113
113
}
114
114
115
- static async addSocketComments (
115
+ async addSocketComments (
116
116
securityComment : string ,
117
117
overviewComment : string ,
118
118
comments : Record < string , Comment > ,
@@ -132,7 +132,7 @@ export class GitHub {
132
132
)
133
133
} else {
134
134
debug ( 'Posting new Dependency Overview comment' )
135
- await GitHub . postComment ( overviewComment )
135
+ await this . postComment ( overviewComment )
136
136
}
137
137
}
138
138
@@ -146,19 +146,19 @@ export class GitHub {
146
146
)
147
147
} else {
148
148
debug ( 'Posting new Security Issue comment' )
149
- await GitHub . postComment ( securityComment )
149
+ await this . postComment ( securityComment )
150
150
}
151
151
}
152
152
}
153
153
154
- static async postComment ( body : string ) : Promise < void > {
154
+ async postComment ( body : string ) : Promise < void > {
155
155
const repo = env [ 'GITHUB_REPOSITORY' ] ?. split ( '/' ) [ 1 ]
156
156
const path = `repos/${ env [ 'GITHUB_REPOSITORY_OWNER' ] } /${ repo } /issues/${ env [ 'PR_NUMBER' ] } /comments`
157
157
const payload = JSON . stringify ( { body } )
158
158
await fetch ( path , { body : payload , method : 'POST' , headers } )
159
159
}
160
160
161
- static async updateComment ( body : string , commentId : string ) : Promise < void > {
161
+ async updateComment ( body : string , commentId : string ) : Promise < void > {
162
162
const repo = env [ 'GITHUB_REPOSITORY' ] ?. split ( '/' ) [ 1 ]
163
163
const path = `repos/${ env [ 'GITHUB_REPOSITORY_OWNER' ] } /${ repo } /issues/comments/${ commentId } `
164
164
const payload = JSON . stringify ( { body } )
@@ -174,7 +174,7 @@ export class GitHub {
174
174
file . close ( )
175
175
}
176
176
177
- static async getCommentsForPr (
177
+ async getCommentsForPR (
178
178
repo : string ,
179
179
pr : string
180
180
) : Promise < Record < string , Comment | Comment [ ] > > {
@@ -196,14 +196,35 @@ export class GitHub {
196
196
return Comments . checkForSocketComments ( comments )
197
197
}
198
198
199
- static async postReaction ( commentId : number ) : Promise < void > {
199
+ removeCommentAlerts ( comments : Record < string , Comment > ) : void {
200
+ const securityAlert = comments [ 'security' ]
201
+
202
+ if ( securityAlert ) {
203
+ const newBody = Comments . processSecurityComment ( securityAlert , comments )
204
+ this . handleIgnoreReactions ( comments )
205
+ this . updateComment ( newBody , String ( securityAlert . id ) )
206
+ }
207
+ }
208
+
209
+ handleIgnoreReactions ( comments : Record < string , Comment [ ] > ) : void {
210
+ if ( comments [ 'ignore' ] ) {
211
+ for ( const comment of comments [ 'ignore' ] ) {
212
+ if ( comment . body . includes ( 'SocketSecurity ignore' ) ) {
213
+ if ( ! this . commentReactionExists ( comment . id ) ) {
214
+ this . postReaction ( comment . id )
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ async postReaction ( commentId : number ) : Promise < void > {
200
221
const repo = env [ 'GITHUB_REPOSITORY' ] ?. split ( '/' ) [ 1 ]
201
222
const path = `repos/${ env [ 'GITHUB_REPOSITORY_OWNER' ] } /${ repo } /issues/comments/${ commentId } /reactions`
202
223
const payload = JSON . stringify ( { content : '+1' } )
203
224
await fetch ( path , { body : payload , method : 'POST' , headers } )
204
225
}
205
226
206
- static async commentReactionExists ( commentId : number ) : Promise < boolean > {
227
+ async commentReactionExists ( commentId : number ) : Promise < boolean > {
207
228
const repo = env [ 'GITHUB_REPOSITORY' ] ?. split ( '/' ) [ 1 ]
208
229
const path = `repos/${ env [ 'GITHUB_REPOSITORY_OWNER' ] } /${ repo } /issues/comments/${ commentId } /reactions`
209
230
try {
0 commit comments