• Stars
    star
    223
  • Rank 178,458 (Top 4 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Synchronise your GitHub labels with as few destructive operations as possible

GitHub Label Sync NPM version MIT licensed

Synchronise your GitHub labels with as few destructive operations as possible – similar labels get renamed.

Table Of Contents

Requirements

You'll need Node.js 12+ installed to run GitHub Label Sync. You'll also need a GitHub access token ready so that the tool will have access to your repositories. You can generate an access token here, be sure to allow the "repo" scope.

Command-Line Interface

Install GitHub Label Sync globally with npm:

npm install -g github-label-sync

This installs the github-label-sync command-line tool:

Usage: github-label-sync [options] <repository>

Options:

  -h, --help                  output usage information
  -V, --version               output the version number
  -a, --access-token <token>  a GitHub access token (also settable with a GITHUB_ACCESS_TOKEN environment variable)
  -l, --labels <path>         the path or URL to look for the label configuration in. Default: labels.json
  -d, --dry-run               calculate the required label changes but do not apply them
  -A, --allow-added-labels    allow additional labels in the repo, and don't delete them

Run GitHub Label Sync on a repo (reading label data from a local labels.json):

github-label-sync --access-token xxxxxx myname/myrepo

Run GitHub Label Sync using a different label config file:

github-label-sync --access-token xxxxxx --labels my-labels.json myname/myrepo

Label config file can be also specified as YAML:

github-label-sync --access-token xxxxxx --labels my-labels.yml myname/myrepo

Perform a dry run, only making safe "read" requests to the GitHub API:

github-label-sync --access-token xxxxxx --dry-run myname/myrepo

Normally any additional labels found on the repo are deleted. Run GitHub label sync and ignore additional labels, leaving them as-is:

github-label-sync --access-token xxxxxx --allow-added-labels myname/myrepo

JavaScript Interface

Install GitHub Label Sync with npm or add to your package.json:

npm install github-label-sync

Require GitHub Label Sync:

var githubLabelSync = require('github-label-sync');

The githubLabelSync function returns a promise that resolves to a JSON diff between the labels found on GitHub, and the labels in your label config.

Run GitHub Label Sync on a repo (passing in options):

githubLabelSync({
	accessToken: 'xxxxxx',
	repo: 'myname/myrepo',
	labels: [
		// label config
	]
}).then((diff) => {
	console.log(diff);
});

The available options are documented below.

When the promise resolves successfully, its value will be set to a diff between the labels found on GitHub, and the labels in your label config. The diff will look like this:

[
	// This is a "missing" diff, it indicates that a label
	// present in your local config is not present on GitHub.
	{
		name: 'local-label-name',
		type: 'missing',
		actual: null,
		expected: {
			name: 'local-label-name',
			color: 'ff0000'
		}
	},
	// This is a "changed" diff, it indicates that a label
	// present on GitHub has diverged from your local config.
	// This could mean that either somebody has modified the
	// label manually on GitHub, or the local config has
	// been updated.
	{
		name: 'local-label-name',
		type: 'changed',
		actual: {
			name: 'remote-label-name',
			color: '00ff00'
		},
		expected: {
			name: 'local-label-name',
			color: 'ff0000'
		}
	},
	// This is an "added" diff, it indicates that a label
	// is present on GitHub but not in your local config.
	{
		name: 'remote-label-name',
		type: 'added',
		actual: {
			name: 'remote-label-name',
			color: 'ff0000'
		},
		expected: null
	}
]

Label Config File

The labels to sync with are defined as an array in either JavaScript, JSON or YAML. The array must contain only label objects, which look like this:

As JSON:

{
	"name": "mylabel",
	"color": "ff0000",
	"aliases": [],
	"description": "optional description",
	"delete": false
}

As YAML:

- name: mylabel
  color: "ff0000"
  aliases: []
  description: optional description
  delete: false
  • The name property refers to the label name.
  • The color property should be a hex code, with or without the leading #.
  • The delete property is optional. When set to true, matches for this label will always be deleted. This can be used in conjunction with allowAddedLabels to flag specific labels for deletion while leaving non-specified labels intact. Defaults to false.

The aliases property is optional. When GitHub Label Sync is determining whether to update or delete/create a label it will use the aliases property to prevent used labels from being deleted.

For example, given the following config, GitHub Label Sync will look for labels on GitHub named either "feature" or "enhancement" then update them to match the newer config rather than deleting them.

{
	"name": "type: feature",
	"color": "00ff00",
	"aliases": [
		"enhancement",
		"feature"
	]
}

You can find a full example label configuration in this repository (JSON / YAML).

Configuration

accessToken

String. The GitHub access token to use when fetching/updating labels. This must be an access token that has permission to write to the repository you want to sync labels with.

githubLabelSync({
	accessToken: 'xxxxxx'
});

On the command-line this can be set with either the access-token flag or the GITHUB_ACCESS_TOKEN environment variable:

github-label-sync --access-token xxxxxx
GITHUB_ACCESS_TOKEN=xxxxxx github-label-sync

allowAddedLabels

Boolean. Whether to allow labels on GitHub which are not specified in your label config. If true, they are allowed and will be left alone. If false, they will be deleted. Default: false.

githubLabelSync({
	allowAddedLabels: true
});

The command-line allow-added-labels flag corresponds to this option:

github-label-sync --allow-added-labels

dryRun

Boolean. Whether to perform a dry run, only making safe "read" requests to the GitHub API. If true, label changes will not be executed on GitHub. If false, label changes will be executed. Default: false.

githubLabelSync({
	dryRun: true
});

The command-line dry-run flag corresponds to this option:

github-label-sync --dry-run

labels

Array. Your label configuration. See the section on label config file.

githubLabelSync({
	labels: []
});

On the command-line this can be set with the labels flag which should point to a JSON or YAML file.

repo

String. The GitHub repo to sync labels to. This should include the user and repo names, e.g. "Financial-Times/ft-origami".

githubLabelSync({
	repo: 'Financial-Times/ft-origami'
});

The command-line accepts the repo as an argument after the options:

github-label-sync Financial-Times/ft-origami

Contributing

To contribute to GitHub Label Sync, clone this repo locally and commit your code on a separate branch.

Please write unit tests for your code, and check that everything works by running the following before opening a pull-request:

npm test               # run the full test suite
npm run lint           # run the linter
npm run test-unit      # run the unit tests
npm run test-coverage  # run the unit tests with coverage reporting

License

This software is published by the Financial Times under the MIT licence.

More Repositories

1

chart-doctor

Sample files to accompany the FT's Chart Doctor column
HTML
2,791
star
2

ftdomdelegate

Create and manage a DOM event delegator
JavaScript
322
star
3

coronavirus-excess-mortality-data

Excess mortality data compiled by the FT Visual & Data Journalism team
159
star
4

engineering-progression

Careers and progression for engineers in the CTO organisation.
JavaScript
103
star
5

o-grid

Responsive grid system
95
star
6

ft-origami

The Old Origami Website, do not use
HTML
78
star
7

k8s_traffic_plug

Traffic endpoint and graceful shutdown for Elixir Plug apps
Elixir
72
star
8

tapper

Zipkin client for Elixir
Elixir
68
star
9

docker-elixir-build

Dockerfile for building Elixir projects
Dockerfile
56
star
10

n-express-monitor

🎯 configurable express decorator to automate log, metrics for more consistent monitor and debugging across micro-services
JavaScript
55
star
11

origami-build-tools

Standard Origami component development tools.
JavaScript
49
star
12

x-dash

❌➖📰 shared front-end components for FT.com and the FT Apps
JavaScript
38
star
13

ig-images-backend

JavaScript
37
star
14

origami

The Origami Component System
JavaScript
33
star
15

careers

💼 Engineering jobs at the Financial Times.
32
star
16

n-makefile

🍭 Shared build tools.
Makefile
32
star
17

fastly-tools

Command Line Utility for interacting with fastly
JavaScript
30
star
18

ftplottools

R Package for FT ggplot graphs
R
27
star
19

data-journalism-covid-hospital-counterfactual

Methodology behind story on how poor vaccine coverage in the US greatly increased its exposure to Covid hospitalisations relative to peer countries
R
25
star
20

node-health-check

Build health check functions which comply with the FT health check standard
JavaScript
24
star
21

ec2-powercycle

Lambda function to stop and start EC2 instances based on tag
Shell
22
star
22

mongo-hot-backup

A mongodb backup tool for FT Universal Publishing
Go
21
star
23

zipkin-helm

A helm chart for zipkin
Mustache
20
star
24

athloi

💪 Athloi is a tool to assist with the management of multi-package repositories (a.k.a. monorepos)
JavaScript
19
star
25

origami-website

The Origami website
18
star
26

bertha

Service to convert google spreadsheets to JSON, CSV and TSV and cache the result
JavaScript
18
star
27

origami-image-service

Optimises and resizes images
JavaScript
17
star
28

dotcom-page-kit

📰 Page Kit provides a high quality, well tested, and thoroughly documented set of tools for assembling and delivering FT.com based upon the best industry standards.
TypeScript
17
star
29

lambda-logger

Logger for lambda functions. Logs in JSON format using pino
JavaScript
15
star
30

public-people-api

Public API for retrieving information about a person
Go
14
star
31

origami-registry-ui

Get information about Origami components, services, and repositories.
JavaScript
14
star
32

n-heroku-tools

FT.com deployment tools
JavaScript
14
star
33

o-ads

Deprecated see README
JavaScript
14
star
34

grafana-tools

Automate your project Grafana dashboards
JavaScript
13
star
35

serverless-plugin-healthcheck

Scheduled health checks of lambdas
JavaScript
12
star
36

google-amp

⚡️ FT.com's implementation of the AMP project.
JavaScript
12
star
37

n-search-parser

🔎 A sane, fast, not too smart, search expression parser.
JavaScript
11
star
38

coco-splunk-http-forwarder

Go
11
star
39

ui-style-guide

Deprecated
HTML
11
star
40

nori

🍙 exploratory command-line tool to make changes across multiple repositories & track their progress
JavaScript
11
star
41

ft-api-client

A Node.js client for the Financial Times Content and Notifications APIs
JavaScript
11
star
42

ft-poller

Scheduled, asynchronous JSON fetching for Node.js applications
JavaScript
11
star
43

dotcom-tool-kit

🧰 modern, maintainable, modular developer tooling for FT.com projects
TypeScript
10
star
44

g-components

Reusable layout and structural components
JavaScript
10
star
45

o-typography

Typography and vertical rhythm styles for FT branding
10
star
46

treecreeper

A set of tools for working with graph data - Not supported
JavaScript
10
star
47

ebi

🦐 Ebi: GitHub repositories contents search
JavaScript
9
star
48

structured-google-docs-client

A client library for fetching and transforming markup from Google Docs
JavaScript
9
star
49

n-gage

Shared developer and build tools for FT.com applications and components
Makefile
9
star
50

fec-donor-overlaps

Scripts and data used to generate donor overlap figures between 2020 and 2022 candidates in US elections, based off of FEC/ActBlue/WinRed data
Python
9
star
51

n-jsonp

❌Deprecated: This package is no longer maintained, consider using fetch() and CORS instead
JavaScript
9
star
52

n-auto-logger

a configurable logger decorator to automate function logs, compatible with winston, n-logger, n-mask-logger, etc.
JavaScript
9
star
53

scrumple

A fast (and scrappy) JavaScript bundler for developing Origami components.
Rust
9
star
54

coco-kafka-bridge

Kafka consumer forwarding messages to an HTTP endpoint.
Go
9
star
55

origami-build-service

Creates bundles of JavaScript and CSS from building Origami and Origami-compatible modules
JavaScript
8
star
56

content-k8s-provisioner

HTML
8
star
57

n-express

Slightly enhanced Express.
JavaScript
8
star
58

public-brands-api

Provides a public API for Brands stored in a Neo4J graph database
Go
8
star
59

yield-curve-sonification

An experiment to sonify the yield curve
JavaScript
8
star
60

internal-content-api

API for articles that should get the internal content
Go
8
star
61

babel-polyfill-silencer

Microlibrary for use by webpack to avoid babel implicitly importing core-js polyfills
JavaScript
8
star
62

aws-cf-elixir

AWS CloudFormation Templates for Elixir Build and Application Nodes
7
star
63

o-colors

Origami module containing color palette and use case Sass variables.
7
star
64

o-element-visibility

Element visibility tracking
JavaScript
7
star
65

o-table

Data table styling.
7
star
66

useragent_parser

JS and VCL implementation of uap-core
JavaScript
7
star
67

n-tracking

Client-side tracking initialisation and custom events for FT.com
JavaScript
7
star
68

police-misconduct-complaints-analysis

An analysis conducted for the May 28, 2021, Financial Times story "Small share of police draw third of complaints in big US cities"
Jupyter Notebook
7
star
69

n-ui

❌ DEPRECATED Server, build and client side bootstrapping for FT.com's user-facing applications.
JavaScript
7
star
70

o-crossword

An experimental Origami component to implement a responsive crossword.
JavaScript
6
star
71

kubectl-login

Logs you into multiple clusters which use dex
Go
6
star
72

o-tracking

Origami Tracking component
6
star
73

n-automation

Automated regression tests for your app
JavaScript
6
star
74

n-logger

Logging utility
JavaScript
6
star
75

o-ft-icons

Deprecated, please use o-icons instead
CSS
6
star
76

notifications-push

Proactively notifies subscribers about new content publishes/modifications.
Go
6
star
77

n-mask-logger

Version of @financial-times/n-logger that masks sensitive fields
JavaScript
6
star
78

ig-images-frontend

Web interface to upload images
JavaScript
6
star
79

upp-provisioners

Contains the various provisioning projects used by the Universal Publishing Platform
Shell
6
star
80

express-markdown-pages

An Express middleware that transforms plain text files into dynamic pages and fits right into your existing app.
JavaScript
6
star
81

fluent-logging

Fluent, splunk friendly logging
Java
6
star
82

g-deploy

Deploys IG pages to S3
TypeScript
5
star
83

tapper_plug

Plug integration for Tapper
Elixir
5
star
84

zipper-s3

App that is zipping up files from an S3 bucket and uploads the zip file back into the bucket.
Go
5
star
85

upp-aggregate-healthcheck

Aggregate healthcheck that is currently used for Kubernetes cluster
Go
5
star
86

next-metrics

A library for sending metrics to Graphite
JavaScript
5
star
87

coco-neo4j-backup

Docker Image for automated neo4j backups
Go
5
star
88

elasticsearch-reindexer

A tool for migrating data in an ElasticSearch index with updated mappings
Go
5
star
89

o-share

URL and social media sharing
5
star
90

o-header

FT branded page header for responsive sites
5
star
91

splunk-event-reader

Reads Splunk events via the Splunk REST API
Go
5
star
92

o-gallery

A gallery component for slideshows and carousels
JavaScript
5
star
93

express-web-service

Install FT Web Standard web service descriptions in an Express.js application
JavaScript
5
star
94

dotcom-reliability-kit

🪨 A well tested suite of tools designed to help FT.com applications be more reliable and measurable
JavaScript
5
star
95

n-swg

JS, Styles, Templates and utils for FT.com Subscribe with Google implementation
JavaScript
5
star
96

disable-tree-shaking-for-chunk-plugin

🌲 A Webpack plugin to disable tree shaking for all JS modules in the specified chunks.
JavaScript
5
star
97

cookiecutter-upp-golang

Go
5
star
98

next-json-ld

Helpers for producing schema.org markup in JSON LD on ft.com
JavaScript
5
star
99

golang-app-template

Template for golang apps with config reading and logging setup
Go
5
star
100

crypto-signatures

A library that provides capabilities to create cryptographic signatures and verify them.
Java
5
star