Skip to content

Commit

Permalink
Merge pull request #26 from fmaschler/update-github
Browse files Browse the repository at this point in the history
Update GitHub API
  • Loading branch information
spruce committed Nov 27, 2017
2 parents 46cffaa + acaf4c2 commit ca6effb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
49 changes: 18 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ if (settings.gitlab.projectID === null) {


var github = new GitHubApi({
// required
version: "3.0.0",
// optional
debug: false,
protocol: "https",
host: settings.github.url,
pathPrefix: settings.github.pathPrefix,
timeout: 5000,
followRedirects: true,
headers: {
"user-agent": "node-gitlab-2-github" // GitHub is happy with a unique user agent
"user-agent": "node-gitlab-2-github",// GitHub is happy with a unique user agent
'accept': 'application/vnd.github.v3+json',
}
});
github.authenticate({
Expand Down Expand Up @@ -206,27 +204,17 @@ function createAllIssuesAndComments(milestoneData, callback) {

function getAllGHMilestones(callback) {
github.issues.getMilestones({
user: settings.github.owner,
repo: settings.github.repo
}, function(err, milestoneDataOpen) {
owner: settings.github.owner,
repo: settings.github.repo,
state: 'all'
}, function(err, milestoneDataAll) {
if(err){
console.log(err);
console.log('getAllGHMilestones1');
console.log('FAIL!');
process.exit(1);
}
github.issues.getMilestones({
user: settings.github.owner,
repo: settings.github.repo,
state: 'closed'
}, function(err, milestoneDataClosed) {
if(err){
console.log(err);
console.log('getAllGHMilestones2');
console.log('FAIL!');
process.exit(1);
}
milestoneData = milestoneDataClosed.concat(milestoneDataOpen).map(function(item) {
milestoneData = milestoneDataAll.data.map(function(item) {
return {
number: item.number,
title: item.title
Expand All @@ -237,8 +225,7 @@ function getAllGHMilestones(callback) {
});
return callback(milestoneData, milestoneDataMapped);

}); // openMilestones
}); //closedMilestones
}); // Milestones

}

Expand All @@ -250,7 +237,7 @@ function getAllGHIssues(callback) {
return hasNext(lastItem)
}, function(cb) {
github.issues.getForRepo({
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
state: 'all',
per_page: 100,
Expand All @@ -276,7 +263,7 @@ function getAllGHIssues(callback) {

function getAllGHLabelNames(callback) {
github.issues.getLabels({
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
per_page: 100
}, function(err, labelData) {
Expand All @@ -286,7 +273,7 @@ function getAllGHLabelNames(callback) {
console.log('FAIL!');
process.exit(1);
}
var labelNames = labelData.map(function(item) {
var labelNames = labelData.data.map(function(item) {
return item.name;
});

Expand Down Expand Up @@ -321,7 +308,7 @@ function createIssueAndComments(item, callback) {
var props = null;
convertIssuesAndComments(item.description, item, function(bodyConverted) {
props = {
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
title: item.title.trim(),
body: bodyConverted
Expand Down Expand Up @@ -356,8 +343,8 @@ function createIssueAndComments(item, callback) {
console.log('props', props);
github.issues.create(props, function(err, newIssueData) {
if (!err) {
createAllIssueComments(settings.gitlab.projectID, item.id, newIssueData, function(err, issueData) {
makeCorrectState(newIssueData, item, callback);
createAllIssueComments(settings.gitlab.projectID, item.id, newIssueData.data, function(err, issueData) {
makeCorrectState(newIssueData.data, item, callback);
});
} else {
console.log('errData', err, newIssueData);
Expand All @@ -375,7 +362,7 @@ function makeCorrectState(ghIssueData, item, callback) {

// TODO get props
var props = {
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
number: ghIssueData.number,
state: 'closed',
Expand Down Expand Up @@ -412,7 +399,7 @@ function createAllIssueComments(projectID, issueID, newIssueData, callback) {
} else {
convertIssuesAndComments(item.body, item, function(bodyConverted) {
github.issues.createComment({
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
number: newIssueData.number,
body: bodyConverted
Expand All @@ -429,7 +416,7 @@ function createAllIssueComments(projectID, issueID, newIssueData, callback) {

function createMilestone(data, cb) {
github.issues.createMilestone({
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
title: data.title,
description: data.description,
Expand All @@ -440,7 +427,7 @@ function createMilestone(data, cb) {

function createLabel(glLabel, cb) {
github.issues.createLabel({
user: settings.github.owner,
owner: settings.github.owner,
repo: settings.github.repo,
name: glLabel.name,
color: glLabel.color.substr(1) // remove leading "#" because gitlab returns it but github wants the color without it
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"homepage": "https://github.com/piceaTech/node-gitlab-2-github#readme",
"dependencies": {
"async": "^1.4.0",
"github": "^3.0.0",
"gitlab": "^1.4.0"
"github": "^12.0.5",
"gitlab": "^1.7.1"
}
}

0 comments on commit ca6effb

Please sign in to comment.