Skip to content

Commit 5e3d91f

Browse files
committed
checks and manual
1 parent 07fa762 commit 5e3d91f

11 files changed

Lines changed: 213 additions & 11 deletions

File tree

.github/actions/check/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'check-replication-action'
2+
description: 'Checks that all external bounties are replicated internally'
3+
author: 'xcorail'
4+
inputs:
5+
internal_repo:
6+
description: 'The destination repo for the internal issue'
7+
default: 'github/securitylab-bounties'
8+
runs:
9+
using: 'node12'
10+
main: './check-replication.js'

.github/actions/check/check-replication.js

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as core from '@actions/core'
2+
import * as github from '@actions/github'
3+
import { getIssueList, internalIssueAlreadyCreated } from '../replicate/issues'
4+
5+
const run = async (): Promise<void> => {
6+
const internalRepoAccessToken: string | undefined = process.env['INT_REPO_TOKEN']
7+
const internalRepo = core.getInput('internal_repo') || '/'
8+
const [owner, repo] = internalRepo.split('/')
9+
const internalIssues = await getIssueList(owner, repo, internalRepoAccessToken, false, false)
10+
if(!internalIssues) {
11+
core.setFailed(`Internal error. Cannot access the internal repo ${internalRepo}. Aborting`)
12+
return
13+
} else {
14+
const externalIssues = await getIssueList(github.context.repo.owner, github.context.repo.repo, process.env['GITHUB_TOKEN'], true, true)
15+
if(!externalIssues) {
16+
core.setFailed(`Internal error when retrieving all issues.`)
17+
return
18+
}
19+
let failed = false
20+
externalIssues.forEach( issue => {
21+
const ref = internalIssueAlreadyCreated(issue?.html_url, internalIssues)
22+
if(!ref) {
23+
core.debug(`External issue ${issue?.number} is not replicated internally.`)
24+
failed = true
25+
}
26+
})
27+
if(failed) {
28+
core.setFailed("Some submissions are not replicated internally, see execution logs.")
29+
}
30+
}
31+
return
32+
}
33+
34+
run()
35+
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'debug-action'
2-
description: 'Outputs debug information'
1+
name: 'replicate-action'
2+
description: 'Replicates bounty internal'
33
author: 'xcorail'
44
inputs:
55
internal_repo:
@@ -8,6 +8,9 @@ inputs:
88
existing_issue:
99
description: 'Launching on existing issues: we check duplicates, and we do not comment the original issue'
1010
default: false
11+
specific_issue:
12+
description: 'Specific issue to replicate, in case of manual trigger'
13+
default: ''
1114
runs:
1215
using: 'node12'
1316
main: './replicate.js'

.github/actions/replicate/issues.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/replicate/issues.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as core from '@actions/core'
22
import * as github from '@actions/github'
33
import * as replicate from './replicate'
44

5-
export type Issue_info = {title: string, author: string, body: string, number: number}
5+
export type Issue_info = {title: string, author: string, body: string, number: number, html_url?: string}
66
type Issue_state = 'open' | 'all' | 'closed' | undefined
77

88
export const getIssueList = async (owner: string, repo: string, token: string | undefined, open: boolean, checkBountyLabels: boolean, per_page?: number) : Promise<Issue_info[] | undefined> => {
@@ -32,7 +32,8 @@ export const getIssueList = async (owner: string, repo: string, token: string |
3232
title: issue.title,
3333
author: issue.user?.login,
3434
body: issue.body? issue.body : '',
35-
number: issue.number
35+
number: issue.number,
36+
html_url: issue.html_url
3637
}
3738
result.push(item)
3839
}

.github/actions/replicate/replicate.js

Lines changed: 17 additions & 3 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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const BOUNTY_LABELS = ['All For One', 'The Bug Slayer'] as const
77
export type BountyType = typeof BOUNTY_LABELS[number]
88
type CommentMap = {[K in BountyType]: string}
99
export 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

1112
const COMMENT_TASK_LIST_AFO = `## Task List
1213
- [ ] CodeQL Initial assessment - In case of rejection, please record your decision in the comment below:
@@ -55,8 +56,23 @@ const COMMENT_SCORING = `## Scoring
5556

5657
const 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
6278
let bountyType = ''
@@ -202,7 +218,7 @@ export const isFirstSubmission = async (payload: WebhookPayload, token : string
202218
}
203219

204220
const run = async (): Promise<void> => {
205-
const internalIssue = await generateInternalIssueContentFromPayload(github.context.payload)
221+
const internalIssue = await generateInternalIssueContentFromPayload(github.context.payload, core.getInput('specific_issue'))
206222
if(!internalIssue)
207223
return
208224

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Bounty issue replication workflow'
2+
on: workflow_dispatch
3+
4+
jobs:
5+
build:
6+
name: check-replicate-manual
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
with:
11+
fetch-depth: 1
12+
- run: npm install
13+
- run: npm run build
14+
- uses: ./.github/actions/check
15+
with:
16+
internal_repo: 'github/securitylab-bounties'
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
INT_REPO_TOKEN: ${{ secrets.INT_REPO_TOKEN }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Bounty issue replication workflow'
2+
on:
3+
schedule:
4+
- cron: '0 17 * * *'
5+
6+
jobs:
7+
build:
8+
name: check-replicate
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
with:
13+
fetch-depth: 1
14+
- run: npm install
15+
- run: npm run build
16+
- uses: ./.github/actions/check
17+
with:
18+
internal_repo: 'github/securitylab-bounties'
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
INT_REPO_TOKEN: ${{ secrets.INT_REPO_TOKEN }}

0 commit comments

Comments
 (0)