Skip to content

Commit 71b6746

Browse files
authored
v2.1.0 add codewatchers_ref config option
1 parent 0ce0df8 commit 71b6746

File tree

10 files changed

+32
-21
lines changed

10 files changed

+32
-21
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ charset = utf-8
1111
trim_trailing_whitespace = true
1212
insert_final_newline = false
1313

14-
[*.{json,yml,yaml}]
14+
[*.{json,yml,yaml,md}]
1515
indent_style = space
1616
indent_size = 2

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GITHUB_ACTION='.'
1010
INPUT_SHA_FROM=<FROM COMMIT>
1111
INPUT_SHA_TO=<TO COMMIT>
1212
INPUT_CODEWATCHERS=".github/CODEWATCHERS"
13+
INPUT_CODEWATCHERS_REF="main"
1314
INPUT_IGNORE_OWN=false
1415
```
1516

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Subscriptions are managed in a [CODEOWNERS](https://docs.github.com/en/repositor
88
### Inputs
99
* `GITHUB_TOKEN` (required) - token for interaction with GitHub API, standard GITHUB_TOKEN secret provided to each workflow is good enough
1010
* `codewatchers` (optional) - location of the subscriptions file, default is ".github/CODEWATCHERS"
11+
* `codewatchers_ref` (optional) - the ref to use when loading the CODEWATCHERS file, default is github.ref
1112
* `ignore_own` (optional) - toggles if committer will get notifications for own commits (boolean, default is "true")
1213
* `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)
1314
* `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:
2627
id: check
2728
uses: yrtimiD/github-codewatchers@v1
2829
with:
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30-
codewatchers: '.github/CODEWATCHERS'
31-
ignore_own: true
32-
sha_from: ${{ github.event.before }}
33-
sha_to: ${{ github.event.after }}
34-
aggregate_files_limit: 20
35-
aggregate_notifications_limit: 5
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
codewatchers: '.github/CODEWATCHERS'
32+
codewatchers_ref: 'main'
33+
ignore_own: true
34+
sha_from: ${{ github.event.before }}
35+
sha_to: ${{ github.event.after }}
36+
aggregate_files_limit: 20
37+
aggregate_notifications_limit: 5
3638
outputs:
3739
notifications: ${{ steps.check.outputs.notifications }}
3840
```

action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ inputs:
1515
description: 'Location of the CODEWATCHERS file'
1616
required: false
1717
default: '.github/CODEWATCHERS'
18+
codewatchers_ref:
19+
description: 'The ref to use when loading the CODEWATCHERS file. (using github.ref by default)'
20+
required: false
1821
ignore_own:
1922
description: 'Prevents notifications for own commits'
2023
required: false

dist/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52235,13 +52235,13 @@ const core = __importStar(__nccwpck_require__(2186));
5223552235
const ignore_1 = __importDefault(__nccwpck_require__(1230));
5223652236
function loadCodewatchers(context, options) {
5223752237
return __awaiter(this, void 0, void 0, function* () {
52238-
let { octokit, owner, repo, ref } = context;
52239-
let { codewatchers } = options;
52238+
let { octokit, owner, repo } = context;
52239+
let { codewatchers, codewatchersRef } = options;
5224052240
let CW = [];
5224152241
let file;
52242-
core.info(`Loading "${codewatchers}" file from ${ref}...`);
52242+
core.info(`Loading "${codewatchers}" file from ${codewatchersRef}...`);
5224352243
try {
52244-
let { data } = yield octokit.rest.repos.getContent({ owner, repo, ref, path: codewatchers, mediaType: { format: 'raw' } });
52244+
let { data } = yield octokit.rest.repos.getContent({ owner, repo, ref: codewatchersRef, path: codewatchers, mediaType: { format: 'raw' } });
5224552245
if (typeof data === 'string') {
5224652246
file = data;
5224752247
core.debug(file);
@@ -52365,10 +52365,12 @@ function main() {
5236552365
let shaFrom = core.getInput('sha_from', { required: true });
5236652366
let shaTo = core.getInput('sha_to', { required: true });
5236752367
let codewatchers = core.getInput('codewatchers', { required: true });
52368+
let codewatchersRef = core.getInput('codewatchers_ref', { required: false }) || context.ref;
5236852369
let ignoreOwn = core.getBooleanInput('ignore_own', { required: true });
5236952370
let aggregateFilesLimit = Number.parseInt(core.getInput('aggregate_files_limit', { required: false }), 10) || 20;
5237052371
let aggregateNotificationsLimit = Number.parseInt(core.getInput('aggregate_notifications_limit', { required: false }), 10) || 5;
52371-
let options = { shaFrom, shaTo, codewatchers, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit };
52372+
let options = { shaFrom, shaTo, codewatchers, codewatchersRef, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit };
52373+
core.debug(JSON.stringify({ options }, null, 2));
5237252374
let notifications = yield (0, match_1.check)(context, options);
5237352375
notifications = (0, match_1.aggregateCommits)(context, options, notifications);
5237452376
notifications = (0, match_1.aggregateFiles)(context, options, notifications);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-codewatchers",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "GitHub Action that triggers notifications about changed files to a list of subscribers",
55
"main": "dist/index.js",
66
"scripts": {

src/codewatchers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import ignore from 'ignore';
55

66

77
export async function loadCodewatchers(context: Context, options: Options): Promise<Notif.CodeWatchers[]> {
8-
let { octokit, owner, repo, ref } = context;
9-
let { codewatchers } = options;
8+
let { octokit, owner, repo } = context;
9+
let { codewatchers, codewatchersRef } = options;
1010

1111
let CW: Notif.CodeWatchers[] = [];
1212
let file: string;
13-
core.info(`Loading "${codewatchers}" file from ${ref}...`);
13+
core.info(`Loading "${codewatchers}" file from ${codewatchersRef}...`);
1414
try {
15-
let { data } = await octokit.rest.repos.getContent({ owner, repo, ref, path: codewatchers, mediaType: { format: 'raw' } });
15+
let { data } = await octokit.rest.repos.getContent({ owner, repo, ref: codewatchersRef, path: codewatchers, mediaType: { format: 'raw' } });
1616
if (typeof data === 'string') {
1717
file = data;
1818
core.debug(file);

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export async function main(): Promise<void> {
1717
let shaFrom = core.getInput('sha_from', { required: true });
1818
let shaTo = core.getInput('sha_to', { required: true });
1919
let codewatchers = core.getInput('codewatchers', { required: true });
20+
let codewatchersRef = core.getInput('codewatchers_ref', { required: false }) || context.ref;
2021
let ignoreOwn = core.getBooleanInput('ignore_own', { required: true });
2122
let aggregateFilesLimit = Number.parseInt(core.getInput('aggregate_files_limit', { required: false }), 10) || 20;
2223
let aggregateNotificationsLimit = Number.parseInt(core.getInput('aggregate_notifications_limit', { required: false }), 10) || 5;
23-
let options: Options = { shaFrom, shaTo, codewatchers, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit };
24+
let options: Options = { shaFrom, shaTo, codewatchers, codewatchersRef, ignoreOwn, aggregateFilesLimit, aggregateNotificationsLimit };
25+
core.debug(JSON.stringify({ options }, null, 2));
2426

2527
let notifications = await check(context, options);
2628
notifications = aggregateCommits(context, options, notifications);

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type Context = {
1313

1414
export type Options = {
1515
codewatchers: string,
16+
codewatchersRef: string,
1617
shaFrom: string,
1718
shaTo: string,
1819
ignoreOwn: boolean,

0 commit comments

Comments
 (0)