mirror of
https://github.com/actions/labeler.git
synced 2025-12-13 21:17:02 +00:00
Rebuild project
This commit is contained in:
38
dist/index.js
vendored
38
dist/index.js
vendored
@@ -47,19 +47,19 @@ const minimatch_1 = __nccwpck_require__(3973);
|
|||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
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 syncLabels = !!core.getInput('sync-labels', { required: false });
|
||||||
const prNumber = getPrNumber();
|
const prNumber = getPrNumber();
|
||||||
if (!prNumber) {
|
if (!prNumber) {
|
||||||
console.log("Could not get pull request number from context, exiting");
|
console.log('Could not get pull request number from context, exiting');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const client = github.getOctokit(token);
|
const client = github.getOctokit(token);
|
||||||
const { data: pullRequest } = yield client.rest.pulls.get({
|
const { data: pullRequest } = yield client.rest.pulls.get({
|
||||||
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
|
||||||
});
|
});
|
||||||
core.debug(`fetching changed files for pr #${prNumber}`);
|
core.debug(`fetching changed files for pr #${prNumber}`);
|
||||||
const changedFiles = yield getChangedFiles(client, prNumber);
|
const changedFiles = yield getChangedFiles(client, prNumber);
|
||||||
@@ -71,7 +71,7 @@ function run() {
|
|||||||
if (checkGlobs(changedFiles, globs)) {
|
if (checkGlobs(changedFiles, globs)) {
|
||||||
labels.push(label);
|
labels.push(label);
|
||||||
}
|
}
|
||||||
else if (pullRequest.labels.find((l) => l.name === label)) {
|
else if (pullRequest.labels.find(l => l.name === label)) {
|
||||||
labelsToRemove.push(label);
|
labelsToRemove.push(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,13 +101,13 @@ function getChangedFiles(client, prNumber) {
|
|||||||
const listFilesOptions = client.rest.pulls.listFiles.endpoint.merge({
|
const listFilesOptions = client.rest.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 listFilesResponse = yield client.paginate(listFilesOptions);
|
const listFilesResponse = yield client.paginate(listFilesOptions);
|
||||||
const changedFiles = listFilesResponse.map((f) => f.filename);
|
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) {
|
||||||
core.debug(" " + file);
|
core.debug(' ' + file);
|
||||||
}
|
}
|
||||||
return changedFiles;
|
return changedFiles;
|
||||||
});
|
});
|
||||||
@@ -127,7 +127,7 @@ function fetchContent(client, repoPath) {
|
|||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
path: repoPath,
|
path: repoPath,
|
||||||
ref: github.context.sha,
|
ref: github.context.sha
|
||||||
});
|
});
|
||||||
return Buffer.from(response.data.content, response.data.encoding).toString();
|
return Buffer.from(response.data.content, response.data.encoding).toString();
|
||||||
});
|
});
|
||||||
@@ -135,7 +135,7 @@ function fetchContent(client, repoPath) {
|
|||||||
function getLabelGlobMapFromObject(configObject) {
|
function getLabelGlobMapFromObject(configObject) {
|
||||||
const labelGlobs = new Map();
|
const labelGlobs = new Map();
|
||||||
for (const label in configObject) {
|
for (const label in configObject) {
|
||||||
if (typeof configObject[label] === "string") {
|
if (typeof configObject[label] === 'string') {
|
||||||
labelGlobs.set(label, [configObject[label]]);
|
labelGlobs.set(label, [configObject[label]]);
|
||||||
}
|
}
|
||||||
else if (configObject[label] instanceof Array) {
|
else if (configObject[label] instanceof Array) {
|
||||||
@@ -148,15 +148,15 @@ function getLabelGlobMapFromObject(configObject) {
|
|||||||
return labelGlobs;
|
return labelGlobs;
|
||||||
}
|
}
|
||||||
function toMatchConfig(config) {
|
function toMatchConfig(config) {
|
||||||
if (typeof config === "string") {
|
if (typeof config === 'string') {
|
||||||
return {
|
return {
|
||||||
any: [config],
|
any: [config]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
function printPattern(matcher) {
|
function printPattern(matcher) {
|
||||||
return (matcher.negate ? "!" : "") + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
function checkGlobs(changedFiles, globs) {
|
function checkGlobs(changedFiles, globs) {
|
||||||
for (const glob of globs) {
|
for (const glob of globs) {
|
||||||
@@ -183,7 +183,7 @@ function isMatch(changedFile, matchers) {
|
|||||||
}
|
}
|
||||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||||
function checkAny(changedFiles, globs) {
|
function checkAny(changedFiles, globs) {
|
||||||
const matchers = globs.map((g) => new minimatch_1.Minimatch(g));
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
core.debug(` checking "any" patterns`);
|
core.debug(` checking "any" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
for (const changedFile of changedFiles) {
|
||||||
if (isMatch(changedFile, matchers)) {
|
if (isMatch(changedFile, matchers)) {
|
||||||
@@ -196,7 +196,7 @@ function checkAny(changedFiles, globs) {
|
|||||||
}
|
}
|
||||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||||
function checkAll(changedFiles, globs) {
|
function checkAll(changedFiles, globs) {
|
||||||
const matchers = globs.map((g) => new minimatch_1.Minimatch(g));
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
core.debug(` checking "all" patterns`);
|
core.debug(` checking "all" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
for (const changedFile of changedFiles) {
|
||||||
if (!isMatch(changedFile, matchers)) {
|
if (!isMatch(changedFile, matchers)) {
|
||||||
@@ -226,17 +226,17 @@ function addLabels(client, prNumber, labels) {
|
|||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: prNumber,
|
issue_number: prNumber,
|
||||||
labels: labels,
|
labels: labels
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function removeLabels(client, prNumber, labels) {
|
function removeLabels(client, prNumber, labels) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
yield Promise.all(labels.map((label) => client.rest.issues.removeLabel({
|
yield Promise.all(labels.map(label => client.rest.issues.removeLabel({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: prNumber,
|
issue_number: prNumber,
|
||||||
name: label,
|
name: label
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user