generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First cut. Logs but does not comment
- Loading branch information
1 parent
a4557cb
commit fa0177a
Showing
10 changed files
with
10,068 additions
and
3,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,91 @@ | ||
import {wait} from '../src/wait' | ||
import * as process from 'process' | ||
import * as cp from 'child_process' | ||
import * as path from 'path' | ||
import {getFileOwners, parseCodeOwnersContent} from '../src/main' | ||
|
||
test('throws invalid number', async () => { | ||
const input = parseInt('foo', 10) | ||
await expect(wait(input)).rejects.toThrow('milliseconds not a number') | ||
}) | ||
describe('parseCodeOwnersContent', () => { | ||
const tests = [ | ||
{ | ||
name: 'single line', | ||
content: '/foo @nikclayton', | ||
want: [{path: '/foo', owners: ['@nikclayton']}] | ||
}, | ||
{ | ||
name: 'comment', | ||
content: `# This is a comment | ||
/foo @nikclayton`, | ||
want: [{path: '/foo', owners: ['@nikclayton']}] | ||
}, | ||
{ | ||
name: 'multiple owners', | ||
content: '/foo @bar @baz', | ||
want: [{path: '/foo', owners: ['@bar', '@baz']}] | ||
} | ||
] | ||
|
||
test('wait 500 ms', async () => { | ||
const start = new Date() | ||
await wait(500) | ||
const end = new Date() | ||
var delta = Math.abs(end.getTime() - start.getTime()) | ||
expect(delta).toBeGreaterThan(450) | ||
for (const t of tests) { | ||
test(t.name, () => { | ||
const got = parseCodeOwnersContent(t.content) | ||
expect(got).toEqual(t.want) | ||
}) | ||
} | ||
}) | ||
|
||
// shows how the runner will run a javascript action with env / stdout protocol | ||
test('test runs', () => { | ||
process.env['INPUT_MILLISECONDS'] = '500' | ||
const np = process.execPath | ||
const ip = path.join(__dirname, '..', 'lib', 'main.js') | ||
const options: cp.ExecFileSyncOptions = { | ||
env: process.env | ||
describe('getFileOwners', () => { | ||
const tests = [ | ||
{ | ||
name: 'single owner', | ||
content: '/foo @nikclayton', | ||
filename: 'foo', | ||
want: ['nikclayton'] | ||
}, | ||
{ | ||
name: 'multiple owners', | ||
content: '/foo @bar @baz', | ||
filename: 'foo', | ||
want: ['bar', 'baz'] | ||
}, | ||
{ | ||
name: 'last entry wins', | ||
content: `/foo @bar @baz | ||
/foo @fred`, | ||
filename: 'foo', | ||
want: ['fred'] | ||
}, | ||
{ | ||
name: 'file in any subdirectory matches', | ||
content: 'foo/ @bar', | ||
filename: '/foo/bar/baz', | ||
want: ['bar'] | ||
}, | ||
{ | ||
name: 'only immediate children are tested (1)', | ||
content: 'foo/*.txt @bar', | ||
filename: 'foo/test.txt', | ||
want: ['bar'] | ||
}, | ||
{ | ||
name: 'only immediate children are tested (2)', | ||
content: 'foo/*.txt @bar', | ||
filename: '/foo/bar/test.txt', | ||
want: [] | ||
}, | ||
{ | ||
name: 'file with no owners', | ||
content: '/foo @bar', | ||
filename: 'not-in-codeowners', | ||
want: [] | ||
}, | ||
{ | ||
name: '@ghost implies no owners', | ||
content: '/foo @ghost', | ||
filename: 'foo', | ||
want: [] | ||
} | ||
] | ||
|
||
for (const t of tests) { | ||
test(t.name, () => { | ||
const codeOwners = parseCodeOwnersContent(t.content) | ||
const owners = getFileOwners(codeOwners, t.filename) | ||
expect(owners).toEqual(t.want) | ||
}) | ||
} | ||
console.log(cp.execFileSync(np, [ip], options).toString()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
name: 'Your name here' | ||
description: 'Provide a description here' | ||
author: 'Your name or organization here' | ||
name: 'codeowners' | ||
description: 'Update PR with details of missing reviews' | ||
author: 'Nik Clayton' | ||
inputs: | ||
milliseconds: # change this | ||
token: | ||
required: true | ||
description: 'input description here' | ||
default: 'default value if applicable' | ||
description: 'Token to perform API calls' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Oops, something went wrong.