Skip to content

Commit

Permalink
feat: Repository label manager
Browse files Browse the repository at this point in the history
Labels on the repo are now defined through a `labels.yml` file and
maintained through a GitHub action.
  • Loading branch information
oliversalzburg committed Nov 19, 2022
1 parent 619ac28 commit ca45d3a
Show file tree
Hide file tree
Showing 15 changed files with 928 additions and 394 deletions.
5 changes: 4 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "monthly"
interval: "daily"
labels:
- "dependencies"
- "type:housekeeping"
97 changes: 97 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
labels:
affects:all:
color: "0DDAFA"
description: Not browser-specific
affects:build:
color: "0DDAFA"
description: An issue with the build process
affects:chrome:
color: "0DDAFA"
description: Has been observed in Chrome
affects:firefox:
color: "0DDAFA"
description: Has been observed in Firefox

dependencies:
color: "BFD4F2"
description: Pull requests that update a dependency file
# https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#about-default-labels
good first issue:
color: "7057ff"
description: If you haven't contributed yet, this might be a good place to start
help wanted:
color: "008672"
description: We can't figure this out, please help

needs:confirmation:
color: "eb6420"
description: A developer should confirm this issue happening
needs:merge:
color: "eb6420"
description: This work has been completed. It needs to be merged
needs:research:
color: "eb6420"
description: We don't know enough. Someone needs to look into it
needs:testing:
color: "eb6420"
description: Work has been done. Someone needs to test it
needs:triage:
color: "eb6420"
description: A developer needs to look at this
needs:work:
color: "eb6420"
description: It's clear what needs to be done. Now we need to do it

prio:accepted:
color: "53F643"
description: Tickets under active consideration for implementation
prio:beta:
color: "016E96"
description: Delayed until beta phase (earliest)
prio:important:
color: "B60205"
description: Should be included in next release
prio:rejected:
color: "CE3C0F"
description: Not realistically solvable at this time

status:confirmed:
color: "c7def8"
description: A developer reproduced this issue
status:duplicate:
color: "c7def8"
description: This problem has already neem reported
status:fixed:
color: "c7def8"
description: This problem has been solved
status:inprogress:
color: "c7def8"
description: Someone is actively working on this
status:norepro:
color: "c7def8"
description: We tried, but we don't know why this happens
status:wontfix:
color: "c7def8"
description: Sorry

type:bug:
color: "cc317c"
description: Problems in existing behavior
type:documentation:
color: "cc317c"
description: Improvements or additions to documentation
type:enhancement:
color: "cc317c"
description: Improvements to existing behavior
type:feature:
color: "cc317c"
description: Completely new behavior
type:housekeeping:
color: "cc317c"
description: Pull requests that maintain our repository in a clean state
type:rfc:
color: "cc317c"
description: Please provide feedback on this item
type:question:
color: "cc317c"
description: Support; no call to action
27 changes: 27 additions & 0 deletions .github/workflows/manage-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Manage Labels

