withspectrum/danger-plugin-labels

Name: danger-plugin-labels

Owner: Spectrum

Description: Let any contributor add labels to their PRs and issues

Created: 2018-03-16 13:28:37.0

Updated: 2018-04-24 15:07:37.0

Pushed: 2018-03-23 11:53:56.0

Homepage:

Size: 92

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

danger-plugin-labels

Build Status npm version

Let any contributor add labels to their pull requests and issues

Usage

Install:

 add danger-plugin-labels --dev

At a glance:

angerfile.js
rt { schedule } from 'danger'
rt labels from 'danger-plugin-labels'

dule(labels({
les: [
{ match: /WIP/i, label: 'Work In Progress' },
{ match: /Ready for Review/i, label: 'Ready for Review' }


arkdown
 PULL_REQUEST_TEMPLATE.md -->

atus (check one)**

] WIP
] Ready for Review

Now contributors even without write access to the repo can label their PR as “Work In Progress” and “Ready for Review”!

Note: There is experimental issue support if you're using Peril and point the issue event hook to your Dangerfile. No guarantees it won't break though!

Options
rules (required)

Rules lets you specify which labels to apply depending on which checkboxes are ticked:

dule(labels({
 A checked box with "WIP" will apply the "Work In Progress" label
les: [{
match: /WIP/i,
label: "Work In Progress"


Because it's tedious to repeat the same string twice if the label matches the checkbox, you can also provide the shorthand notation:

dule(labels({
 A checked box with "WIP" will apply the "WIP" label
les: ["WIP"]

Note: The checkbox text in this case is case insensitive (wip, Wip and WIP in the markdown would all apply the label), but the label content isn't. (GitHub treats “WIP” as a separate label than “wip”, make sure to match the text exactly!)

validate

A function that's called with all the matching labels, allowing you to accept or reject them by returnng true or false, respectively. This is useful for a number of things, for example to limit the maximum number of labels selected:

rt { fail } from 'danger';

dule(labels({
les: [/* ... */],
lidate: (labels) => {
if (labels.length < 1 || labels.length > 3) {
  fail('Please specify at least one and at most 3 labels.');
  return false;
}

return true;


This method can also be asynchronous so you can do all sorts of cool stuff, like close issues that users want to label as questions:

rt { fail } from 'danger';

dule(labels({
les: [/* ... */],
lidate: async (labels) => {
if (labels.includes('Question')) {
  fail('Please direct questions to the community on Spectrum.')
  await closeIssue();
  return false;
}
return true;


Changelog

See the GitHub release history.

Contributing

See CONTRIBUTING.md.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.