@@ -7,6 +7,7 @@ export const BOUNTY_LABELS = ['All For One', 'The Bug Slayer'] as const
77export type BountyType = typeof BOUNTY_LABELS [ number ]
88type CommentMap = { [ K in BountyType ] : string }
99export type Issue = { title : string , body : string , labels : string [ ] , bountyType : BountyType }
10+ type GitHubIssue = { [ key : string ] : any , number : number , html_url ?: string | undefined , body ?: string | undefined }
1011
1112const COMMENT_TASK_LIST_AFO = `## Task List
1213- [ ] CodeQL Initial assessment - In case of rejection, please record your decision in the comment below:
@@ -55,11 +56,25 @@ const COMMENT_SCORING = `## Scoring
5556
5657const COMMENT_FIRST_SUBMISSION = `## :tada: First submission for this user :tada:`
5758
58- export const generateInternalIssueContentFromPayload = async ( payload : WebhookPayload ) : Promise < Issue | undefined > => {
59- const issue = payload . issue
59+ const getIssueFromRef = async ( issueRef : string | undefined ) : Promise < GitHubIssue | undefined > => {
60+ if ( ! issueRef )
61+ return undefined
62+ const token : string | undefined = process . env [ 'GITHUB_TOKEN' ]
63+ if ( token === undefined )
64+ return undefined
65+ const octokit : github . GitHub = new github . GitHub ( token )
66+ const issueResponse = await octokit . issues . get ( {
67+ owner : github . context . repo . owner ,
68+ repo : github . context . repo . repo ,
69+ issue_number : Number ( issueRef ) ,
70+ } ) ;
71+ return issueResponse . data
72+ }
73+
74+ export const generateInternalIssueContentFromPayload = async ( payload ?: WebhookPayload , issueRef ?: string ) : Promise < Issue | undefined > => {
75+ const issue = await getIssueFromRef ( issueRef ) || payload ?. issue
6076 let result : Issue = { title : 'none' , body : 'none' , labels : [ ] , bountyType : 'All For One' }
6177 let bountyIssue : boolean = false
62- let bountyType = ''
6378
6479 if ( ! issue || ! issue . user || ! issue . html_url ) {
6580 core . debug ( "Invalid issue payload" )
@@ -71,7 +86,7 @@ export const generateInternalIssueContentFromPayload = async (payload: WebhookPa
7186 if ( ! bountyIssue ) {
7287 bountyIssue = BOUNTY_LABELS . includes ( element . name )
7388 if ( bountyIssue ) {
74- bountyType = element . name
89+ result . bountyType = element . name
7590 }
7691 }
7792 } ) ;
@@ -81,7 +96,7 @@ export const generateInternalIssueContentFromPayload = async (payload: WebhookPa
8196 return undefined
8297 }
8398
84- result . title = `[${ bountyType } ] ${ issue . title } ` ,
99+ result . title = `[${ result . bountyType } ] ${ issue . title } ` ,
85100 // In order to differentiate immediately the issues from others in the repo
86101 // And with the current situation, the robot with Read access cannot add labels to the issue
87102 result . body = `Original external [issue](${ issue . html_url } )
@@ -115,6 +130,13 @@ export const createInternalIssue = async (payload: WebhookPayload, issue: Issue)
115130 } )
116131 internal_ref = issueResponse . data . number
117132 core . debug ( `issue created: ${ internal_ref } ` )
133+ const labelsResponse = await octokit . issues . addLabels ( {
134+ owner,
135+ repo,
136+ issue_number : internal_ref ,
137+ labels : issue . labels
138+ } )
139+ core . debug ( `Labels addition result: ${ labelsResponse . status } ${ ( labelsResponse . status == 200 ) ? "OK" : "FAILED" } ` )
118140
119141 const issueCommentResponse1 = await octokit . issues . createComment ( {
120142 owner,
@@ -202,7 +224,7 @@ export const isFirstSubmission = async (payload: WebhookPayload, token : string
202224}
203225
204226const run = async ( ) : Promise < void > => {
205- const internalIssue = await generateInternalIssueContentFromPayload ( github . context . payload )
227+ const internalIssue = await generateInternalIssueContentFromPayload ( github . context . payload , core . getInput ( 'specific_issue' ) )
206228 if ( ! internalIssue )
207229 return
208230
0 commit comments