Skip to content

Commit

Permalink
v2.1.0 add codewatchers_ref config option
Browse files Browse the repository at this point in the history
  • Loading branch information
yrtimiD authored Jul 7, 2024
1 parent 0ce0df8 commit 71b6746
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GITHUB_ACTION='.'
INPUT_SHA_FROM=<FROM COMMIT>
INPUT_SHA_TO=<TO COMMIT>
INPUT_CODEWATCHERS=".github/CODEWATCHERS"
INPUT_CODEWATCHERS_REF="main"
INPUT_IGNORE_OWN=false
```

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }}
```
Expand Down
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions src/codewatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ignore from 'ignore';


export async function loadCodewatchers(context: Context, options: Options): Promise<Notif.CodeWatchers[]> {
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);
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export async function main(): Promise<void> {
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);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Context = {

export type Options = {
codewatchers: string,
codewatchersRef: string,
shaFrom: string,
shaTo: string,
ignoreOwn: boolean,
Expand Down

0 comments on commit 71b6746

Please sign in to comment.