Skip to content

Commit 564fa37

Browse files
committed
Create card at issue replication
1 parent 2d5670e commit 564fa37

2 files changed

Lines changed: 25 additions & 115 deletions

File tree

.github/actions/replicate/replicate.js

Lines changed: 12 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/replicate/replicate.ts

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
33
import { WebhookPayload } from '@actions/github/lib/interfaces'
4-
import { getIssueList, internalIssueAlreadyCreated, isUserAlreadyParticipant } from './issues'
4+
import { getIssueList, internalIssueAlreadyCreated } from './issues'
55

66
export const BOUNTY_LABELS = ['All For One', 'The Bug Slayer'] as const
77
export type BountyType = typeof BOUNTY_LABELS[number]
@@ -12,7 +12,7 @@ type GitHubIssue = { [key: string]: any, number: number, html_url?: string | und
1212
const COMMENT_TASK_LIST_AFO = `## Task List
1313
1414
- **If this is your first time in this process, have a look at that [5 min video](https://drive.google.com/drive/folders/1Jq6UfqP3CRF9Iafde86_IPAQPfdgH5rR)**
15-
- **Visit the [documented process](https://github.com/github/pe-security-lab/blob/master/docs/bug_bounty.md)**
15+
- **Visit the [documented process](https://github.com/github/pe-security-lab/blob/main/docs/bug_bounty.md)**
1616
1717
- [ ] CodeQL Initial assessment - In case of rejection, please record your decision in the comment below:
1818
- [ ] Acceptance
@@ -45,7 +45,7 @@ const COMMENT_TASK_LIST: CommentMap = {
4545

4646
const COMMENT_SCORING = `## Scoring
4747
48-
- **Visit the [scoring guidelines](https://github.com/github/pe-security-lab/blob/master/docs/bug_bounty.md)**
48+
- **Visit the [scoring guidelines](https://github.com/github/pe-security-lab/blob/main/docs/bug_bounty.md)**
4949
- **Accepted values are: 0 (= NA), or 1 (minimal) to 5 (maximal). Any other value will throw an error**
5050
5151
| Criterion | Score|
@@ -62,8 +62,6 @@ const COMMENT_SCORING = `## Scoring
6262
- [ ] Accept
6363
`
6464

65-
const COMMENT_FIRST_SUBMISSION = `## :tada: First submission for this user :tada:`
66-
6765
const getIssueFromRef = async (issueRef: string | undefined): Promise<GitHubIssue | undefined> => {
6866
if(!issueRef)
6967
return undefined
@@ -116,9 +114,8 @@ ${issue.body? issue.body : ""}`
116114
return result
117115
}
118116

119-
export const createInternalIssue = async (payload: WebhookPayload, issue: Issue) : Promise<number | undefined> => {
117+
export const createInternalIssue = async (issue: Issue) : Promise<number | undefined> => {
120118
const internalRepoAccessToken: string | undefined = process.env['INT_REPO_TOKEN']
121-
const token: string | undefined = process.env['GITHUB_TOKEN']
122119
let internal_ref: number | undefined = undefined
123120

124121
if(!internalRepoAccessToken) {
@@ -162,49 +159,19 @@ export const createInternalIssue = async (payload: WebhookPayload, issue: Issue)
162159
})
163160
core.debug(`comment created ${issueCommentResponse2.data.url}`)
164161

165-
if(await isFirstSubmission(payload, token)) {
166-
const issueCommentResponse3 = await octokit.issues.createComment({
167-
owner,
168-
repo,
169-
issue_number: internal_ref,
170-
body: COMMENT_FIRST_SUBMISSION,
171-
})
172-
core.debug(`comment created ${issueCommentResponse3.data.url}`)
173-
}
162+
const issueCard = await octokit.projects.createCard({
163+
column_id: (issue.labels.includes(BOUNTY_LABELS[1]))? 10205381 : 10205379,
164+
content_id: internal_ref,
165+
content_type: 'issue',
166+
});
167+
core.debug(`Card creation status: ${issueCard.status}`)
168+
174169
} catch(error) {
175170
core.debug(error.message)
176171
}
177172
return internal_ref
178173
}
179174

180-
const commentOriginalIssue = async (payload: WebhookPayload, internal_issue: number): Promise<void> => {
181-
const repository = payload.repository
182-
const external_issue = payload.issue? payload.issue.number : 0
183-
const token: string | undefined = process.env['GITHUB_TOKEN']
184-
185-
if(!token) {
186-
core.debug("No valid token for this repo")
187-
return
188-
}
189-
if(!repository || external_issue <=0) {
190-
core.debug("Invalid payload")
191-
return
192-
}
193-
try {
194-
const octokit: github.GitHub = new github.GitHub(token)
195-
const issueCommentResponseOriginal = await octokit.issues.createComment({
196-
owner: repository.owner.login,
197-
repo: repository.name,
198-
issue_number: external_issue,
199-
body: `Thanks for submitting this bounty :heart:!
200-
Your submission is tracked internally with the issue reference ${internal_issue}.`,
201-
})
202-
core.debug(`comment created ${issueCommentResponseOriginal.data.url}`)
203-
} catch (error) {
204-
core.debug(error.message)
205-
}
206-
}
207-
208175
const checkDuplicates = async (payload: WebhookPayload): Promise<boolean> => {
209176
const internalRepoAccessToken: string | undefined = process.env['INT_REPO_TOKEN']
210177
const internalRepo = core.getInput('internal_repo') || '/'
@@ -223,30 +190,17 @@ const checkDuplicates = async (payload: WebhookPayload): Promise<boolean> => {
223190
return false
224191
}
225192

226-
export const isFirstSubmission = async (payload: WebhookPayload, token : string | undefined) : Promise<boolean> => {
227-
const repository = payload.repository
228-
if(!repository)
229-
return false
230-
const allSubmissions = await getIssueList(repository.owner.login, repository.name, token, false, true)
231-
return !isUserAlreadyParticipant(payload.issue?.user.login, allSubmissions)
232-
}
233-
234193
const run = async (): Promise<void> => {
235194
const internalIssue = await generateInternalIssueContentFromPayload(github.context.payload, core.getInput('specific_issue'))
236195
if(!internalIssue)
237196
return
238197

239-
const existingIssue = core.getInput('existingIssue') || true
240-
if(existingIssue && await checkDuplicates(github.context.payload))
198+
if(await checkDuplicates(github.context.payload))
241199
return
242200

243-
const internal_ref = await createInternalIssue(github.context.payload, internalIssue)
201+
const internal_ref = await createInternalIssue(internalIssue)
244202
if(!internal_ref)
245203
return
246-
247-
if(!existingIssue) {
248-
commentOriginalIssue(github.context.payload, internal_ref)
249-
}
250204
}
251205

252206
run()

0 commit comments

Comments
 (0)