Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 8 additions & 42 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"plugin:@typescript-eslint/eslint-recommended"
],
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"import"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -30,29 +31,6 @@
"properties": "always"
}
],
"require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}
],
"valid-jsdoc": [
"error",
{
"requireReturn": false,
"preferType": {
"String": "string",
"Object": "object",
"Number": "number",
"Function": "function",
"Void": "void"
}
}
],
"quotes": [
"error",
"single",
Expand All @@ -71,12 +49,6 @@
}
}
],
"no-magic-numbers": [
"error",
{
"ignoreArrayIndexes": true
}
],
"eqeqeq": "error",
"block-scoped-var": "error",
"complexity": [
Expand All @@ -85,7 +57,6 @@
"maximum": 20
}
],
"curly": "error",
"default-case": "error",
"dot-location": [
"error",
Expand All @@ -102,16 +73,6 @@
"after": true
}
],
"id-length": [
"error",
{
"min": 2,
"properties": "never",
"exceptions": [
"$"
]
}
],
"indent": [
"error",
2,
Expand Down Expand Up @@ -144,6 +105,11 @@
],
"semi": [
"error"
]
],
"sort-imports": 0,
"import/order": [2, {
"groups": ["type", "builtin", "external", "internal", "parent", "sibling", "index", "object"],
"alphabetize": { "order": "asc", "caseInsensitive": true }
}]
}
}
13 changes: 0 additions & 13 deletions jest.config.js

This file was deleted.

3 changes: 0 additions & 3 deletions jest.setup.ts

This file was deleted.

