mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 20:51:42 +00:00
Paginate to get all changed files. Add option to remove labels
This commit is contained in:
@@ -7,6 +7,12 @@ inputs:
|
||||
configuration-path:
|
||||
description: 'The path for the label configurations'
|
||||
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:
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
||||
|
||||
12
src/main.ts
12
src/main.ts
@@ -7,6 +7,7 @@ async function run() {
|
||||
try {
|
||||
const token = core.getInput('repo-token', {required: true});
|
||||
const configPath = core.getInput('configuration-path', {required: true});
|
||||
const syncLabels = !!core.getInput("sync-labels", { required: false });
|
||||
|
||||
const prNumber = getPrNumber();
|
||||
if (!prNumber) {
|
||||
@@ -16,6 +17,12 @@ async function run() {
|
||||
|
||||
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}`);
|
||||
const changedFiles: string[] = await getChangedFiles(client, prNumber);
|
||||
const labelGlobs: Map<string, string[]> = await getLabelGlobs(
|
||||
@@ -53,13 +60,14 @@ async function getChangedFiles(
|
||||
client: github.GitHub,
|
||||
prNumber: number
|
||||
): Promise<string[]> {
|
||||
const listFilesResponse = await client.pulls.listFiles({
|
||||
const listFilesOptions = client.pulls.listFiles.endpoint.merge({
|
||||
owner: github.context.repo.owner,
|
||||
repo: github.context.repo.repo,
|
||||
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:');
|
||||
for (const file of changedFiles) {
|
||||
|
||||
Reference in New Issue
Block a user