mirror of
https://github.com/actions/labeler.git
synced 2025-12-13 21:17:02 +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:
|
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'
|
||||||
|
|||||||
12
src/main.ts
12
src/main.ts
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user