feat(config): support reading from local file if it exists (#394)

* feat(config): support reading from local file if it exists

Signed-off-by: Liam Stanley <me@liamstanley.io>

* fix: fix review point, update logic

* docs: update readme

* docs: update readme

* feat: add additional logging

* chore: update licenses

* docs: fix review point in readme.md

---------

Signed-off-by: Liam Stanley <me@liamstanley.io>
Co-authored-by: IvanZosimov <ivanzosimov@github.com>
This commit is contained in:
Liam Stanley
2023-07-07 06:44:54 -04:00
committed by GitHub
parent 327d35fdca
commit 994304c5d5
30 changed files with 1081 additions and 71 deletions

View File

@@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import * as pluginRetry from '@octokit/plugin-retry';
import * as yaml from 'js-yaml';
import fs from 'fs';
import {Minimatch} from 'minimatch';
interface MatchConfig {
@@ -159,7 +160,19 @@ async function getLabelGlobs(
): Promise<Map<string, StringOrMatchConfig[]>> {
let configurationContent: string;
try {
configurationContent = await fetchContent(client, configurationPath);
if (!fs.existsSync(configurationPath)) {
core.info(
`The configuration file (path: ${configurationPath}) isn't not found locally, fetching via the api`
);
configurationContent = await fetchContent(client, configurationPath);
} else {
core.info(
`The configuration file (path: ${configurationPath}) is found locally, reading from the file`
);
configurationContent = fs.readFileSync(configurationPath, {
encoding: 'utf8'
});
}
} catch (e: any) {
if (e.name == 'HttpError' || e.name == 'NotFound') {
core.warning(