Skip to content

Commit

Permalink
feat: add issue creation to action
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypicalpro committed Jul 30, 2020
2 parents 0fc573b + 9f29486 commit 3a728e3
Show file tree
Hide file tree
Showing 26 changed files with 2,570 additions and 3,366 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/test.yml

This file was deleted.

153 changes: 151 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,152 @@
test('runs tests', async () => {
expect(true).toBe(true)
import * as cp from 'child_process'
import * as path from 'path'
import {Inputs} from '../src/inputs'

async function execAsync(
command: string,
opts: cp.ExecOptions
): Promise<{out: string; err: string; code: number}> {
return new Promise((resolve, reject) => {
cp.exec(command, opts, (err, outstd, errstd) =>
err !== null && err.code === undefined
? reject(err)
: resolve({
out: outstd,
err: errstd,
code: err !== null ? (err.code as number) : 0
})
)
})
}

async function runAction(
env: NodeJS.ProcessEnv
): Promise<{out: string; err: string; code: number}> {
const ip = path.join(__dirname, '..', 'lib', 'main.js')
return execAsync(`node ${ip}`, {env})
}

function getInputName(input: string): string {
return `INPUT_${input.replace(/ /g, '_').toUpperCase()}`
}

describe('main', () => {
beforeEach(() => {
process.env[getInputName(Inputs.REPO)] = 'newrelic/repolinter-action'
process.env[getInputName(Inputs.OUTPUT_TYPE)] = 'off'
delete process.env[getInputName(Inputs.CONFIG_FILE)]
delete process.env[getInputName(Inputs.CONFIG_URL)]
})

test('throws when no token is supplied', async () => {
delete process.env[getInputName(Inputs.TOKEN)]

const {out, code} = await runAction(process.env)

// console.debug(out)
expect(code).not.toEqual(0)
expect(out).toContain(
`::error::Input required and not supplied: ${Inputs.TOKEN}`
)
})

test('throws when an invalid token is supplied and output-type is not off', async () => {
process.env[getInputName(Inputs.TOKEN)] = '2'
process.env[getInputName(Inputs.OUTPUT_TYPE)] = 'issue'

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain('Bad credentials')
// console.debug(out)
})

test('throws when no output-type is supplied', async () => {
delete process.env[getInputName(Inputs.OUTPUT_TYPE)]

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain(
`::error::Input required and not supplied: ${Inputs.OUTPUT_TYPE}`
)
})

test('throws when an invalid output-type is supplied', async () => {
process.env[getInputName(Inputs.OUTPUT_TYPE)] = 'string-cheese'

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain('string-cheese')
})

test('throws when no repository is supplied', async () => {
delete process.env[getInputName(Inputs.REPO)]

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain(
`::error::Input required and not supplied: ${Inputs.REPO}`
)
// console.debug(out)
})

test('throws when an invalid config-url is specified', async () => {
process.env[getInputName(Inputs.CONFIG_URL)] = 'notadomain'

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain('notadomain')
// console.debug(out)
})

test('throws when an invalid config-file is specified', async () => {
process.env[getInputName(Inputs.CONFIG_FILE)] = 'notafile'

const {out, code} = await runAction(process.env)

expect(code).not.toEqual(0)
expect(out).toContain('notafile')
// console.debug(out)
})

test('runs a test config', async () => {
process.env[getInputName(Inputs.CONFIG_FILE)] = path.resolve(
__dirname,
'testconfig.json'
)

const {out, code} = await runAction(process.env)

// console.debug(out)
expect(code).toEqual(0)
expect(out).toContain('testconfig.json')
expect(out).not.toContain('undefined')
})

test('runs a URL config', async () => {
process.env[getInputName(Inputs.CONFIG_URL)] =
'https://raw.githubusercontent.com/aperture-science-incorporated/.github/master/repolinter.json'

const {out, code} = await runAction(process.env)

// console.debug(out)
expect(code).toEqual(0)
expect(out).toContain(
'https://raw.githubusercontent.com/aperture-science-incorporated/.github/master/repolinter.json'
)
expect(out).not.toContain('undefined')
})

test('runs the default config', async () => {
const {out, code} = await runAction(process.env)

// console.debug(out)
expect(code).toEqual(0)
expect(out).toContain('default')
expect(out).not.toContain('undefined')
})
})
14 changes: 13 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ name: 'Repolinter Action'
description: 'Runs Repolinter against a repository, then uses the results to open an issue.'
author: 'New Relic Opensource'
inputs:
config-file: # change this
config-file:
required: false
description: 'The filename of the Repolinter configuration to use, relative to the repository this action is being run on. Mutually exclusive with configUrl.'
config-url:
required: false
description: 'The URL to pull the Repolinter configuration from. The URL must be publicly accessible. Mutually exclusive with configFile.'
token:
required: false
description: 'GitHub token to use when creating an issue on the current repository'
default: ${{ github.token }}
repository:
required: false
description: 'Repository name with owner. For example, actions/checkout'
default: ${{ github.repository }}
output-type:
required: false
description: 'Where to push the results from the Repolinter output. Can be "off" (console only) or "issue" (create a github issue).'
default: 'off'
runs:
using: 'node12'
main: 'dist/index.js'
30 changes: 15 additions & 15 deletions dist/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"rule": {
"type": "file-existence",
"options": {
"globsAny": ["LICENSE*", "COPYING*"],
"globsAny": ["LICENSE*", "COPYING*"],
"nocase": true
}
}
Expand Down Expand Up @@ -43,8 +43,8 @@
"type": "file-existence",
"options": {
"globsAny": [
"{docs/,.github/,}CODEOFCONDUCT*",
"{docs/,.github/,}CODE-OF-CONDUCT*",
"{docs/,.github/,}CODEOFCONDUCT*",
"{docs/,.github/,}CODE-OF-CONDUCT*",
"{docs/,.github/,}CODE_OF_CONDUCT*"
],
"nocase": true
Expand Down Expand Up @@ -116,13 +116,13 @@
"type": "file-existence",
"options": {
"globsAny": [
".gitlab-ci.yml",
".travis.yml",
"appveyor.yml",
".appveyor.yml",
"circle.yml",
".circleci/config.yml",
"Jenkinsfile",
".gitlab-ci.yml",
".travis.yml",
"appveyor.yml",
".appveyor.yml",
"circle.yml",
".circleci/config.yml",
"Jenkinsfile",
".drone.yml",
".github/workflows/*",
"azure-pipelines.yml"
Expand All @@ -136,18 +136,18 @@
"type": "file-contents",
"options": {
"globsAll": [
"CODEOFCONDUCT*",
"CODE-OF-CONDUCT*",
"CODEOFCONDUCT*",
"CODE-OF-CONDUCT*",
"CODE_OF_CONDUCT*",
".github/CODEOFCONDUCT*",
".github/CODE-OF-CONDUCT*",
".github/CODEOFCONDUCT*",
".github/CODE-OF-CONDUCT*",
".github/CODE_OF_CONDUCT*"
],
"content": ".+@.+\\..+",
"flags": "i",
"human-readable-content": "email address"
}
}
}
},
"source-license-headers-exist": {
"level": "warning",
Expand Down
45 changes: 18 additions & 27 deletions dist/fixes/file-create-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,26 @@
"$id": "https://raw.githubusercontent.com/prototypicalpro/repolinter/master/fixes/file-create-config.json",
"type": "object",
"properties": {
"type": { "const": "file-create" },
"options": {
"type": "object",
"additionalProperties": false,
"properties": {
"file": { "type": "string" },
"text": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"additionalProperties": false,
"properties": { "url": { "type": "string" } }
},
{
"type": "object",
"additionalProperties": false,
"properties": { "file": { "type": "string" } }
}
]
"file": { "type": "string" },
"text": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"additionalProperties": false,
"properties": { "url": { "type": "string" } }
},
"replace": {
"type": "boolean",
"default": false
{
"type": "object",
"additionalProperties": false,
"properties": { "file": { "type": "string" } }
}
},
"required": ["file", "text"]
]
},
"replace": {
"type": "boolean",
"default": false
}
},
"required": ["type", "options"],
"additionalProperties": false
"required": ["file", "text"]
}
Loading

0 comments on commit 3a728e3

Please sign in to comment.