npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

copy-github-labels

v2.0.0

Published

Easily copy labels from one GitHub repository to another

Downloads

15

Readme

Copy GitHub labels

Easily copy GitHub labels from one repository to another. Uses GitHub API for Node.js.

Build Status

octocat

If you want to copy GitHub labels from your command-line instead of from a script, check out copy-github-labels-cli.

Installation

$ npm install copy-github-labels

Example

// Instantiate
var copyGitHubLabels = require('copy-github-labels')();

// Optionally use credentials
copyGitHubLabels.authenticate({
  token: 'your-github-token'
});

// Copy labels from one repository to another
copyGitHubLabels.copy('github-username/src-repo', 'github-username/dest-repo');

Options

By default, copyGitHubLabels is configured to use GitHub, but you can optionally pass in an options object during instantiation:

// Define custom options
var options = {
  version: '3.0.0',
  debug: true,
  protocol: 'https',
  host: 'github.my-GHE-enabled-company.com',
  pathPrefix: '/api/v3', // for some GHEs
  timeout: 5000,
  headers: {
    'user-agent': 'My-Cool-GitHub-App', // GitHub is happy with a unique user agent
  }
});

// Instantiate with custom options
var copyGitHubLabels = require('copy-github-labels')(options);

All node-github API options are supported.

API

Once you have instantiated copyGitHubLabels, you can use the following methods:

authenticate(credentials)

Specify credentials to use when connecting to GitHub:

// Use basic auth
copyGitHubLabels.authenticate({
  type: 'basic',
  username: 'mikedeboertest',
  password: 'test1324'
});

// Or use oauth
copyGitHubLabels.authenticate({
  type: 'oauth',
  token: 'e5a4a27487c26e571892846366de023349321a73'
});

// Or use oauth key/ secret
copyGitHubLabels.authenticate({
  type: 'oauth',
  key: 'clientID',
  secret: 'clientSecret'
});

// Or use a token
copyGitHubLabels.authenticate({
  type: 'token',
  token: 'userToken',
});

copy(source, destination[, callback])

Copy labels from one repository to another:

// A repo can be a string
var source = 'github-username/repo-name';

// Or an object
var destination = {
  owner: 'github-username',
  repo: 'repo-name'
};

// Copy labels from one repository to another
copyGitHubLabels.copy(source, destination, function (err, label){

  // Handle errors
  if(err){
  	return console.log('Could not copy label: ' + err);
  }

  // Copy succeeded
  console.log('Label copied successfully: ' + label)
});

Dry runs

There is a special option called dryRun to perform a test run without actually copying the labels.

This is convenient if you want to check if the correct labels are coming in before performing the actual copy:

// Define custom options
var options = {

  // Dry run is a special option that allows us to perform
  // a test run without actually copying the labels.
  dryRun: true
};

// Instantiate with custom options
var copyGitHubLabels = require('copy-github-labels')(options);

// Define source and destination
var source = 'jvandemo/copy-github-labels';
var destination = 'your-username/your-repo';

// Copy labels from one repository to another
// The callback is called for every label but no actual
// copy operation is performed, so the destination repository is not updated.
copyGitHubLabels.copy(source, destination, function (err, label){

  // Log errors
  if(err){
    return console.log('Could not copy label: ' + JSON.stringify(err));
  }

  // Log copies
  console.log('Label copied successfully: ' + JSON.stringify(label))
});

Change log

v2.0.0

v1.3.1

  • removed console.log statement

v1.3.0

  • added support for more than 30 labels
  • reformatted source code
  • updated documentation

v1.2.1

  • fix documentation

v1.2.0

  • added documentation
  • added additional unit tests

v1.1.0

  • added support for obsolete callback

v1.0.0

  • added authentication support
  • added documentation
  • packaged as npm module