Skip to content

Commit

Permalink
Update label gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Barber committed Dec 10, 2022
1 parent a87fb51 commit 5169d7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
17 changes: 7 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52216,33 +52216,30 @@ function setupLabels(context) {
exports.setupLabels = setupLabels;
function createLabels(labelSizeConfig, context) {
return __awaiter(this, void 0, void 0, function* () {
const existingLabels = yield context.octokit.issues.listLabelsForRepo({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
});
const labels = Object.values(Config_1.LabelSuffix).map((suffix) => ({
name: `${labelSizeConfig.prefix}${suffix}`,
colour: labelSizeConfig.colours[suffix],
}));
const requests = [];
labels.map(({ name, colour }) => {
requests.push(upsertLabel(context, name, colour, !!existingLabels.data.find((label) => label.name === name)));
requests.push(upsertLabel(context, name, colour));
});
yield Promise.all(requests);
});
}
function upsertLabel(context, name, colour, labelExists) {
function upsertLabel(context, name, colour) {
return __awaiter(this, void 0, void 0, function* () {
if (labelExists) {
yield context.octokit.issues.updateLabel({
try {
yield context.octokit.issues.createLabel({
name,
color: colour.replace("#", ""),
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
});
}
else {
context.octokit.issues.createLabel({
catch (error) {
console.info(`Label [${name}] already exists, updating instead.`);
yield context.octokit.issues.updateLabel({
name,
color: colour.replace("#", ""),
owner: context.payload.repository.owner.login,
Expand Down
25 changes: 7 additions & 18 deletions src/features/SetupLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ async function createLabels(
labelSizeConfig: LabelSizeConfig,
context: Context<"pull_request">
): Promise<void> {
const existingLabels = await context.octokit.issues.listLabelsForRepo({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
});
const labels = Object.values(LabelSuffix).map((suffix) => ({
name: `${labelSizeConfig.prefix}${suffix}`,
colour: labelSizeConfig.colours[suffix],
Expand All @@ -29,14 +25,7 @@ async function createLabels(
const requests: Promise<unknown>[] = [];

labels.map(({ name, colour }) => {
requests.push(
upsertLabel(
context,
name,
colour,
!!existingLabels.data.find((label) => label.name === name)
)
);
requests.push(upsertLabel(context, name, colour));
});

await Promise.all(requests);
Expand All @@ -45,18 +34,18 @@ async function createLabels(
async function upsertLabel(
context: Context<"pull_request">,
name: string,
colour: string,
labelExists: boolean
colour: string
): Promise<void> {
if (labelExists) {
await context.octokit.issues.updateLabel({
try {
await context.octokit.issues.createLabel({
name,
color: colour.replace("#", ""),
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
});
} else {
context.octokit.issues.createLabel({
} catch (error) {
console.info(`Label [${name}] already exists, updating instead.`);
await context.octokit.issues.updateLabel({
name,
color: colour.replace("#", ""),
owner: context.payload.repository.owner.login,
Expand Down

0 comments on commit 5169d7e

Please # to comment.