This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'tom/JENKINS-36177' into JENKINS-36660
- Loading branch information
Showing
5 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node { | ||
stage 'Stage 1' | ||
echo 'Stage 1' | ||
sleep 5 | ||
stage 'Stage 2' | ||
echo 'Stage 2' | ||
sleep 5 | ||
} |