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.
$ npm install copy-github-labels
// 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');
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,
force: false,
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.
Once you have instantiated copyGitHubLabels
, you can use the following methods:
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 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)
});
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))
});
The default behavior copies labels from the source repo and adds them to the destination only if they do not already exist. Use
the force
option to update existing labels in the destination with their version from source.
// Define custom options
var options = {
// Force existing labels to update
force: true
};
// Instantiate with custom options
var copyGitHubLabels = require('copy-github-labels')(options);
- Add a
force
option. Withforce: true
, if a label already exists in the destination it will be updated with the source label.
- replaced deprecated Github package with Octokit rest.js (credits to Edric Chan)
- added support to copy label description (credits to Edric Chan)
- removed console.log statement
- added support for more than 30 labels
- reformatted source code
- updated documentation
- fix documentation
- added documentation
- added additional unit tests
- added support for obsolete callback
- added authentication support
- added documentation
- packaged as npm module