From ac69d6abadb62cb25de9d64a7da28c0c537a271d Mon Sep 17 00:00:00 2001 From: abe545 Date: Mon, 28 Apr 2014 00:29:16 -0400 Subject: [PATCH] Added ability to get branches for git and hg repos. Added blank configuration so the projects can be added and removed correctly. --- config/config.html | 2 ++ config/config.js | 7 +++++++ lib/codeplex.js | 47 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 1 + webapp.js | 1 + 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/config/config.html b/config/config.html index e69de29..9c26cbc 100644 --- a/config/config.html +++ b/config/config.html @@ -0,0 +1,2 @@ +
+
\ No newline at end of file diff --git a/config/config.js b/config/config.js index e69de29..93d738c 100644 --- a/config/config.js +++ b/config/config.js @@ -0,0 +1,7 @@ +app.controller('CodeplexController', ['$scope', function ($scope) { + $scope.config = $scope.providerConfig(); + + $scope.save = function () { + $scope.providerConfig($scope.config, function () {}); + }; +}]); \ No newline at end of file diff --git a/lib/codeplex.js b/lib/codeplex.js index ae1e34b..1580b22 100644 --- a/lib/codeplex.js +++ b/lib/codeplex.js @@ -1,12 +1,53 @@ var https = require('https') - , TokenProvider = require('refresh-token'); + , TokenProvider = require('refresh-token') + , git = require('git-node'); module.exports = { getRepos: function(account, appConfig, callback) { getCodeplex(account, appConfig, '/api/user/projects', callback); }, - getAvailableHooks: function(account, appConfig, projectName, callback) { - getCodeplex(account, appConfig, '/api/projects/' + projectName + '/hooks', callback); + getBranches: function(account, config, callback) { + var sourceType = config.sourceType; + if (sourceType === 'git') { + var remote = git.remote(config.sourceUrl); + remote.discover(function(err, refs) { + if (err) { + callback(err, null); + } else { + remote.close(function(error) { + if (error) { + callback(error, null); + } else if (!refs) { + callback("No data returned for the repo.", null); + } else { + var branches = Object.keys(refs).filter(function (ref) { return ref.indexOf('refs/heads/') == 0; }).map(function (ref) { + return ref.replace('refs/heads/', ''); + }); + + callback(null, branches); + } + }); + } + }); + } else if (sourceType === 'mercurial') { + request(config.sourceUrl + '/branches?style=raw', function(error, response, body) { + if (error) return callback(error, null); + var branches = []; + var rows = rawText.split(/\r\n|\r|\n/g); + + // ignore the last row... it is always blank + for (var i = rows.length - 2; i >= 0; i--) { + var branchInfo = rows[i].split(/\t/g); + if (branchInfo[2] !== 'closed') { + branches.push(branchInfo[0]); + } + } + + callback(null, branches); + }); + } else { + callback("Only git and mercurial repos are supported at this time", null); + } } } diff --git a/package.json b/package.json index cdc02ea..7762dc6 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "license": "GPL-2.0", "readmeFilename": "Readme.md", "dependencies": { + "git-node": "0.1.1", "passport-oauth2": "1.x.x", "refresh-token": "0.0.2" }, diff --git a/webapp.js b/webapp.js index 2b6fb1f..75da0f9 100644 --- a/webapp.js +++ b/webapp.js @@ -67,6 +67,7 @@ module.exports = { }, getBranches: function (account, config, project, done) { + codeplex.getBranches(account, config, done); }, getFile: function (filename, ref, account, config, project, done) {