Skip to content

Commit ef70eae

Browse files
committed
Replicate bounty issue
1 parent 76e4953 commit ef70eae

15 files changed

Lines changed: 6844 additions & 0 deletions

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js
2+
!/.github

.github/actions/replicate/__tests__/replicate.test.js

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import * as core from '@actions/core'
2+
import * as replicate from '../replicate'
3+
import { WebhookPayload, PayloadRepository } from '@actions/github/lib/interfaces'
4+
5+
const TEST_ISSUE_1 = 1
6+
const TEST_REPOSITORY: PayloadRepository = {
7+
full_name: 'myuser/myrepo',
8+
name: 'myrepo',
9+
owner: {
10+
login: 'myuser',
11+
name: 'My User'
12+
}
13+
}
14+
15+
const TEST_INVALID_PAYLOAD_NOUSER: WebhookPayload = {
16+
repository: TEST_REPOSITORY,
17+
issue: {
18+
number: TEST_ISSUE_1,
19+
html_url: 'https://github.com/test_owner/test_repo/issues/1',
20+
}
21+
}
22+
23+
const TEST_INVALID_PAYLOAD_NOURL: WebhookPayload = {
24+
repository: TEST_REPOSITORY,
25+
issue: {
26+
number: TEST_ISSUE_1,
27+
user: {
28+
login: 'issue_user',
29+
html_url: 'https://github.com/users/issue_user'
30+
}
31+
}
32+
}
33+
34+
const TEST_INVALID_PAYLOAD_NOISSUE: WebhookPayload = {
35+
repository: TEST_REPOSITORY,
36+
}
37+
38+
const TEST_LABEL_ALLFORONE = { name: 'All For One' }
39+
const TEST_LABEL_NOTBOUNTY_1 = { name: 'not-a-bounty-label' }
40+
const TEST_LABEL_NOTBOUNTY_2 = { name: 'not-a-bounty-label-either' }
41+
42+
const TEST_PAYLOAD_NOTBOUNTY: WebhookPayload = {
43+
repository: TEST_REPOSITORY,
44+
issue: {
45+
number: TEST_ISSUE_1,
46+
html_url: 'https://github.com/test_owner/test_repo/issues/1',
47+
user: {
48+
login: 'issue_user',
49+
html_url: 'https://github.com/users/issue_user'
50+
},
51+
labels: [TEST_LABEL_NOTBOUNTY_1,TEST_LABEL_NOTBOUNTY_2],
52+
}
53+
}
54+
55+
const TEST_PAYLOAD: WebhookPayload = {
56+
repository: TEST_REPOSITORY,
57+
issue: {
58+
number: TEST_ISSUE_1,
59+
html_url: 'https://github.com/test_owner/test_repo/issues/1',
60+
user: {
61+
login: 'ghsecuritylab',
62+
html_url: 'https://github.com/ghsecuritylab'
63+
},
64+
title: 'Issue Title',
65+
labels: [TEST_LABEL_ALLFORONE,TEST_LABEL_NOTBOUNTY_1],
66+
body: `# This is the issue title
67+
This is the issue body first line
68+
This is the issue body second line
69+
`
70+
}
71+
}
72+
73+
const TEST_GENERATED_ISSUE: replicate.Issue = {
74+
title: '[BOUNTY - All For One] Issue Title',
75+
labels: ['All For One','not-a-bounty-label'],
76+
body: `Original external [issue](https://github.com/test_owner/test_repo/issues/1)
77+
78+
Sumitted by [ghsecuritylab](https://github.com/ghsecuritylab)
79+
80+
# This is the issue title
81+
This is the issue body first line
82+
This is the issue body second line
83+
`
84+
}
85+
86+
describe('log errors when generating issue content', () => {
87+
it('outputs a message for invalid issue in payload', async () => {
88+
const debugMock = jest.spyOn(core, 'debug')
89+
const issue = await replicate.generateInternalIssueContentFromPayload(TEST_INVALID_PAYLOAD_NOURL)
90+
expect(debugMock).toHaveBeenCalledWith('Invalid issue payload')
91+
expect(issue).toBeUndefined()
92+
93+
const issue2 = await replicate.generateInternalIssueContentFromPayload(TEST_INVALID_PAYLOAD_NOUSER)
94+
expect(debugMock).toHaveBeenCalledWith('Invalid issue payload')
95+
expect(issue2).toBeUndefined()
96+
97+
const issue3 = await replicate.generateInternalIssueContentFromPayload(TEST_INVALID_PAYLOAD_NOISSUE)
98+
expect(debugMock).toHaveBeenCalledWith('Invalid issue payload')
99+
expect(issue3).toBeUndefined()
100+
101+
})
102+
})
103+
104+
describe('excludes non bounty issues', () => {
105+
it('creates the proper issue', async () => {
106+
const debugMock = jest.spyOn(core, 'debug')
107+
const issue = await replicate.generateInternalIssueContentFromPayload(TEST_PAYLOAD_NOTBOUNTY)
108+
expect(debugMock).toHaveBeenCalledWith('Not a bounty')
109+
expect(issue).toBeUndefined()
110+
})
111+
})
112+
113+
describe('generates proper content', () => {
114+
it('creates the proper issue', async () => {
115+
const issue = await replicate.generateInternalIssueContentFromPayload(TEST_PAYLOAD)
116+
expect(issue).toBeDefined()
117+
expect(issue).toEqual(TEST_GENERATED_ISSUE)
118+
})
119+
})
120+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'debug-action'
2+
description: 'Outputs debug information'
3+
author: 'xcorail'
4+
inputs:
5+
internal_repo:
6+
description: 'The destination repo for the internal issue'
7+
default: 'github/securitylab-bounties'
8+
existing_issue:
9+
description: 'Launching on existing issues: we check duplicates, and we do not comment the original issue'
10+
default: false
11+
runs:
12+
using: 'node12'
13+
main: './replicate.js'

.github/actions/replicate/issues.js

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

0 commit comments

Comments
 (0)