generated from actions/container-toolkit-action
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from Renato66/feat/json-config
Feat/json config
- Loading branch information
Showing
20 changed files
with
324 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
labelsSynonyms: { | ||
bug: ['error', 'need fix', 'not working'], | ||
enhancement: ['upgrade'], | ||
question: ['help', 'how can i'] | ||
}, | ||
labelsNotAllowed: [ | ||
'documentation', | ||
'duplicate', | ||
'good first issue', | ||
'help wanted', | ||
'invalid' | ||
], | ||
defaultLabels: ['triage'] | ||
} |
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,20 @@ | ||
name: Labeling new issue | ||
|
||
on: | ||
issues: | ||
types: ['opened'] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
.github/workflows/ | ||
# .github/workflows/auto-label.json5 | ||
# .github/workflows/auto-label.jsonc | ||
# .github/workflows/auto-label.json | ||
sparse-checkout-cone-mode: false | ||
- uses: Renato66/auto-label@main | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} |
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,2 @@ | ||
src/__mock__/config/invalid/invalid3.json | ||
readme.md |
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,8 @@ | ||
{ | ||
"labelsSynonyms": { | ||
"bug": ["error"] | ||
}, | ||
"labelsNotAllowed": ["documentation"], | ||
"defaultLabels": ["triage"], | ||
"ignoreComments": true | ||
} |
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,13 @@ | ||
{ | ||
// comment test | ||
labelsSynonyms: { | ||
bug: [ | ||
'error' | ||
// trailing comma | ||
] | ||
}, | ||
// single quote | ||
labelsNotAllowed: ['documentation'], | ||
defaultLabels: ['triage'], | ||
ignoreComments: true | ||
} |
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,9 @@ | ||
{ | ||
// comment test | ||
"labelsSynonyms": { | ||
"bug": ["error"] | ||
}, | ||
"labelsNotAllowed": ["documentation"], | ||
"defaultLabels": ["triage"], | ||
"ignoreComments": true | ||
} |
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 @@ | ||
{} |
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,6 @@ | ||
{ | ||
"labels-synonyms": "expected: Record<string, string[]>", | ||
"labels-not-allowed": "expected: string[]", | ||
"default-labels": "expected: string[]", | ||
"ignoreComments": "expected: boolean" | ||
} |
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 @@ | ||
"invalid json" |
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 @@ | ||
not-valid-json |
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 @@ | ||
{ | ||
"labelsSynonyms": { | ||
"bug": ["error"] | ||
}, | ||
"labelsNotAllowed": ["documentation"], | ||
"defaultLabels": ["triage"], | ||
"ignoreComments": true | ||
} |
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 |
---|---|---|
@@ -1,18 +1,32 @@ | ||
import { getInput } from './getInput' | ||
import { getLabelConfigs } from './getLabelConfigs' | ||
|
||
export const getConfigFile = () => { | ||
export type Config = { | ||
labelsNotAllowed: string[] | ||
defaultLabels: string[] | ||
labelsSynonyms: Record<string, string[]> | ||
ignoreComments: boolean | ||
} | ||
|
||
export const getConfigFile = (): Config => { | ||
const configPath = getInput<string>( | ||
'configuration-file', | ||
'.github/workflows/' | ||
) | ||
const labelsNotAllowed = getInput<string[]>('labels-not-allowed', []) | ||
const defaultLabels = getInput<string[]>('default-labels', []) | ||
const labelsSynonyms = getInput<Record<string, string[]>>( | ||
'labels-synonyms', | ||
{} | ||
) | ||
const ignoreComments = getInput('ignore-comments', true) | ||
const config = getLabelConfigs(configPath) | ||
|
||
return { | ||
labelsNotAllowed, | ||
defaultLabels, | ||
labelsSynonyms, | ||
ignoreComments | ||
ignoreComments, | ||
...config | ||
} | ||
} |
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,52 @@ | ||
import { expect, describe, test, mock, jest } from 'bun:test' | ||
import { getLabelConfigs } from './getLabelConfigs' | ||
import * as core from '@actions/core' | ||
|
||
const configurationPath = 'src/__mock__/config' | ||
const defaultConfig = { | ||
labelsSynonyms: { | ||
bug: ['error'] | ||
}, | ||
labelsNotAllowed: ['documentation'], | ||
defaultLabels: ['triage'], | ||
ignoreComments: true | ||
} | ||
describe('getLabelConfigs', () => { | ||
test('should return label configurations from a valid JSON folder path', () => { | ||
const options = [`${configurationPath}/`, `${configurationPath}`] | ||
options.forEach((elem) => { | ||
const result = getLabelConfigs(elem) | ||
expect(result).toEqual(defaultConfig) | ||
}) | ||
}) | ||
|
||
test('should return label configurations from a valid JSONC file path', () => { | ||
const result = getLabelConfigs(`${configurationPath}/auto-label.jsonc`) | ||
expect(result).toEqual(defaultConfig) | ||
}) | ||
|
||
test('should return label configurations from a valid JSON5 file path', () => { | ||
const result = getLabelConfigs(`${configurationPath}/auto-label.json5`) | ||
expect(result).toEqual(defaultConfig) | ||
}) | ||
|
||
test('should return an empty object if the configuration file is not valid', () => { | ||
const options = [ | ||
`${configurationPath}/invalid/invalid1.json`, | ||
`${configurationPath}/invalid/invalid2.json` | ||
] | ||
options.forEach((elem) => { | ||
const result = getLabelConfigs(elem) | ||
expect(result).toEqual({}) | ||
}) | ||
}) | ||
|
||
test('should send an warning if file is not readable', () => { | ||
mock.module('@actions/core', () => ({ | ||
warning: jest.fn() | ||
})) | ||
const result = getLabelConfigs(`${configurationPath}/invalid/invalid3.json`) | ||
expect(result).toEqual({}) | ||
mock.module('@actions/core', () => core) | ||
}) | ||
}) |
Oops, something went wrong.