-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge branch 'feature/generate-issue' into develop
- Loading branch information
Showing
14 changed files
with
278 additions
and
22 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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import getConfig from '../src/getConfig' | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
import fetch from 'node-fetch' | ||
|
||
describe('getConfig', () => { | ||
test('getConfig returns a config from a JSON file', async () => { | ||
const filepath = path.resolve(__dirname, 'testconfig.json') | ||
const expected = JSON.parse(await fs.promises.readFile(filepath, 'utf8')) | ||
const res = await getConfig({configFile: filepath}) | ||
|
||
expect(res).toMatchObject(expected) | ||
}) | ||
|
||
test('getConfig returns a config from a URL', async () => { | ||
// TODO: change this to point to the new relic repo when it goes public | ||
const url = | ||
'https://raw.githubusercontent.com/aperture-science-incorporated/.github/master/repolinter.json' | ||
const expected = await (await fetch(url)).json() | ||
const res = await getConfig({configUrl: url}) | ||
|
||
expect(res).toMatchObject(expected) | ||
}) | ||
|
||
test('getConfig fails with an invalid file', async () => { | ||
const filepath = 'notafile' | ||
|
||
expect(async () => getConfig({configFile: filepath})).rejects.toThrowError() | ||
}) | ||
|
||
test('getConfig failed with an invalid url', async () => { | ||
const url = 'notadomain' | ||
|
||
expect(async () => getConfig({configUrl: url})).rejects.toThrowError() | ||
}) | ||
|
||
test('getConfig fails with an invalid json structure', async () => { | ||
const filepath = path.resolve(__dirname, 'invalidtestconfig.json') | ||
|
||
expect(async () => getConfig({configFile: filepath})).rejects.toThrowError() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/prototypicalpro/repolinter/master/rulesets/schema.json", | ||
"version": 2, | ||
"the-axioms": { | ||
"linguist":"language", | ||
"licensee":"license", | ||
"packagers":"packager" | ||
}, | ||
"the-rules": { | ||
"code-of-conduct-file-up-to-date": { | ||
"level": "error", | ||
"rule": { | ||
"type": "file-hash", | ||
"options": { | ||
"globsAny": [ | ||
"{docs/,.github/,}CODEOFCONDUCT*", | ||
"{docs/,.github/,}CODE-OF-CONDUCT*", | ||
"{docs/,.github/,}CODE_OF_CONDUCT*" | ||
], | ||
"nocase": true, | ||
"hash": "c0b76cd474db37b060a909aba86a85f60381bbdd46ce1575dde2f6e86e319c63" | ||
} | ||
}, | ||
"fix": { | ||
"type": "file-create", | ||
"options": { | ||
"file": "CODE_OF_CONDUCT.md", | ||
"replace": true, | ||
"text": { "url": "https://raw.githubusercontent.com/aperture-science-incorporated/.github/master/CODE_OF_CONDUCT.md" } | ||
} | ||
} | ||
}, | ||
"community-header-present": { | ||
"level": "error", | ||
"rule": { | ||
"type": "file-starts-with", | ||
"options": { | ||
"globsAll": ["README*"], | ||
"nocase": true, | ||
"lineCount": 1, | ||
"patterns": ["\\[\\s*\\!\\[[a-z0-9\\s]+\\]\\(\\s*[\\/\\.a-z0-9\\-\\_\\~:]+\\s*\\)\\s*]\\(\\s*https:\\/\\/opensource\\.newrelic\\.com\\/oss-category\\/#([\\/\\.a-z0-9\\-\\_\\~]+)\\s*\\)"], | ||
"human-readable-pattern": "Open source category header (see https://opensource.newrelic.com/oss-category)", | ||
"flags": "i", | ||
"succeed-on-non-existent": false | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/prototypicalpro/repolinter/master/rulesets/schema.json", | ||
"version": 2, | ||
"axioms": { | ||
"linguist":"language", | ||
"licensee":"license", | ||
"packagers":"packager" | ||
}, | ||
"rules": { | ||
"code-of-conduct-file-up-to-date": { | ||
"level": "error", | ||
"rule": { | ||
"type": "file-hash", | ||
"options": { | ||
"globsAny": [ | ||
"{docs/,.github/,}CODEOFCONDUCT*", | ||
"{docs/,.github/,}CODE-OF-CONDUCT*", | ||
"{docs/,.github/,}CODE_OF_CONDUCT*" | ||
], | ||
"nocase": true, | ||
"hash": "c0b76cd474db37b060a909aba86a85f60381bbdd46ce1575dde2f6e86e319c63" | ||
} | ||
}, | ||
"fix": { | ||
"type": "file-create", | ||
"options": { | ||
"file": "CODE_OF_CONDUCT.md", | ||
"replace": true, | ||
"text": { "url": "https://raw.githubusercontent.com/aperture-science-incorporated/.github/master/CODE_OF_CONDUCT.md" } | ||
} | ||
} | ||
}, | ||
"community-header-present": { | ||
"level": "error", | ||
"rule": { | ||
"type": "file-starts-with", | ||
"options": { | ||
"globsAll": ["README*"], | ||
"nocase": true, | ||
"lineCount": 1, | ||
"patterns": ["\\[\\s*\\!\\[[a-z0-9\\s]+\\]\\(\\s*[\\/\\.a-z0-9\\-\\_\\~:]+\\s*\\)\\s*]\\(\\s*https:\\/\\/opensource\\.newrelic\\.com\\/oss-category\\/#([\\/\\.a-z0-9\\-\\_\\~]+)\\s*\\)"], | ||
"human-readable-pattern": "Open source category header (see https://opensource.newrelic.com/oss-category)", | ||
"flags": "i", | ||
"succeed-on-non-existent": false | ||
} | ||
} | ||
} | ||
} | ||
} |
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,13 @@ | ||
name: 'Repolinter Action' | ||
description: 'Provide a description here' | ||
description: 'Runs Repolinter against a repository, then uses the results to open an issue.' | ||
author: 'New Relic Opensource' | ||
inputs: | ||
milliseconds: # change this | ||
required: true | ||
description: 'input description here' | ||
default: 'default value if applicable' | ||
config-file: # change this | ||
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.' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ module.exports = { | |
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
verbose: true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import fetch from 'node-fetch' | ||
import * as fs from 'fs' | ||
import * as core from '@actions/core' | ||
import {validateConfig} from 'repolinter' | ||
|
||
/** | ||
* Load a repolinter configuration from either a file or URL, | ||
* return the validated deserialized configuration. | ||
* @param where.configFile The file path to the config, relative to the current working directory. Mutually exclusive with where.configUrl. | ||
* @param where.configUrl The URL to load fhe config from. Mutually exclusive with where.configFile | ||
* @returns A deserialized JSON configuration object if one was found. If the configuration does not exist or does not pass validation this function will throw an error. | ||
*/ | ||
export default async function getConfig(where: { | ||
configFile?: string | ||
configUrl?: string | ||
}): Promise<object | null> { | ||
// get the config file contents | ||
let contents | ||
if (where.configFile) { | ||
core.debug(`Reading config file ${where.configFile}`) | ||
// read the file | ||
try { | ||
contents = await fs.promises.readFile(where.configFile, 'utf8') | ||
} catch { | ||
throw new Error(`Unable to open file ${where.configFile}`) | ||
} | ||
} else if (where.configUrl) { | ||
core.debug(`Reading config url ${where.configUrl}`) | ||
// fetch the data from the URL | ||
try { | ||
const res = await fetch(where.configUrl) | ||
if (!res.ok) { | ||
throw new Error( | ||
`Failed to fetch from ${where.configUrl} with status code ${res.status} (${res.statusText})` | ||
) | ||
} | ||
contents = await res.text() | ||
} catch (e) { | ||
throw new Error( | ||
`Got error when retrieving data from ${ | ||
where.configUrl | ||
}: ${e.toString()}` | ||
) | ||
} | ||
} | ||
// if neither parameters are present, return null | ||
else { | ||
core.debug('Using default config') | ||
return null | ||
} | ||
// parse it | ||
let ret | ||
try { | ||
ret = JSON.parse(contents) | ||
} catch (e) { | ||
throw new Error( | ||
`Unable to parse JSON from file ${ | ||
where.configFile | ||
} with error ${e.toString()}` | ||
) | ||
} | ||
// validate the config using repolinters validator | ||
const validationResult = await validateConfig(ret) | ||
if (!validationResult.passed) { | ||
throw new Error( | ||
`Configuration validation failed with error ${validationResult.error}` | ||
) | ||
} | ||
return ret | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "." | ||
}, | ||
"include": ["src/**/*.ts", "__tests__/**/*.ts"], | ||
"exclude": [] | ||
} |