Easily copy GitHub labels from one repository to another. Uses GitHub API for Node.js.
$ npm install copy-github-labels
// Instantiate
var copyGitHubLabels = require('copy-github-labels')();
// Optionally use credentials
copyGitHubLabels.authenticate({
type: 'oauth',
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,
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
},
// Includes and excludes are both lists of regular expressions
// to match label names against
includes: ["type-bug", "severity-.*"],
excludes: ["repo-specific.*"]
});
// 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 = {
user: '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))
});
- remove 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