Skip to content

Instantly share code, notes, and snippets.

@Lexicality
Created August 2, 2015 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lexicality/ad6e97ff59316bedd883 to your computer and use it in GitHub Desktop.
Save Lexicality/ad6e97ff59316bedd883 to your computer and use it in GitHub Desktop.
Github to Trello issue converter
/* 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