Skip to content

Commit

Permalink
refactor(global): reformat source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandemo committed May 1, 2015
1 parent 7ffa5b1 commit dc7c696
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 115 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
160 changes: 81 additions & 79 deletions lib/copy-github-labels.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
|
/**
* Module dependencies
*/
Expand All @@ -6,71 +7,72 @@ var extend = require('extend');

module.exports = function (opts) {

// Create object to export
var self = {};

var defaultOptions = {
// required
version: "3.0.0",
// optional
debug: false,
protocol: "https",
host: "api.github.com",
timeout: 5000,
headers: {
"user-agent": "Copy-GitHub-Labels" // GitHub is happy with a unique user agent
}
};

var options = extend({}, defaultOptions, opts);

self.github = new GitHubApi(options);

self.authenticate = function (credentials) {
self.github.authenticate(credentials);
};

self.copy = function (sourceRepository, destinationRepository, cb) {

sourceRepository = parseRepo(sourceRepository);
destinationRepository = parseRepo(destinationRepository);
cb = cb || function(){};

if (!sourceRepository) {
return cb(new Error('Invalid source repository'));
}

if (!destinationRepository) {
return cb(new Error('Invalid destination repository'));
}

// Get all labels from source
self.github.issues.getLabels(sourceRepository, function (err, labels) {

if (err) {
return cb(err);
}

labels.forEach(function (label) {

// Create label in destination repository
self.github.issues.createLabel({
user: destinationRepository.user,
repo: destinationRepository.repo,
name: label.name,
color: label.color
}, function (err, res) {
if (err) {
return cb(err);
}
return cb(null, res);
});

})
});
};

return self;
// Create object to export
var self = {};

var defaultOptions = {
// required
version: "3.0.0",
// optional
debug: false,
protocol: "https",
host: "api.github.com",
timeout: 5000,
headers: {
"user-agent": "Copy-GitHub-Labels" // GitHub is happy with a unique user agent
}
};

var options = extend({}, defaultOptions, opts);

self.github = new GitHubApi(options);

self.authenticate = function (credentials) {
self.github.authenticate(credentials);
};

self.copy = function (sourceRepository, destinationRepository, cb) {

sourceRepository = parseRepo(sourceRepository);
destinationRepository = parseRepo(destinationRepository);
cb = cb || function () {
};

if (!sourceRepository) {
return cb(new Error('Invalid source repository'));
}

if (!destinationRepository) {
return cb(new Error('Invalid destination repository'));
}

// Get all labels from source
self.github.issues.getLabels(sourceRepository, function (err, labels) {

if (err) {
return cb(err);
}

labels.forEach(function (label) {

// Create label in destination repository
self.github.issues.createLabel({
user: destinationRepository.user,
repo: destinationRepository.repo,
name: label.name,
color: label.color
}, function (err, res) {
if (err) {
return cb(err);
}
return cb(null, res);
});

})
});
};

return self;

};

Expand All @@ -91,18 +93,18 @@ module.exports = function (opts) {
* @returns {*}
*/
function parseRepo(input) {
if (typeof input === 'string') {
var parts = input.split('/');
if (parts.length < 2) {
return null;
}
return {
user: parts[0],
repo: parts[1]
}
}
if (input.user && input.repo) {
return input;
}
return null;
if (typeof input === 'string') {
var parts = input.split('/');
if (parts.length < 2) {
return null;
}
return {
user: parts[0],
repo: parts[1]
}
}
if (input.user && input.repo) {
return input;
}
return null;
}
72 changes: 36 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{
"name": "copy-github-labels",
"version": "1.2.1",
"description": "Easily copy labels from one GitHub repository to another",
"main": "index.js",
"dependencies": {
"extend": "^2.0.0",
"github": "^0.2.3"
},
"devDependencies": {
"chai": "^1.10.0",
"mocha": "^2.0.1"
},
"scripts": {
"test": "mocha test/*.js"
},
"repository": {
"type": "git",
"url": "https://github.com/jvandemo/copy-github-labels.git"
},
"keywords": [
"git",
"github",
"labels",
"issues",
"copy"
],
"author": {
"name": "Jurgen Van de Moere",
"email": "jurgen.van.de.moere@gmail.com",
"url": "http://www.jvandemo.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/jvandemo/copy-github-labels/issues"
},
"homepage": "https://github.com/jvandemo/copy-github-labels"
"name": "copy-github-labels",
"version": "1.2.1",
"description": "Easily copy labels from one GitHub repository to another",
"main": "index.js",
"dependencies": {
"extend": "^2.0.0",
"github": "^0.2.3"
},
"devDependencies": {
"chai": "^1.10.0",
"mocha": "^2.0.1"
},
"scripts": {
"test": "mocha test/*.js"
},
"repository": {
"type": "git",
"url": "https://github.com/jvandemo/copy-github-labels.git"
},
"keywords": [
"git",
"github",
"labels",
"issues",
"copy"
],
"author": {
"name": "Jurgen Van de Moere",
"email": "jurgen.van.de.moere@gmail.com",
"url": "http://www.jvandemo.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/jvandemo/copy-github-labels/issues"
},
"homepage": "https://github.com/jvandemo/copy-github-labels"
}

0 comments on commit dc7c696

Please sign in to comment.