Skip to content

Commit fa0177a

Browse files
First cut. Logs but does not comment
1 parent a4557cb commit fa0177a

File tree

10 files changed

+10068
-3068
lines changed

10 files changed

+10068
-3068
lines changed

__tests__/main.test.ts

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,91 @@
1-
import {wait} from '../src/wait'
2-
import * as process from 'process'
3-
import * as cp from 'child_process'
4-
import * as path from 'path'
1+
import {getFileOwners, parseCodeOwnersContent} from '../src/main'
52

6-
test('throws invalid number', async () => {
7-
const input = parseInt('foo', 10)
8-
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
9-
})
3+
describe('parseCodeOwnersContent', () => {
4+
const tests = [
5+
{
6+
name: 'single line',
7+
content: '/foo @nikclayton',
8+
want: [{path: '/foo', owners: ['@nikclayton']}]
9+
},
10+
{
11+
name: 'comment',
12+
content: `# This is a comment
13+
/foo @nikclayton`,
14+
want: [{path: '/foo', owners: ['@nikclayton']}]
15+
},
16+
{
17+
name: 'multiple owners',
18+
content: '/foo @bar @baz',
19+
want: [{path: '/foo', owners: ['@bar', '@baz']}]
20+
}
21+
]
1022

11-
test('wait 500 ms', async () => {
12-
const start = new Date()
13-
await wait(500)
14-
const end = new Date()
15-
var delta = Math.abs(end.getTime() - start.getTime())
16-
expect(delta).toBeGreaterThan(450)
23+
for (const t of tests) {
24+
test(t.name, () => {
25+
const got = parseCodeOwnersContent(t.content)
26+
expect(got).toEqual(t.want)
27+
})
28+
}
1729
})
1830

19-
// shows how the runner will run a javascript action with env / stdout protocol
20-
test('test runs', () => {
21-
process.env['INPUT_MILLISECONDS'] = '500'
22-
const np = process.execPath
23-
const ip = path.join(__dirname, '..', 'lib', 'main.js')
24-
const options: cp.ExecFileSyncOptions = {
25-
env: process.env
31+
describe('getFileOwners', () => {
32+
const tests = [
33+
{
34+
name: 'single owner',
35+
content: '/foo @nikclayton',
36+
filename: 'foo',
37+
want: ['nikclayton']
38+
},
39+
{
40+
name: 'multiple owners',
41+
content: '/foo @bar @baz',
42+
filename: 'foo',
43+
want: ['bar', 'baz']
44+
},
45+
{
46+
name: 'last entry wins',
47+
content: `/foo @bar @baz
48+
/foo @fred`,
49+
filename: 'foo',
50+
want: ['fred']
51+
},
52+
{
53+
name: 'file in any subdirectory matches',
54+
content: 'foo/ @bar',
55+
filename: '/foo/bar/baz',
56+
want: ['bar']
57+
},
58+
{
59+
name: 'only immediate children are tested (1)',
60+
content: 'foo/*.txt @bar',
61+
filename: 'foo/test.txt',
62+
want: ['bar']
63+
},
64+
{
65+
name: 'only immediate children are tested (2)',
66+
content: 'foo/*.txt @bar',
67+
filename: '/foo/bar/test.txt',
68+
want: []
69+
},
70+
{
71+
name: 'file with no owners',
72+
content: '/foo @bar',
73+
filename: 'not-in-codeowners',
74+
want: []
75+
},
76+
{
77+
name: '@ghost implies no owners',
78+
content: '/foo @ghost',
79+
filename: 'foo',
80+
want: []
81+
}
82+
]
83+
84+
for (const t of tests) {
85+
test(t.name, () => {
86+
const codeOwners = parseCodeOwnersContent(t.content)
87+
const owners = getFileOwners(codeOwners, t.filename)
88+
expect(owners).toEqual(t.want)
89+
})
2690
}
27-
console.log(cp.execFileSync(np, [ip], options).toString())
2891
})

action.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
name: 'Your name here'
2-
description: 'Provide a description here'
3-
author: 'Your name or organization here'
1+
name: 'codeowners'
2+
description: 'Update PR with details of missing reviews'
3+
author: 'Nik Clayton'
44
inputs:
5-
milliseconds: # change this
5+
token:
66
required: true
7-
description: 'input description here'
8-
default: 'default value if applicable'
7+
description: 'Token to perform API calls'
98
runs:
109
using: 'node12'
1110
main: 'dist/index.js'

0 commit comments

Comments
 (0)