Paginate to get all changed files. Add option to remove labels

This commit is contained in:
David Kale
2020-09-08 12:37:50 -04:00
parent c5c9bd0f54
commit e4246d2b5b
2 changed files with 16 additions and 2 deletions

View File

@@ -7,6 +7,12 @@ inputs:
configuration-path: configuration-path:
description: 'The path for the label configurations' description: 'The path for the label configurations'
default: '.github/labeler.yml' default: '.github/labeler.yml'
required: false
sync-labels:
description: 'Whether or not to remove labels when matching files are reverted'
default: false
required: false
runs: runs:
using: 'node12' using: 'node12'
main: 'lib/main.js' main: 'lib/main.js'

View File

@@ -7,6 +7,7 @@ async function run() {
try { try {
const token = core.getInput('repo-token', {required: true}); const token = core.getInput('repo-token', {required: true});
const configPath = core.getInput('configuration-path', {required: true}); const configPath = core.getInput('configuration-path', {required: true});
const syncLabels = !!core.getInput("sync-labels", { required: false });
const prNumber = getPrNumber(); const prNumber = getPrNumber();
if (!prNumber) { if (!prNumber) {
@@ -16,6 +17,12 @@ async function run() {
const client = new github.GitHub(token); const client = new github.GitHub(token);
const { data: pullRequest } = await client.pulls.get({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber
});
core.debug(`fetching changed files for pr #${prNumber}`); core.debug(`fetching changed files for pr #${prNumber}`);
const changedFiles: string[] = await getChangedFiles(client, prNumber); const changedFiles: string[] = await getChangedFiles(client, prNumber);
const labelGlobs: Map<string, string[]> = await getLabelGlobs( const labelGlobs: Map<string, string[]> = await getLabelGlobs(
@@ -53,13 +60,14 @@ async function getChangedFiles(
client: github.GitHub, client: github.GitHub,
prNumber: number prNumber: number
): Promise<string[]> { ): Promise<string[]> {
const listFilesResponse = await client.pulls.listFiles({ const listFilesOptions = client.pulls.listFiles.endpoint.merge({
owner: github.context.repo.owner, owner: github.context.repo.owner,
repo: github.context.repo.repo, repo: github.context.repo.repo,
pull_number: prNumber pull_number: prNumber
}); });
const changedFiles = listFilesResponse.data.map(f => f.filename); const listFilesResponse = await client.paginate(listFilesOptions);
const changedFiles = listFilesResponse.map(f => f.filename);
core.debug('found changed files:'); core.debug('found changed files:');
for (const file of changedFiles) { for (const file of changedFiles) {