mirror of
https://github.com/dorny/paths-filter.git
synced 2024-12-20 00:49:04 +00:00
Fix change detection using Github API (#51)
This commit is contained in:
parent
eb8fe2c24b
commit
d599443ba5
@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## v2.5.3
|
||||
- [Fixed mapping of removed/deleted change status from github API](https://github.com/dorny/paths-filter/pull/51)
|
||||
- [Fixed retrieval of all changes via Github API when there are 100+ changes](https://github.com/dorny/paths-filter/pull/50)
|
||||
|
||||
## v2.5.2
|
||||
|
20
dist/index.js
vendored
20
dist/index.js
vendored
@ -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) {
|
||||
|
20
src/main.ts
20
src/main.ts
@ -2,7 +2,6 @@ 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'
|
||||
@ -124,14 +123,14 @@ async function getChangedFilesFromApi(
|
||||
token: string,
|
||||
pullRequest: Webhooks.WebhookPayloadPullRequestPullRequest
|
||||
): Promise<File[]> {
|
||||
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: File[] = []
|
||||
let response: Octokit.Response<Octokit.PullsListFilesResponse>
|
||||
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,
|
||||
@ -139,6 +138,7 @@ async function getChangedFilesFromApi(
|
||||
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
|
||||
@ -153,15 +153,17 @@ async function getChangedFilesFromApi(
|
||||
status: ChangeStatus.Deleted
|
||||
})
|
||||
} else {
|
||||
// Github status and git status variants are same except for deleted files
|
||||
const status = row.status === 'removed' ? ChangeStatus.Deleted : (row.status as ChangeStatus)
|
||||
files.push({
|
||||
filename: row.filename,
|
||||
status: row.status as ChangeStatus
|
||||
status
|
||||
})
|
||||
}
|
||||
}
|
||||
page++
|
||||
} while (response?.data?.length > 0)
|
||||
}
|
||||
|
||||
core.endGroup()
|
||||
return files
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user