started to changed the code. Added tests.
This commit is contained in:
1 parent
3c8aafcbc2
commit
cfbf2aa42f
4 files changed
+94
-43
No files matched your search
@@ -1,6 +0,0 @@
|
||||
from mercurial import ui, hg, node
|
||||
from sys import argv
|
||||
|
||||
peer = hg.peer(ui.ui(), {}, argv[1])
|
||||
for name, rev in peer.branchmap().items():
|
||||
print(name)
|
||||
+63
-34
@@ -3,6 +3,7 @@ var gitane = require('gitane')
|
||||
, exec = require('child_process').exec
|
||||
, shellescape = require('shell-escape')
|
||||
, path = require('path')
|
||||
, fs = require('fs')
|
||||
, _ = require('underscore')
|
||||
|
||||
module.exports = {
|
||||
@@ -11,9 +12,29 @@ module.exports = {
|
||||
httpUrl: httpUrl,
|
||||
gitCmd: gitCmd,
|
||||
gitaneCmd: gitaneCmd,
|
||||
processBranches: processBranches,
|
||||
getBranches: getBranches,
|
||||
shellEscape: shellEscape
|
||||
shellEscape: shellEscape,
|
||||
Config: Config,
|
||||
Hg : Hg
|
||||
}
|
||||
|
||||
function Config(basedConfig){
|
||||
this.sanitizeConfig = function(config) {
|
||||
config = config || {};
|
||||
config.auth = config.auth || {};
|
||||
|
||||
this.url= config.url || "",
|
||||
this.display_url= config.display_url || "",
|
||||
this.auth = {
|
||||
type: config.auth.type || "",
|
||||
privkey: config.auth.privkey || "",
|
||||
pubkey: config.auth.pubkey || "",
|
||||
username: config.auth.username || "",
|
||||
password: config.auth.password || ""
|
||||
}
|
||||
}
|
||||
|
||||
this.sanitizeConfig(basedConfig);
|
||||
return this
|
||||
}
|
||||
|
||||
function shellEscape(one) {
|
||||
@@ -51,8 +72,6 @@ function gitCmd(cmd, cwd, auth, context, done) {
|
||||
}, done)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// run a strider command with gitane
|
||||
function gitaneCmd(cmd, dest, privkey, context, done) {
|
||||
var start = new Date()
|
||||
@@ -77,44 +96,54 @@ function gitaneCmd(cmd, dest, privkey, context, done) {
|
||||
})
|
||||
}
|
||||
|
||||
function processBranches(data, done) {
|
||||
done(null, data.trim().split(/\n+/).map(function (line) {
|
||||
return line.split(/\s+/)[1].split('/').slice(-1)[0]
|
||||
}))
|
||||
}
|
||||
function Hg(){
|
||||
this.getMercurialBranchesCommandLine = function(config){
|
||||
var repoLocation = config.url;
|
||||
var pythonScript = fs.realpathSync(path.join(__dirname, 'get_branches.py'));
|
||||
var cmd = 'python ' + pythonScript + " " + repoLocation;
|
||||
}
|
||||
|
||||
this.getNameOfMercurialBranchesOutOfScriptStdout = function(stdout){
|
||||
return _.filter(stdout.split("\n"),function(v){return !!v})
|
||||
}
|
||||
|
||||
this.getMercurialBranchesForHttpBasedReposetories = function(config, done){
|
||||
var cmd = this.getMercurialBranchesCommandLine(config);
|
||||
exec(cmd, function (err, stdout, stderr) {
|
||||
if (err){
|
||||
return done(err);
|
||||
}else{
|
||||
return done(this.getNameOfMercurialBranchesOutOfScriptStdout(stdout));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getBranches(config, privkey, done) {
|
||||
if (config.auth.type === 'ssh') {
|
||||
this.getMercurialBranchesForSshBasedReposetories = function(config, privkey, done){
|
||||
var cmd = this.getMercurialBranchesCommandLine(config);
|
||||
gitane.run({
|
||||
cmd: 'git ls-remote -h ' + gitUrl(config)[0],
|
||||
cmd: cmd,
|
||||
baseDir: '/',
|
||||
privKey: config.auth.privkey || privkey,
|
||||
detached: true
|
||||
}, function (err, stdout, stderr, exitCode) {
|
||||
if (err || exitCode !== 0) return done(err || new Error(stderr))
|
||||
processBranches(stdout, done)
|
||||
})
|
||||
} else {
|
||||
exec('git ls-remote -h ' + httpUrl(config)[0], function (err, stdout, stderr) {
|
||||
if (err) return done(err)
|
||||
processBranches(stdout, done)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getMercurialBranches(repoLocation){
|
||||
var pythonScript = path.join(__dirname, 'get_branches.py');
|
||||
var cmd = 'python ' + pythonScript + " " + repoLocation;
|
||||
exec(cmd, function (err, stdout, stderr) {
|
||||
if (err){
|
||||
return console.log(err)
|
||||
},
|
||||
function (err, stdout, stderr, exitCode) {
|
||||
if (err || exitCode !== 0){
|
||||
return done(err || new Error(stderr))
|
||||
}else{
|
||||
return console.log(_.filter(stdout.split("\n"),function(v){return !!v} ))
|
||||
return done(this.getNameOfMercurialBranchesOutOfScriptStdout(stdout));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.getMercurialBranches = function(config, privkey, done){
|
||||
if (config.auth.type === 'ssh') {
|
||||
privkey = config.auth.privkey || privkey;
|
||||
return this.getMercurialBranchesForSshBasedReposetories(config, privkey, done);
|
||||
}else{
|
||||
return this.getMercurialBranchesForHttpBasedReposetories(config, done);
|
||||
}
|
||||
}
|
||||
}
|
||||
getMercurialBranches('ssh://hg@bitbucket.org/ustraca/crypto')
|
||||
console.log("ok?")
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -20,8 +20,8 @@
|
||||
"license": "MIT",
|
||||
"readmeFilename": "Readme.md",
|
||||
"strider": {
|
||||
"id": "git",
|
||||
"title": "Git",
|
||||
"id": "hg",
|
||||
"title": "Hg",
|
||||
"type": "provider",
|
||||
"webapp": "webapp.js",
|
||||
"worker": "worker.js",
|
||||
@@ -32,7 +32,8 @@
|
||||
"gitane": "~0.3.1",
|
||||
"shell-escape": "0.0.1",
|
||||
"mkdirp": "~0.3.5",
|
||||
"underscore": "~1.5.2"
|
||||
"underscore": "~1.5.2",
|
||||
"expect.js": "~0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "~2.3.0",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
var expect = require('expect.js')
|
||||
, utils = require('../lib/index.js')
|
||||
|
||||
describe('The lib util interface', function () {
|
||||
describe('the Hg object', function () {
|
||||
it('should always pass', function(){
|
||||
expect(1).to.be(1);
|
||||
});
|
||||
var hg = new utils.Hg();
|
||||
it('should get the branched name from the script stdout', function () {
|
||||
var stdout = "a\nb\nc\n";
|
||||
expect(hg.getNameOfMercurialBranchesOutOfScriptStdout(stdout)).to.eql(["a", "b", "c"]);
|
||||
})
|
||||
})
|
||||
|
||||
describe('the config object', function(){
|
||||
it('should be able to initiate properly', function () {
|
||||
var config = new utils.Config();
|
||||
expect(config.url).to.eql("");
|
||||
expect(config.auth.username).to.eql("");
|
||||
config = new utils.Config({url: "1", auth: {username: "2"}});
|
||||
expect(config.url).to.eql("1");
|
||||
expect(config.auth.username).to.eql("2");
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user