2.2.0 • Published 3 years ago

copy-github-labels-reloaded v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Copy GitHub labels

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

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

Installation

$ npm install copy-github-labels-reloaded

Example

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

// 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-reloaded')(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))
});
2.2.0

3 years ago

2.1.0

3 years ago