Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit f0e2de50360ce5979b9b39047a22147ab0a82b04 0 parents
Jamie Forrest authored
15 .gitignore
@@ -0,0 +1,15 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
1  Procfile
@@ -0,0 +1 @@
+web: node app.js
27 README.md
@@ -0,0 +1,27 @@
+github-asana
+============
+
+github-asana is a little web server written in node.js that integrates GitHub with Asana (the project management app).
+The server listens for GitHub Post-Receive Hooks, and sends commit messages as comments in Asana Tasks.
+
+http://asana.com/
+
+Installation
+============
+To get it up and running, open up the lib/github-asana.js file and update the asana_key variable with your Asana API key.
+Then host the app somewhere (heroku is easiest) and provide the url to the app in the "Service Hooks / WebHook URLs" section of the GitHub repository you want to integrate with Asana (the app receives GitHub's POST requests at the base url or '/').
+
+Commit Syntax
+=============
+For now, the only thing supported is referencing Asana task IDs in your commit messages (prefixed by a #). When you commit, write something like:
+
+ git commit -m "fixed bug #123456789"
+
+That will send the commit message to Asana and place it as a comment in the task with ID 123456789.
+Task IDs in Asana are the strings of digits after the final slash in the url, visible when you're viewigin a task.
+
+Roadmap
+=======
+In the future, we will be adding the ability to assign tasks and add tags to tasks, with syntax such as:
+
+ git commit -m "fixed bug #123456789 to:user@example.com tags:'in progress','feedback'"
34 app.js
@@ -0,0 +1,34 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , github_asana = require('./lib/github-asana');
+
+var app = module.exports = express.createServer();
+
+// Configuration
+
+app.configure(function(){
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ app.use(express.errorHandler());
+});
+
+// Routes
+
+app.post('/', github_asana.index);
+
+var port = process.env.PORT || 3000;
+app.listen(port, function() {
+ console.log("Listening on " + port);
+});
52 lib/github-asana.js
@@ -0,0 +1,52 @@
+var util = require('util');
+var request = require('request');
+var asana_key = "your-asana-api-key";
+var asana_base_url = 'https://app.asana.com/api/1.0';
+
+function getTaskComments(req) {
+ var payload;
+ if (typeof req.body.payload === 'object') {
+ payload = req.body.payload;
+ } else {
+ payload = JSON.parse(req.body.payload);
+ }
+ var commits = payload.commits;
+ var comments = [];
+ for (var i in commits) {
+ var regex = /#(\d+)\b/g;
+ var tasks = commits[i].message.match(/#(\d+)\b/g);
+ if (tasks) {
+ for (var j in tasks) {
+ comments.push({
+ "id":tasks[j].slice(1),
+ "text":commits[i].author.username + ' referenced this issue from a commit\n'+commits[i].id.slice(0,7)+' '+commits[i].message+'\n'+commits[i].url
+ });
+ }
+ }
+ }
+ return comments;
+}
+
+function updateAsana(taskComments) {
+ var auth = 'Basic ' + new Buffer(asana_key+":").toString('base64');
+ for (var i in taskComments) {
+ request.post({
+ url: asana_base_url+"/tasks/"+taskComments[i].id+"/stories",
+ json: {data: {text:taskComments[i].text}},
+ headers: {"Authorization":auth}
+ },
+ function (error, response, body) {
+ if (!error && response.statusCode == 200) {
+ console.log(body)
+ } else {
+ console.log(response.statusCode+': '+error);
+ console.log(util.inspect(response.body));
+ }
+ })
+ }
+}
+
+exports.index = function(req, res){
+ updateAsana(getTaskComments(req));
+ res.send("Updated Asana.");
+};
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "github-asana"
+ , "version": "0.0.1"
+ , "private": false
+ , "dependencies": {
+ "express": "2.5.8"
+ , "jade": ">= 0.0.1"
+ , "request": ">= 2.9.202"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.