43 changes: 24 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-config-helper",
"version": "2.0.45",
"version": "2.1.0",
"description": "Helper for GitHub Action to manage config.",
"keywords": [
"github",
Expand All @@ -20,38 +20,43 @@
"email": "technote.space@gmail.com",
"url": "https://technote.space"
},
"main": "dist/index.js",
"type": "module",
"exports": "./dist/index.mjs",
"main": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"cover": "jest --coverage",
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
"test": "yarn lint && yarn cover",
"build": "tsc && rm -f dist/*.js && rollup -c",
"cover": "vitest run --coverage",
"lint": "eslint 'src/**/*.ts' --cache",
"lint:fix": "eslint --fix 'src/**/*.ts'",
"test": "yarn lint && yarn typecheck && yarn cover",
"typecheck": "tsc --noEmit",
"update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit"
},
"dependencies": {
"@actions/github": "^5.0.0",
"@actions/github": "^5.0.1",
"@octokit/plugin-rest-endpoint-methods": "^5.13.0",
"@technote-space/github-action-helper": "^5.2.27",
"@technote-space/github-action-helper": "^5.3.1",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@technote-space/github-action-test-helper": "^0.7.40",
"@types/jest": "^27.4.1",
"@rollup/plugin-typescript": "^8.3.2",
"@sindresorhus/tsconfig": "^2.0.0",
"@technote-space/github-action-test-helper": "^0.9.2",
"@types/js-yaml": "^4.0.5",
"@types/node": "^17.0.22",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.11.0",
"jest": "^27.5.1",
"jest-circus": "^27.5.1",
"@types/node": "^17.0.25",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"c8": "^7.11.0",
"eslint": "^8.13.0",
"eslint-plugin-import": "^2.26.0",
"nock": "^13.2.4",
"ts-jest": "^27.1.3",
"typescript": "^4.6.2"
"rollup": "^2.70.2",
"typescript": "^4.6.3",
"vitest": "^0.9.3"
},
"publishConfig": {
"access": "public"
Expand Down
12 changes: 12 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pluginTypescript from '@rollup/plugin-typescript';

export default {
input: 'src/index.ts',
output: {
file: 'dist/index.mjs',
format: 'es',
},
plugins: [
pluginTypescript(),
],
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, it } from 'vitest';
import { getConfig, parseConfig } from '.';

it('helper methods should be imported', () => {
expect(getConfig).not.toBeFalsy();
expect(parseConfig).not.toBeFalsy();
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {getConfig} from './utils';
export {parseConfig} from './misc';
export { getConfig } from './utils';
export { parseConfig } from './misc';
23 changes: 12 additions & 11 deletions __tests__/misc.test.ts → src/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-magic-numbers */
import {encodeContent, spyOnStdout, stdoutCalledWith, getLogStdout} from '@technote-space/github-action-test-helper';
import {parseConfig} from '../src';
import {isYaml, parseYamlConfig, parseJsonConfig} from '../src/misc';
import { encodeContent, spyOnStdout, stdoutCalledWith, getLogStdout } from '@technote-space/github-action-test-helper';
import { describe, expect, it } from 'vitest';
import { parseConfig } from '../src';
import { isYaml, parseYamlConfig, parseJsonConfig } from './misc';

describe('isYaml', () => {
it('should return true', () => {
Expand All @@ -20,8 +21,8 @@ describe('isYaml', () => {

describe('parseYamlConfig', () => {
it('should parse config', async() => {
expect(parseYamlConfig('a: b')).toEqual({a: 'b'});
expect(parseYamlConfig('a:\n - b\n - c')).toEqual({a: ['b', 'c']});
expect(parseYamlConfig('a: b')).toEqual({ a: 'b' });
expect(parseYamlConfig('a:\n - b\n - c')).toEqual({ a: ['b', 'c'] });
});

it('should return empty if empty', () => {
Expand Down Expand Up @@ -51,8 +52,8 @@ describe('parseYamlConfig', () => {

describe('parseJsonConfig', () => {
it('should parse config', async() => {
expect(parseJsonConfig('{"a": "b"}')).toEqual({a: 'b'});
expect(parseJsonConfig('{"a": ["b", "c"]}')).toEqual({a: ['b', 'c']});
expect(parseJsonConfig('{"a": "b"}')).toEqual({ a: 'b' });
expect(parseJsonConfig('{"a": ["b", "c"]}')).toEqual({ a: ['b', 'c'] });
});

it('should return empty if error', () => {
Expand All @@ -68,12 +69,12 @@ describe('parseJsonConfig', () => {

describe('parseConfig', () => {
it('should parse yaml', async() => {
expect(parseConfig(encodeContent('a: b'))).toEqual({a: 'b'});
expect(parseConfig(encodeContent('a: b'), 'test.yaml')).toEqual({a: 'b'});
expect(parseConfig(encodeContent('a: b'))).toEqual({ a: 'b' });
expect(parseConfig(encodeContent('a: b'), 'test.yaml')).toEqual({ a: 'b' });
});

it('should parse json', () => {
expect(parseConfig(encodeContent('{"a": "b"}'), 'test.json')).toEqual({a: 'b'});
expect(parseConfig(encodeContent('{"a": "b"}'), '.eslintrc')).toEqual({a: 'b'});
expect(parseConfig(encodeContent('{"a": "b"}'), 'test.json')).toEqual({ a: 'b' });
expect(parseConfig(encodeContent('{"a": "b"}'), '.eslintrc')).toEqual({ a: 'b' });
});
});
2 changes: 1 addition & 1 deletion src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {load} from 'js-yaml';
import { load } from 'js-yaml';

export const isYaml = (filename: string): boolean => ['yaml', 'yml'].includes(String(filename.split('.').pop()));

Expand Down
3 changes: 3 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { setupGlobal } from '@technote-space/github-action-test-helper';

setupGlobal();
11 changes: 6 additions & 5 deletions __tests__/utils.test.ts → src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-magic-numbers */
import { resolve } from 'path';
import { disableNetConnect, getConfigFixture, getContext, getOctokit } from '@technote-space/github-action-test-helper';
import nock from 'nock';
import {resolve} from 'path';
import {disableNetConnect, getConfigFixture, getContext, getOctokit} from '@technote-space/github-action-test-helper';
import {getConfig} from '../src';
import { describe, expect, it } from 'vitest';
import { getConfig } from './utils';

const fixturesDir = resolve(__dirname, 'fixtures');

Expand Down Expand Up @@ -38,7 +39,7 @@ describe('getConfig', () => {
owner: 'hello',
repo: 'world',
},
}), {ref: 'feature/change', configPath: ''});
}), { ref: 'feature/change', configPath: '' });

expect(config).toHaveProperty('Backlog');
expect(config['Backlog']).toHaveProperty('test1');
Expand Down Expand Up @@ -69,6 +70,6 @@ describe('getConfig', () => {
owner: 'hello',
repo: 'world',
},
}), {configPath: '.test'})).rejects.toThrow();
}), { configPath: '.test' })).rejects.toThrow();
});
});
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {join} from 'path';
import {Context} from '@actions/github/lib/context';
import {Octokit} from '@technote-space/github-action-helper/dist/types';
import {parseConfig} from './misc';
import {NOT_FOUND_STATUS} from './constant';
import type { Context } from '@actions/github/lib/context';
import type { Octokit } from '@technote-space/github-action-helper/dist/types';
import { join } from 'path';
import { NOT_FOUND_STATUS } from './constant';
import { parseConfig } from './misc';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getConfig = async(fileName: string, octokit: Octokit, context: Context, options: { configPath?: string; ref?: string } = {}): Promise<{ [key: string]: any } | false> | never => {
const {configPath = '.github', ref} = options;
const { configPath = '.github', ref } = options;
try {
const params: {
owner: string;
Expand Down
Loading