Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/sync-labels/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
25 changes: 25 additions & 0 deletions scripts/sync-labels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Issue Label Syncer

Manually sync issue labels.

## Install

Before usage, you'll need to install the dependencies.

```go
$ npm install
```

## Usage

To sync issue labels to all repos listed in `.config/workflows/config.json`, run:

```bash
$ node index.js
```

You can also sync labels to a specific repo:

```bash
$ node index.js my-org/my-repo
```
61 changes: 61 additions & 0 deletions scripts/sync-labels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import githubLabelSync from 'github-label-sync'
import { readFile } from 'fs/promises'
import path from 'path'
import url from 'url'

const GH_TOKEN = process.env.GITHUB_TOKEN
if (!GH_TOKEN) {
console.log('Error: Please set the GITHUB_TOKEN environment variable')
process.exit(1)
}

const REPO_ROOT = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../../');

(async () => {
let repos = process.argv.splice(2)
// Apply to all repos if no repos are specified.
if (repos.length == 0) {
repos = JSON.parse(await readFile(path.join(REPO_ROOT, ".github/workflows/config.json")))
.map(item => item.target)
}

let labels = JSON.parse(await readFile(path.join(REPO_ROOT, "templates/.github/issue-labels.json")))

for (const repo of repos) {
try {
let diff = await githubLabelSync({
accessToken: GH_TOKEN,
repo: repo,
allowAddedLabels: true,
labels: labels
})
console.log(`updating ${repo}`)
for (var change of diff) {
switch (change.type) {
case 'missing':
console.log(` added ${change.expected.name}`)
break;
case 'changed':
if (change.actual.name !== change.expected.name) {
console.log(` renamed ${change.actual.name} to ${change.expected.name}`)
} else if (change.actual.description !== change.expected.description) {
console.log(` changed ${change.actual.name} description to: ${change.expected.description}`)
} else if (change.actual.color !== change.expected.color) {
console.log(` recolored ${change.actual.name}`)
} else {
console.log(` updated ${change.actual.name}`)
}
break;
case 'added':
console.log(` removed ${change.actual.name}`)
break;
default:
console.log(` unknown change ${diff}`)
}
}
} catch (e) {
console.log(`failed to update labels for ${repo}: ${e}`)
console.dir(e, {depth: 4, colors: true})
}
}
})()
Loading