Fix change detection using Github API (#51)

This commit is contained in:
Michal Dorner 2020-11-13 20:15:41 +01:00 committed by GitHub
parent eb8fe2c24b
commit d599443ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 18 deletions

20
dist/index.js vendored
View file

@ -4729,15 +4729,14 @@ async function getChangedFilesFromGit(base, initialFetchDepth) {
}
// Uses github REST api to get list of files changed in PR
async function getChangedFilesFromApi(token, pullRequest) {
var _a;
core.info(`Fetching list of changed files for PR#${pullRequest.number} from Github API`);
core.startGroup(`Fetching list of changed files for PR#${pullRequest.number} from Github API`);
core.info(`Number of changed_files is ${pullRequest.changed_files}`);
const client = new github.GitHub(token);
const pageSize = 100;
const files = [];
let response;
let page = 0;
do {
response = await client.pulls.listFiles({
for (let page = 1; (page - 1) * pageSize < pullRequest.changed_files; page++) {
core.info(`Invoking listFiles(pull_number: ${pullRequest.number}, page: ${page}, per_page: ${pageSize})`);
const response = await client.pulls.listFiles({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: pullRequest.number,
@ -4745,6 +4744,7 @@ async function getChangedFilesFromApi(token, pullRequest) {
per_page: pageSize
});
for (const row of response.data) {
core.info(`[${row.status}] ${row.filename}`);
// There's no obvious use-case for detection of renames
// Therefore we treat it as if rename detection in git diff was turned off.
// Rename is replaced by delete of original filename and add of new filename
@ -4760,14 +4760,16 @@ async function getChangedFilesFromApi(token, pullRequest) {
});
}
else {
// Github status and git status variants are same except for deleted files
const status = row.status === 'removed' ? file_1.ChangeStatus.Deleted : row.status;
files.push({
filename: row.filename,
status: row.status
status
});
}
}
page++;
} while (((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.length) > 0);
}
core.endGroup();
return files;
}
function exportResults(results, format) {