Skip to content

Commit

Permalink
Added ability to get branches for git and hg repos.
Browse files Browse the repository at this point in the history
Added blank configuration so the projects can be added and removed
correctly.
  • Loading branch information
abe545 committed Apr 28, 2014
1 parent f879fbb commit ac69d6a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="row-fluid">
</div>
7 changes: 7 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
app.controller('CodeplexController', ['$scope', function ($scope) {
$scope.config = $scope.providerConfig();

$scope.save = function () {
$scope.providerConfig($scope.config, function () {});
};
}]);
47 changes: 44 additions & 3 deletions lib/codeplex.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ac69d6a

Please sign in to comment.