mirror of
https://github.com/actions/labeler.git
synced 2025-12-14 05:43:42 +00:00
build
This commit is contained in:
29
lib/main.js
29
lib/main.js
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
@@ -35,14 +35,20 @@ const minimatch_1 = require("minimatch");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const token = core.getInput('repo-token', { required: true });
|
||||
const configPath = core.getInput('configuration-path', { required: true });
|
||||
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) {
|
||||
console.log('Could not get pull request number from context, exiting');
|
||||
console.log("Could not get pull request number from context, exiting");
|
||||
return;
|
||||
}
|
||||
const client = new github.GitHub(token);
|
||||
const { data: pullRequest } = yield 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 = yield getChangedFiles(client, prNumber);
|
||||
const labelGlobs = yield getLabelGlobs(client, configPath);
|
||||
@@ -72,15 +78,16 @@ function getPrNumber() {
|
||||
}
|
||||
function getChangedFiles(client, prNumber) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const listFilesResponse = yield 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);
|
||||
core.debug('found changed files:');
|
||||
const listFilesResponse = yield client.paginate(listFilesOptions);
|
||||
const changedFiles = listFilesResponse.map(f => f.filename);
|
||||
core.debug("found changed files:");
|
||||
for (const file of changedFiles) {
|
||||
core.debug(' ' + file);
|
||||
core.debug(" " + file);
|
||||
}
|
||||
return changedFiles;
|
||||
});
|
||||
@@ -102,19 +109,19 @@ function fetchContent(client, repoPath) {
|
||||
path: repoPath,
|
||||
ref: github.context.sha
|
||||
});
|
||||
if (!('content' in response.data)) {
|
||||
if (!("content" in response.data)) {
|
||||
throw new Error(`The path '${repoPath}' is not a file`);
|
||||
}
|
||||
if (!response.data.content) {
|
||||
throw new Error(`The file '${repoPath}' has no content`);
|
||||
}
|
||||
return Buffer.from(response.data.content, 'base64').toString();
|
||||
return Buffer.from(response.data.content, "base64").toString();
|
||||
});
|
||||
}
|
||||
function getLabelGlobMapFromObject(configObject) {
|
||||
const labelGlobs = new Map();
|
||||
for (const label in configObject) {
|
||||
if (typeof configObject[label] === 'string') {
|
||||
if (typeof configObject[label] === "string") {
|
||||
labelGlobs.set(label, [configObject[label]]);
|
||||
}
|
||||
else if (configObject[label] instanceof Array) {
|
||||
|
||||
Reference in New Issue
Block a user