Created
August 2, 2015 12:18
-
-
Save Lexicality/ad6e97ff59316bedd883 to your computer and use it in GitHub Desktop.
Github to Trello issue converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint esnext: true, node: true */ | |
"use strict"; | |
import Q from 'q'; | |
import GithubAPI from 'github'; | |
import Trello from 'node-trello'; | |
// Top secret credentials | |
const trelloKey = ""; | |
const trelloToken = ""; | |
const githubToken = ""; | |
// El Clients | |
var trello = new Trello(trelloKey, trelloToken); | |
var github = new GithubAPI({ | |
version: "3.0.0", | |
}); | |
github.authenticate({ | |
type: "oauth", | |
token: githubToken | |
}); | |
// Might come in handy | |
const usernames = { | |
trello: "", | |
github: "" | |
}; | |
const boards = { | |
trello: "", | |
github: "" | |
}; | |
var githubIssues = Q.ninvoke(github.issues, "repoIssues", { | |
user: usernames.github, | |
repo: boards.github | |
}); | |
// githubIssues.then((issues) => { | |
// console.log("got issues:", issues[1]); | |
// }, (err) => { | |
// console.error("Unable to fetch issues: ", err); | |
// }); | |
var issue1 = githubIssues.then((issues) => issues[1]); | |
// var trelloBoard = Q.ninvoke(trello, "get", "/1/boards/" + boards.trello); | |
var trelloList = Q.ninvoke(trello, "get", "/1/boards/" + boards.trello + "/lists").then((lists) => lists[0].id); | |
var trelloLabels = Q.ninvoke(trello, "get", "/1/boards/" + boards.trello + "/labels") | |
.then((labels) => { | |
var ret = {}; | |
labels.forEach((label) => { | |
ret[label.name] = label.id; | |
}); | |
return ret; | |
}); | |
// trelloLabels.then((l) => console.dir(l)); | |
Q.spread([githubIssues, trelloList, trelloLabels], (issues, listID, trelloLabels) => { | |
return issues.map((issue) => { | |
var data = { | |
name: issue.title, | |
desc: issue.body, | |
idLabels: issue.labels.map((label) => { | |
var ret = trelloLabels[label.name]; | |
if (!ret) | |
throw new Error("Unknown label " + label.name + "!"); | |
return ret; | |
}).join(","), | |
idList: listID | |
}; | |
return Q.ninvoke(trello, "post", "/1/cards", data); | |
}); | |
}) | |
.all() | |
.then(() => console.log("It worked!"), (e) => console.error("damn", e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment