Skip to content

Commit

Permalink
gracefully handle new branches/tags pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
yrtimiD committed Jul 14, 2024
1 parent f376378 commit c45b216
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
37 changes: 21 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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.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": {
Expand Down
17 changes: 10 additions & 7 deletions src/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ export async function check(context: Context, options: Options): Promise<Notif.N
core.debug(JSON.stringify(watchers, ['user', 'patterns', 'login']));

core.info(`Comparing ${shaFrom}...${shaTo}`);

let commits: string[] = [];
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;
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;
}
}
}

Expand Down

0 comments on commit c45b216

Please sign in to comment.