From 71b674643f1c9b398a66fb5e6b550c4d48999001 Mon Sep 17 00:00:00 2001 From: Dmitry Gurovich Date: Sun, 7 Jul 2024 18:03:25 +0300 Subject: [PATCH] v2.1.0 add codewatchers_ref config option --- .editorconfig | 2 +- CONTRIBUTING.md | 1 + README.md | 16 +++++++++------- action.yaml | 3 +++ dist/index.js | 12 +++++++----- package-lock.json | 4 ++-- package.json | 2 +- src/codewatchers.ts | 8 ++++---- src/index.ts | 4 +++- src/types.ts | 1 + 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.editorconfig b/.editorconfig index 69ed2aa..f579a0a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = false -[*.{json,yml,yaml}] +[*.{json,yml,yaml,md}] indent_style = space indent_size = 2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index de175e0..1686305 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,7 @@ GITHUB_ACTION='.' INPUT_SHA_FROM= INPUT_SHA_TO= INPUT_CODEWATCHERS=".github/CODEWATCHERS" +INPUT_CODEWATCHERS_REF="main" INPUT_IGNORE_OWN=false ``` diff --git a/README.md b/README.md index 961cba4..6ac3727 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Subscriptions are managed in a [CODEOWNERS](https://docs.github.com/en/repositor ### Inputs * `GITHUB_TOKEN` (required) - token for interaction with GitHub API, standard GITHUB_TOKEN secret provided to each workflow is good enough * `codewatchers` (optional) - location of the subscriptions file, default is ".github/CODEWATCHERS" +* `codewatchers_ref` (optional) - the ref to use when loading the CODEWATCHERS file, default is github.ref * `ignore_own` (optional) - toggles if committer will get notifications for own commits (boolean, default is "true") * `sha_from` and `sha_to` (required) - commits range to analize. Usually these are taken from the [push](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push) event (see example below) * `aggregate_files_limit` (optional) - Limit after which files list will be replaced with aggregated summary message. (integer, default is 20) @@ -26,13 +27,14 @@ jobs: id: check uses: yrtimiD/github-codewatchers@v1 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - codewatchers: '.github/CODEWATCHERS' - ignore_own: true - sha_from: ${{ github.event.before }} - sha_to: ${{ github.event.after }} - aggregate_files_limit: 20 - aggregate_notifications_limit: 5 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + codewatchers: '.github/CODEWATCHERS' + codewatchers_ref: 'main' + ignore_own: true + sha_from: ${{ github.event.before }} + sha_to: ${{ github.event.after }} + aggregate_files_limit: 20 + aggregate_notifications_limit: 5 outputs: notifications: ${{ steps.check.outputs.notifications }} ``` diff --git a/action.yaml b/action.yaml index 3cb50bf..eb91b36 100644 --- a/action.yaml +++ b/action.yaml @@ -15,6 +15,9 @@ inputs: description: 'Location of the CODEWATCHERS file' required: false default: '.github/CODEWATCHERS' + codewatchers_ref: + description: 'The ref to use when loading the CODEWATCHERS file. (using github.ref by default)' + required: false ignore_own: description: 'Prevents notifications for own commits' required: false diff --git a/dist/index.js b/dist/index.js index 5e9c780..540b107 100644 --- a/dist/index.js +++ b/dist/index.js @@ -52235,13 +52235,13 @@ const core = __importStar(__nccwpck_require__(2186)); const ignore_1 = __importDefault(__nccwpck_require__(1230)); function loadCodewatchers(context, options) { return __awaiter(this, void 0, void 0, function* () { - let { octokit, owner, repo, ref } = context; - let { codewatchers } = options; + let { octokit, owner, repo } = context; + let { codewatchers, codewatchersRef } = options; let CW = []; let file; - core.info(`Loading "${codewatchers}" file from ${ref}...`); + core.info(`Loading "${codewatchers}" file from ${codewatchersRef}...`); try { - let { data } = yield octokit.rest.repos.getContent({ owner, repo, ref, path: codewatchers, mediaType: { format: 'raw' } }); + let { data } = yield octokit.rest.repos.getContent({ owner, repo, ref: codewatchersRef, path: codewatchers, mediaType: { format: 'raw' } }); if (typeof data === 'string') { file = data; core.debug(file); @@ -52365,10 +52365,12 @@ function main() { let shaFrom = core.getInput('sha_from', { required: true }); let shaTo = core.getInput('sha_to', { required: true }); let codewatchers = core.getInput('codewatchers', { required: true }); + let codewatchersRef = core.getInput('codewatchers_ref', { required: false }) || context.ref; let ignoreOwn = core.getBooleanInput('ignore_own', { required: true }); let aggregateFilesLimit = Number.parseInt(core.getInput('aggregate_files_limit', { required: false }), 10) || 20; let aggregateNotificationsLimit = Number.parseInt(core.getInput('aggregate_notifications_limit', { required: false }), 10) || 5; - let options = { shaFrom, shaTo, codewatchers, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit }; + let options = { shaFrom, shaTo, codewatchers, codewatchersRef, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit }; + core.debug(JSON.stringify({ options }, null, 2)); let notifications = yield (0, match_1.check)(context, options); notifications = (0, match_1.aggregateCommits)(context, options, notifications); notifications = (0, match_1.aggregateFiles)(context, options, notifications); diff --git a/package-lock.json b/package-lock.json index 375b356..28003bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-codewatchers", - "version": "1.0.0", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-codewatchers", - "version": "1.0.0", + "version": "2.1.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 0b1b986..816c701 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-codewatchers", - "version": "2.0.0", + "version": "2.1.0", "description": "GitHub Action that triggers notifications about changed files to a list of subscribers", "main": "dist/index.js", "scripts": { diff --git a/src/codewatchers.ts b/src/codewatchers.ts index bba04fe..ab37f6b 100644 --- a/src/codewatchers.ts +++ b/src/codewatchers.ts @@ -5,14 +5,14 @@ import ignore from 'ignore'; export async function loadCodewatchers(context: Context, options: Options): Promise { - let { octokit, owner, repo, ref } = context; - let { codewatchers } = options; + let { octokit, owner, repo } = context; + let { codewatchers, codewatchersRef } = options; let CW: Notif.CodeWatchers[] = []; let file: string; - core.info(`Loading "${codewatchers}" file from ${ref}...`); + core.info(`Loading "${codewatchers}" file from ${codewatchersRef}...`); try { - let { data } = await octokit.rest.repos.getContent({ owner, repo, ref, path: codewatchers, mediaType: { format: 'raw' } }); + let { data } = await octokit.rest.repos.getContent({ owner, repo, ref: codewatchersRef, path: codewatchers, mediaType: { format: 'raw' } }); if (typeof data === 'string') { file = data; core.debug(file); diff --git a/src/index.ts b/src/index.ts index 91d9650..4cb93c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,10 +17,12 @@ export async function main(): Promise { let shaFrom = core.getInput('sha_from', { required: true }); let shaTo = core.getInput('sha_to', { required: true }); let codewatchers = core.getInput('codewatchers', { required: true }); + let codewatchersRef = core.getInput('codewatchers_ref', { required: false }) || context.ref; let ignoreOwn = core.getBooleanInput('ignore_own', { required: true }); let aggregateFilesLimit = Number.parseInt(core.getInput('aggregate_files_limit', { required: false }), 10) || 20; let aggregateNotificationsLimit = Number.parseInt(core.getInput('aggregate_notifications_limit', { required: false }), 10) || 5; - let options: Options = { shaFrom, shaTo, codewatchers, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit }; + let options: Options = { shaFrom, shaTo, codewatchers, codewatchersRef, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit }; + core.debug(JSON.stringify({ options }, null, 2)); let notifications = await check(context, options); notifications = aggregateCommits(context, options, notifications); diff --git a/src/types.ts b/src/types.ts index 09c9f59..8056fe9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,6 +13,7 @@ export type Context = { export type Options = { codewatchers: string, + codewatchersRef: string, shaFrom: string, shaTo: string, ignoreOwn: boolean,