on:
push:
branches:
- main
paths:
- ./.github/labels.yml
- ./packages/label-manager/**
workflow_dispatch:

concurrency: manage-labels

jobs:
manage-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@master
with:
node-version: 18.x
- run: yarn install
- run: yarn workspace @kitten-science/label-manager tsc --build

- uses: ./packages/label-manager
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
211 changes: 103 additions & 108 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

554 changes: 280 additions & 274 deletions .yarn/releases/yarn-3.2.4.cjs → .yarn/releases/yarn-3.3.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.2.4.cjs
yarnPath: .yarn/releases/yarn-3.3.0.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"kittens",
"scientists"
],
"packageManager": "yarn@3.2.4"
"packageManager": "yarn@3.3.0"
}
10 changes: 10 additions & 0 deletions packages/label-manager/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "KS Label Manager"
description: "Manages labels on the Kitten Science repositories."
author: "Oliver Salzburg"
inputs:
repo_token:
required: true
description: Needs `secrets.GITHUB_TOKEN` to talk to the API.
runs:
using: "node16"
main: "output/main.js"
26 changes: 26 additions & 0 deletions packages/label-manager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"name": "@kitten-science/label-manager",
"version": "latest",
"description": "Manages the labels on this GitHub repository.",
"license": "MIT",
"author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
"homepage": "https://github.com/kitten-science/kitten-scientists",
"repository": {
"type": "git",
"url": "git+https://github.com/kitten-science/kitten-scientists.git"
},
"bugs": {
"url": "https://github.com/kitten-science/kitten-scientists/issues"
},
"dependencies": {
"@actions/core": "1.10.0",
"@actions/github": "5.1.1",
"tslib": "2.4.1",
"yaml": "2.1.3"
},
"devDependencies": {
"@types/node": "18.11.9",
"typescript": "4.9.3"
}
}
95 changes: 95 additions & 0 deletions packages/label-manager/source/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import fs from "node:fs/promises";
import YAML from "yaml";

async function run(): Promise<void> {
try {
if (!process.env.GITHUB_REPOSITORY) {
throw new Error("Missing GITHUB_REPOSITORY");
}

const [repoOwner, repoName] = process.env.GITHUB_REPOSITORY.split("/");
const repoToken = core.getInput("repo_token");

const labelsYaml = await fs.readFile(".github/labels.yml", "utf8");
const config = YAML.parse(labelsYaml) as {
labels: Record<string, { color?: string; description?: string }>;
};

core.debug("Configured labels:");
for (const [name, label] of Object.entries(config.labels)) {
core.debug(name);
if (label.color) {
core.debug(` Color: ${label.color}`);
}
if (label.description) {
core.debug(` Descr: ${label.description}`);
}
}

const octokit = github.getOctokit(repoToken);

const existingLabels = await octokit.rest.issues.listLabelsForRepo({
owner: repoOwner,
repo: repoName,
});

core.info("Updating labels...");
const labelResults = {
created: new Array<string>(),
updated: new Array<string>(),
};

for (const [name, label] of Object.entries(config.labels)) {
const existingLabel = existingLabels.data.find(existing => existing.name === name);
if (existingLabel) {
if (
existingLabel.color === label.color &&
existingLabel.description === (label.description ?? null)
) {
core.info(`Label '${name}' is up-to-date. Skipping.`);
continue;
}

core.notice(`Label '${name}' exists with different attributes. Updating...`);
existingLabel.color = label.color ?? "888888";
existingLabel.description = label.description ?? null;
await octokit.rest.issues.updateLabel({
color: label.color,
description: label.description,
name: existingLabel.name,
owner: repoOwner,
repo: repoName,
});
continue;
}

core.notice(`Creating new label '${name}'...`);
await octokit.rest.issues.createLabel({
color: label.color,
description: label.description,
name: name,
owner: repoOwner,
repo: repoName,
});
labelResults.created.push(name);
}

for (const label of existingLabels.data) {
const labelIsConfigured = Object.keys(config.labels).includes(label.name);
if (!labelIsConfigured) {
core.notice(`Label '${label.name}' is not configured in labels.yml. It should be deleted.`);
}
}

core.setOutput("label_created", labelResults.created);
core.setOutput("label_updated", labelResults.updated);

core.info("Done.");
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
}
}

void run();
12 changes: 12 additions & 0 deletions packages/label-manager/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "output",
"rootDir": "source",
"target": "ES6",
"tsBuildInfoFile": "output/.tsbuildinfo",
"types": ["@types/node"]
},
"include": ["../../@types", "./source"]
}
3 changes: 2 additions & 1 deletion packages/userscript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"rootDir": "source",
"outDir": "output",
"tsBuildInfoFile": "output/.tsbuildinfo"
"tsBuildInfoFile": "output/.tsbuildinfo",
"types": ["@types/web"]
},
"include": ["../../@types", "./source"]
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"strict": true,
"target": "ESNext",
"incremental": true,
"skipLibCheck": true,
"types": ["@types/web"]
"skipLibCheck": true
},
"exclude": ["**/*.cjs", "**/*.js"]
}
Loading

0 comments on commit ca45d3a

Please sign in to comment.