Skip to content

Commit 929e506

Browse files
authored
Modular Flex Architecture.
Flex
2 parents 537ea30 + 4402ac4 commit 929e506

File tree

101 files changed

+6797
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+6797
-549
lines changed

.github/mergeable.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
mergeable:
2-
approvals: 0
3-
milestone: 'Version 1.1'
2+
approvals: 1

LICENSE

Lines changed: 656 additions & 6 deletions
Large diffs are not rendered by default.

__fixtures__/helper.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
const _ = require('lodash')
2+
3+
const throwNotFound = () => {
4+
let error = new Error('404 error')
5+
error.code = 404
6+
throw error
7+
}
8+
19
module.exports = {
210
mockContext: (options) => {
311
if (!options) options = {}
412

513
return {
614
repo: (properties) => { return Object.assign({ owner: 'owner', repo: 'repo' }, properties) },
15+
event: (options.event) ? options.event : 'pull_request',
716
payload: {
817
pull_request: {
918
user: {
@@ -12,6 +21,7 @@ module.exports = {
1221
title: (options.title) ? options.title : 'title',
1322
body: options.body,
1423
number: (options.number) ? options.number : 1,
24+
milestone: (options.milestone) ? options.milestone : null,
1525
base: {
1626
ref: 'baseRef',
1727
sha: 'sha2'
@@ -25,21 +35,24 @@ module.exports = {
2535
assignees: (options.assignees) ? options.assignees : []
2636
}
2737
},
38+
log: {
39+
debug: (s) => console.log(`TEST[debug] > ${JSON.stringify(s)}`),
40+
info: (s) => console.log(`TEST[info] > ${JSON.stringify(s)}`),
41+
warn: (s) => console.log(`TEST[warn] > ${JSON.stringify(s)}`)
42+
},
2843
github: {
2944
repos: {
3045
createStatus: () => {},
3146
getContent: ({ path }) => {
3247
return new Promise((resolve, reject) => {
3348
if (path === '.github/mergeable.yml') {
34-
let error = new Error('404 error')
35-
error.code = 404
36-
throw error
49+
throwNotFound()
3750
}
3851

3952
if (path === '.github/CODEOWNERS') {
4053
return options.codeowners ? resolve({ data: {
4154
content: options.codeowners
42-
}}) : resolve()
55+
}}) : throwNotFound()
4356
}
4457
})
4558
},
@@ -63,7 +76,11 @@ module.exports = {
6376
},
6477
pullRequests: {
6578
getFiles: () => {
66-
return { data: options.files && options.files.map(file => ({filename: file, status: 'modified'})) }
79+
if (_.isString(options.files && options.files[0])) {
80+
return { data: options.files.map(file => ({filename: file, status: 'modified'})) }
81+
} else {
82+
return { data: options.files && options.files }
83+
}
6784
},
6885
getReviews: () => {
6986
return { data: (options.reviews) ? options.reviews : [] }
@@ -85,7 +102,7 @@ module.exports = {
85102
return { data: (options.labels) ? options.labels : [] }
86103
},
87104
get: () => {
88-
return {data: (options.milestone) ? {milestone: options.milestone} : {}}
105+
return {data: (options.deepValidation) ? options.deepValidation : {}}
89106
}
90107
}
91108
}
@@ -105,12 +122,16 @@ module.exports = {
105122
}
106123
},
107124

108-
mockConfigWithContext: (context, configString) => {
125+
mockConfigWithContext: (context, configString, options) => {
109126
context.github.repos.getContent = () => {
110127
return Promise.resolve({ data: {
111128
content: Buffer.from(configString).toString('base64') }
112129
})
113130
}
131+
context.github.pullRequests.getFiles = () => {
132+
return Promise.resolve({
133+
data: options && options.files ? options.files.map(file => ({ filename: file, status: 'modified' })) : []
134+
})
135+
}
114136
}
115-
116137
}

__tests__/actions/action.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { Action } = require('../../lib/actions/action')
2+
3+
describe('Action#isEventSupported', () => {
4+
let action = new Action()
5+
6+
test('Returns correctly with one supported event', () => {
7+
action.supportedEvents = ['issues.opened']
8+
expect(action.isEventSupported('pull_request.opened')).toBe(false)
9+
expect(action.isEventSupported('issues.opened')).toBe(true)
10+
})
11+
12+
test('Returns correctly with more than one supported event', () => {
13+
action.supportedEvents = ['issues.opened', 'pull_request.opened']
14+
expect(action.isEventSupported('pull_request.labeled')).toBe(false)
15+
expect(action.isEventSupported('issues.opened')).toBe(true)
16+
expect(action.isEventSupported('pull_request.opened')).toBe(true)
17+
})
18+
19+
test('Returns correctly with a wildcard in the event name', () => {
20+
action.supportedEvents = ['issues.opened', 'pull_request.*']
21+
expect(action.isEventSupported('pull_request.labeled')).toBe(true)
22+
expect(action.isEventSupported('issues.milestoned')).toBe(false)
23+
})
24+
})

__tests__/actions/checks.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const Checks = require('../../lib/actions/checks')
2+
const Helper = require('../../__fixtures__/helper')
3+
4+
test('check that checks created when doPostAction is called with proper parameter', async () => {
5+
const checks = new Checks()
6+
const context = createMockContext()
7+
8+
await checks.beforeValidate({context})
9+
expect(context.github.checks.create.mock.calls.length).toBe(1)
10+
})
11+
12+
test('check that checks created when doPostAction is called with proper parameter', async () => {
13+
const checks = new Checks()
14+
const context = createMockContext()
15+
const result = {
16+
status: 'pass',
17+
validations: [{
18+
status: 'pass',
19+
name: 'Label'
20+
}]
21+
}
22+
const settings = {
23+
payload: {
24+
title: `Your run has returned the following status: {{status}}`,
25+
summary: 'This is the summary'
26+
}
27+
}
28+
29+
checks.checkRunResult = {
30+
data: {
31+
id: '3'
32+
}
33+
}
34+
35+
await checks.afterValidate(context, settings, result)
36+
expect(context.github.checks.update.mock.calls.length).toBe(1)
37+
expect(context.github.checks.update.mock.calls[0][0].output.summary).toBe('This is the summary')
38+
expect(context.github.checks.update.mock.calls[0][0].output.title).toBe('Your run has returned the following status: pass')
39+
})
40+
41+
const createMockContext = () => {
42+
let context = Helper.mockContext()
43+
44+
context.github.checks.create = jest.fn()
45+
context.github.checks.update = jest.fn()
46+
return context
47+
}

__tests__/actions/comment.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const Comment = require('../../lib/actions/comment')
2+
const Helper = require('../../__fixtures__/helper')
3+
4+
const settings = {
5+
payload: {
6+
body: `Your run has returned the following status: {{status}}`
7+
}
8+
}
9+
10+
let result = {
11+
status: 'pass',
12+
validations: [{
13+
status: 'pass',
14+
name: 'Label'
15+
}]
16+
}
17+
18+
test('check that comment created when afterValidate is called with proper parameter', async () => {
19+
const comment = new Comment()
20+
const context = createMockContext()
21+
22+
await comment.afterValidate(context, settings, result)
23+
expect(context.github.issues.createComment.mock.calls.length).toBe(1)
24+
expect(context.github.issues.createComment.mock.calls[0][0].body).toBe(`Your run has returned the following status: pass`)
25+
})
26+
27+
test('that comment is created three times when result contain three issues found to be acted on', async () => {
28+
const comment = new Comment()
29+
const context = createMockContext()
30+
31+
result.validationSuites = [{
32+
schedule: {
33+
issues: [{number: 1}, {number: 2}, {number: 3}],
34+
pulls: []
35+
}
36+
}]
37+
await comment.afterValidate(context, settings, result)
38+
expect(context.github.issues.createComment.mock.calls.length).toBe(3)
39+
})
40+
41+
const createMockContext = () => {
42+
let context = Helper.mockContext()
43+
44+
context.github.issues.createComment = jest.fn()
45+
return context
46+
}

0 commit comments

Comments
 (0)