From e84bc6af2911ec15490f417930766437b86603c1 Mon Sep 17 00:00:00 2001 From: Simon Tretter Date: Fri, 13 Nov 2020 17:28:22 +0100 Subject: [PATCH 1/2] fix: retrieve all changes via api the number returned by pullRequest.changed_files doesn't reflect the correct number of real changed files. Therefore lot of filters didn't work in my scenario, as it said nothing has changed. This especially happens if there are more than 100 files changed (first time I experienced it where over 1000 files have changed, and now when there were about 300 files that have changed). I changed the detection by querying the api as long as it returns new results. This ensures all pages have been retrieved. It's tested and used in production on our end, but please check again if I didn't miss anything. Thanks a lot for this awesome github action :) --- src/main.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 92cad59..bdf0008 100644 --- a/src/main.ts +++ b/src/main.ts @@ -127,8 +127,10 @@ async function getChangedFilesFromApi( const client = new github.GitHub(token) const pageSize = 100 const files: File[] = [] - for (let page = 0; page * pageSize < pullRequest.changed_files; page++) { - const response = await client.pulls.listFiles({ + let response: Octokit.Response + let page = 0 + do { + response = await client.pulls.listFiles({ owner: github.context.repo.owner, repo: github.context.repo.repo, pull_number: pullRequest.number, @@ -156,7 +158,8 @@ async function getChangedFilesFromApi( }) } } - } + page++ + } while (response?.data?.length > 0) return files } From 785a14adbee423890d02b9bc2b4367f8b14fb54c Mon Sep 17 00:00:00 2001 From: Simon Tretter Date: Fri, 13 Nov 2020 17:30:27 +0100 Subject: [PATCH 2/2] fix: add missing Octokit import --- src/main.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.ts b/src/main.ts index bdf0008..e295ac0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import * as fs from 'fs' import * as core from '@actions/core' import * as github from '@actions/github' import {Webhooks} from '@octokit/webhooks' +import type {Octokit} from '@octokit/rest' import {Filter, FilterResults} from './filter' import {File, ChangeStatus} from './file'