Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'tom/JENKINS-36177' into JENKINS-36660
Browse files Browse the repository at this point in the history
  • Loading branch information
scherler committed Aug 23, 2016
2 parents 805d74b + ae0e57d commit 97f2d75
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -28,6 +28,8 @@
"phantomjs-prebuilt": "2.1.7",
"request": "2.72.0",
"util": "0.10.3",
"xmlhttprequest": "1.8.0"
"xmlhttprequest": "1.8.0",
"fs-extra": "^0.30.0",
"nodegit": "^0.13.2"
}
}
110 changes: 110 additions & 0 deletions src/main/js/api/git.js
@@ -0,0 +1,110 @@
var NodeGit = require("nodegit");
var fse = require('fs-extra');
var path = require("path");

exports.init = function(pathToRepo, onInit) {
var pathToRepo = path.resolve(pathToRepo);

fse.emptyDirSync(pathToRepo);
NodeGit.Repository.init(pathToRepo, 0)
.then(function (repo) {
var signature = NodeGit.Signature.default(repo);
var initIndex;

repo.refreshIndex()
.then(function (index) {
initIndex = index;
return index.write();
})
.then(function (index) {
return initIndex.writeTree();
})
.then(function (oid) {
return repo.createCommit("HEAD", signature, signature, 'initial commit', oid, []);
})
.done(function() {
if (onInit) {
onInit({
repo: repo,
copyDirToRepo: function(dir) {
var pathToFiles = path.resolve(dir);

if (!fse.existsSync(pathToFiles)) {
throw new Error('No such directory: ' + pathToFiles);
}
if (!fse.statSync(pathToFiles).isDirectory()) {
throw new Error('Not a directory: ' + pathToFiles);
}

fse.copySync(pathToFiles, pathToRepo);
},
commit: function (message) {
if (!message) {
message = 'commit all';
}

var index;
var oid;
var returnPromise = repo.refreshIndex()
.then(function (indexResult) {
index = indexResult;
})
.then(function () {
return index.addAll();
})
.then(function () {
return index.write();
})
.then(function () {
return index.writeTree();
})
.then(function (oidResult) {
oid = oidResult;
return NodeGit.Reference.nameToId(repo, "HEAD");
})
.then(function (head) {
return repo.getCommit(head);
})
.then(function (parent) {
return repo.createCommit("HEAD", signature, signature, message, oid, [parent]);
});

return returnPromise;
},
createRepo: function(fromDir, inDir) {
repo.copyDirToRepo(fromDir);
return repo.commit('Added ');
}
});
}
});

});
};

exports.createRepo = function(fromDir, inDir) {
return new Promise(function(resolve, reject) {
exports.init(inDir, function (repo) {
repo.copyDirToRepo(fromDir);
repo.commit('Copied files from ' + fromDir)
.then(resolve)
.catch(reject);
});
});
};

exports.createBranch = function(branchName, pathToRepo) {
var pathToRepo = path.resolve(pathToRepo);

return NodeGit.Repository.open(pathToRepo)
.then(function(repo) {
return repo.getHeadCommit()
.then(function (commit) {
return repo.createBranch(
branchName,
commit, 0,
repo.defaultSignature(),
'Created "' + branchName + '" branch on HEAD');
});
});
};
38 changes: 38 additions & 0 deletions src/test/java/io/jenkins/blueocean/MultibranchTest.java
@@ -0,0 +1,38 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.jenkins.blueocean;

import org.jenkinsci.test.acceptance.junit.WithPlugins;

/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
@WithPlugins({"workflow-aggregator@2.1"})
public class MultibranchTest extends NightwatchTest {


public MultibranchTest() {
super("multibranch.js");
}
}
21 changes: 21 additions & 0 deletions src/test/js/multibranch.js
@@ -0,0 +1,21 @@
const git = require('../../main/js/api/git');
const path = require("path");

const pathToRepo = path.resolve('./target/test-project');

console.log('*** ' + pathToRepo);

module.exports = {
beforeEach: function (browser, done) {
git.createRepo('./src/test/resources/multibranch_1', pathToRepo)
.then(function() {
git.createBranch('feature-1', pathToRepo)
.then(done);
});
},

'Create Multbranch Job': function (browser) {
console.log('*** test!!');
browser.end();
}
};
8 changes: 8 additions & 0 deletions src/test/resources/multibranch_1/Jenkinsfile
@@ -0,0 +1,8 @@
node {
stage 'Stage 1'
echo 'Stage 1'
sleep 5
stage 'Stage 2'
echo 'Stage 2'
sleep 5
}

0 comments on commit 97f2d75

Please sign in to comment.