From c45b2160f23774e709958e3070d1e5bdd78d1e82 Mon Sep 17 00:00:00 2001 From: Dmitry Gurovich Date: Sun, 14 Jul 2024 15:57:14 +0300 Subject: [PATCH] gracefully handle new branches/tags pushes --- dist/index.js | 37 +++++++++++++++++++++---------------- package.json | 2 +- src/match.ts | 17 ++++++++++------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/dist/index.js b/dist/index.js index 31f92cf..05b052c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -52447,25 +52447,30 @@ function check(context, options) { core.debug(JSON.stringify(watchers, ['user', 'patterns', 'login'])); core.info(`Comparing ${shaFrom}...${shaTo}`); let commits = []; - let commitsIter = octokit.paginate.iterator(octokit.rest.repos.compareCommits, { owner, repo, base: shaFrom, head: shaTo, per_page: PAGE_SIZE }); - try { - for (var _f = true, commitsIter_1 = __asyncValues(commitsIter), commitsIter_1_1; commitsIter_1_1 = yield commitsIter_1.next(), _a = commitsIter_1_1.done, !_a; _f = true) { - _c = commitsIter_1_1.value; - _f = false; - let { data } = _c; - (_d = context.compareLink) !== null && _d !== void 0 ? _d : (context.compareLink = data.html_url); - commits.push(...(_e = data.commits.map(c => c.sha)) !== null && _e !== void 0 ? _e : []); - if (commits.at(-1) === shaTo) { - break; - } - } + if (shaFrom === '0000000000000000000000000000000000000000') { + core.info(`Unusable 'shaFrom' value (probably new branch was created).`); } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { + else { + let commitsIter = octokit.paginate.iterator(octokit.rest.repos.compareCommits, { owner, repo, base: shaFrom, head: shaTo, per_page: PAGE_SIZE }); try { - if (!_f && !_a && (_b = commitsIter_1.return)) yield _b.call(commitsIter_1); + for (var _f = true, commitsIter_1 = __asyncValues(commitsIter), commitsIter_1_1; commitsIter_1_1 = yield commitsIter_1.next(), _a = commitsIter_1_1.done, !_a; _f = true) { + _c = commitsIter_1_1.value; + _f = false; + let { data } = _c; + (_d = context.compareLink) !== null && _d !== void 0 ? _d : (context.compareLink = data.html_url); + commits.push(...(_e = data.commits.map(c => c.sha)) !== null && _e !== void 0 ? _e : []); + if (commits.at(-1) === shaTo) { + break; + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (!_f && !_a && (_b = commitsIter_1.return)) yield _b.call(commitsIter_1); + } + finally { if (e_1) throw e_1.error; } } - finally { if (e_1) throw e_1.error; } } let notifications = []; for (let sha of commits) { diff --git a/package.json b/package.json index 1786b4a..de502c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-codewatchers", - "version": "2.1.1", + "version": "2.1.2", "description": "GitHub Action that triggers notifications about changed files to a list of subscribers", "main": "dist/index.js", "scripts": { diff --git a/src/match.ts b/src/match.ts index 8415ca5..b433767 100644 --- a/src/match.ts +++ b/src/match.ts @@ -14,14 +14,17 @@ export async function check(context: Context, options: Options): Promise c.sha) ?? []); - if (commits.at(-1) === shaTo) { - break; + if (shaFrom === '0000000000000000000000000000000000000000') { + core.info(`Unusable 'shaFrom' value (probably new branch was created).`); + } else { + let commitsIter = octokit.paginate.iterator(octokit.rest.repos.compareCommits, { owner, repo, base: shaFrom, head: shaTo, per_page: PAGE_SIZE }); + for await (let { data } of commitsIter) { + context.compareLink ??= data.html_url; + commits.push(...data.commits.map(c => c.sha) ?? []); + if (commits.at(-1) === shaTo) { + break; + } } }