diff --git a/public/partials/site-overview.html b/public/partials/site-overview.html
index e16cab0..629ad2e 100644
--- a/public/partials/site-overview.html
+++ b/public/partials/site-overview.html
@@ -18,15 +18,17 @@
MySQL (db: {{site.dbConfig.database}},
host: {{site.dbConfig.host}}, user: {{site.dbConfig.user}})
- Staging:
- This is the staging site of {{site.stagingOf}}.
+ Staging:
+ This is the staging site of {{site.stagingOf}}.
+ Merge Request:
+ This is the site for merge request of branch {{site.sourceBranch}} into site {{site.stagingOf}}.
Links:
tasks
backups
-
+
diff --git a/src/server.js b/src/server.js
index b03dc43..4747d1e 100644
--- a/src/server.js
+++ b/src/server.js
@@ -11,7 +11,7 @@ require('q').longStackSupport = true;
expressValidator.validator.extend('isIdentifier', function (str) {
if (typeof str != 'string')
return false;
- return str.match(/[a-zA-Z0-9_\-\.]+/) !== null;
+ return str.match(/[a-zA-Z0-9\-]+/) !== null;
});
exports.start = function(port, dir) {
@@ -56,6 +56,31 @@ exports.start = function(port, dir) {
res.json({taskID: task.id});
});
+ app.post('/api/gitlab-merge-request', function(req, res) {
+ if (req.body.object_kind != 'merge_request') {
+ return res.send('Only merge_request events supported', 400);
+ }
+
+ if (req.body.object_attributes.action != 'open') {
+ return res.send('Only considering "open" events', 200);
+ }
+
+ req.checkBody('object_attributes.source_branch').isIdentifier();
+ req.checkBody('object_attributes.target_branch').isIdentifier();
+ var errors = req.validationErrors();
+ if (errors) {
+ return res.send('Validation errors: ' + JSON.stringify(errors), 400);
+ }
+
+ var sourceBranch = req.body.object_attributes.source_branch;
+ var targetBranch = req.body.object_attributes.target_branch;
+
+ var task = controller.manager.createMergeRequestSiteTask(sourceBranch, targetBranch);
+ controller.manager.schedule(task);
+
+ res.json({taskID: task.id});
+ });
+
app.post('/api/reload', function(req, res) {
controller.reload();
res.send(202 /* accepted */);
diff --git a/src/site.js b/src/site.js
index 3892922..e51767f 100644
--- a/src/site.js
+++ b/src/site.js
@@ -43,8 +43,8 @@ Site.prototype.upgradeTask = function() {
return new UpgradeSiteTask(this);
};
-Site.prototype.upgradeToRevisionTask = function(revision) {
- return new UpgradeToRevisionTask(this, revision);
+Site.prototype.upgradeToRevisionTask = function(revision, allowNonFastForward) {
+ return new UpgradeToRevisionTask(this, revision, allowNonFastForward);
};
Site.prototype.backupTask = function(message) {
diff --git a/src/siteManager.js b/src/siteManager.js
index a9f500f..a9cad70 100644
--- a/src/siteManager.js
+++ b/src/siteManager.js
@@ -4,6 +4,7 @@ var FetchTask = require('./tasks/fetch.js');
var LoadSiteManagerTask = require('./tasks/loadSiteManager.js');
var AddSiteTask = require('./tasks/addSite.js');
var DeleteSiteTask = require('./tasks/deleteSite.js');
+var CreateMergeRequestSiteTask = require('./tasks/createMergeRequestSite.js');
var Config = require('./config.js');
// Register common hooks
@@ -36,6 +37,10 @@ SiteManager.prototype.deleteSiteTask = function(site) {
return new DeleteSiteTask(this, site);
};
+SiteManager.prototype.createMergeRequestSiteTask = function(sourceBranch, targetBranch) {
+ return new CreateMergeRequestSiteTask(this, sourceBranch, targetBranch)
+};
+
SiteManager.prototype.getSite = function(siteName) {
for (var i = 0; i < this.sites.length; i++) {
if (this.sites[i].name == siteName)
diff --git a/src/tasks/addSite.js b/src/tasks/addSite.js
index 84a25e6..350df8d 100644
--- a/src/tasks/addSite.js
+++ b/src/tasks/addSite.js
@@ -105,6 +105,8 @@ AddSiteTask.prototype.perform = function*() {
yield site.loaded;
yield hooks.call('afterCreate', this, site);
yield hooks.call('afterCheckout', this, site);
+
+ return site;
};
module.exports = AddSiteTask;
diff --git a/src/tasks/createMergeRequestSite.js b/src/tasks/createMergeRequestSite.js
new file mode 100644
index 0000000..e88fe58
--- /dev/null
+++ b/src/tasks/createMergeRequestSite.js
@@ -0,0 +1,41 @@
+var Task = require('../task.js');
+var fs = require('q-io/fs');
+var Q = require('q');
+var yaml = require('js-yaml');
+
+function CreateMergeRequestSiteTask(siteManager, sourceBranch, targetBranch) {
+ Task.call(this);
+ this.siteManager = siteManager;
+ this.sourceBranch = sourceBranch;
+ this.targetBranch = targetBranch;
+ this.name = 'Create Site for Merge Request from ' + sourceBranch + ' into ' + targetBranch;
+}
+
+CreateMergeRequestSiteTask.prototype = Object.create(Task.prototype);
+
+CreateMergeRequestSiteTask.prototype.perform = function*() {
+ var manager = this.siteManager;
+ var siteName = 'mr-' + this.sourceBranch;
+
+ if (!(this.targetBranch in manager.siteBranchMapping)) {
+ throw new Error('siteBranchMapping config does not contain the site for branch ' + this.targetBranch);
+ }
+ var targetSiteName = manager.siteBranchMapping[this.targetBranch];
+
+ var site = yield this.runNested(manager.addSiteTask(siteName, this.targetBranch));
+
+ this.doLog('Configuring site: isMergeRequest: true, sourceBranch: ' + this.sourceBranch +
+ ', stagingOf: ' + targetSiteName);
+ var sites = yaml.safeLoad(yield fs.read(manager.path + '/sites.yaml'));
+ sites[site.name].isMergeRequestSite = true;
+ sites[site.name].sourceBranch = this.sourceBranch;
+ sites[site.name].stagingOf = targetSiteName;
+ yield fs.write(manager.path + '/sites.yaml', yaml.safeDump(sites));
+
+ yield this.runNested(manager.loadTask());
+ var upgradeTask = site.upgradeTask();
+ site.schedule(upgradeTask);
+ yield upgradeTask;
+};
+
+module.exports = CreateMergeRequestSiteTask;
diff --git a/src/tasks/loadSite.js b/src/tasks/loadSite.js
index 7e20ccc..036f77b 100644
--- a/src/tasks/loadSite.js
+++ b/src/tasks/loadSite.js
@@ -18,11 +18,20 @@ LoadSiteTask.prototype.perform = function*() {
yield this.exec("git fetch");
this.site.revision = (yield this.exec("git rev-parse HEAD")).stdout.trim();
- this.site.branch = (yield this.exec("git rev-parse --abbrev-ref HEAD")).stdout.trim();
+ if (this.site.isMergeRequestSite) {
+ // this site should be upgraded when sourceBranch changes
+ this.site.branch = this.site.sourceBranch;
+ } else {
+ this.site.branch = (yield this.exec("git rev-parse --abbrev-ref HEAD")).stdout.trim();
+ }
if (this.site.branch == 'HEAD') {
this.site.branch = ''; // this happens when no branch is checked out
}
- if (this.site.branch) {
+ if (this.site.isMergeRequestSite) {
+ this.site.upstreamRevision = (yield this.exec("git rev-parse origin/" + this.site.sourceBranch)).stdout.trim();
+ this.site.aheadBy = 0; // not really useful because we are always ahead by the merge commit
+ this.site.behindBy = yield this._getCommitCountBetween('HEAD', 'origin/' + this.site.sourceBranch);
+ } else if (this.site.branch) {
this.site.upstreamRevision = (yield this.exec("git rev-parse origin/" + this.site.branch)).stdout.trim();
this.site.aheadBy = yield this._getCommitCountBetween('origin/' + this.site.branch, this.site.branch);
this.site.behindBy = yield this._getCommitCountBetween(this.site.branch, 'origin/' + this.site.branch);
diff --git a/src/tasks/loadSiteManager.js b/src/tasks/loadSiteManager.js
index 42cdcd2..eb1304d 100644
--- a/src/tasks/loadSiteManager.js
+++ b/src/tasks/loadSiteManager.js
@@ -50,6 +50,7 @@ LoadSiteManagerTask.prototype.perform = function*() {
manager.ownURL = config.ownURL || 'http://localhost:8888/';
manager.mailConfig = config.mail || { transport: 'sendmail', sender: 'Site Manager ' };
manager.config = config;
+ manager.siteBranchMapping = config.siteBranchMapping || {};
var sites = yaml.safeLoad(yield fs.read(manager.path + '/sites.yaml'));
@@ -79,6 +80,8 @@ LoadSiteManagerTask.prototype.perform = function*() {
site.watchers = globalWatchers.concat(siteConfig.watchers || []);
site.ownURL = manager.ownURL + '#/sites/' + site.name;
site.stagingOf = siteConfig.stagingOf;
+ site.isMergeRequestSite = siteConfig.isMergeRequestSite;
+ site.sourceBranch = siteConfig.sourceBranch;
if (this.loadSites || existingSites.length == 0 /* always load new sites */)
site.schedule(site.loadTask());
diff --git a/src/tasks/upgradeSite.js b/src/tasks/upgradeSite.js
index cdf305d..b7f1827 100644
--- a/src/tasks/upgradeSite.js
+++ b/src/tasks/upgradeSite.js
@@ -33,10 +33,16 @@ UpgradeSiteTask.prototype.perform = function*() {
yield this.runNested(site.resetStagingTask( { backup: false }));
}
- this.doLog('Pulling incoming commits...');
- yield this.exec('git pull --ff-only');
+ if (this.site.isMergeRequestSite) {
+ this.doLog('Merging source branch ' + this.site.sourceBranch + '...');
+ yield this.exec('git merge --no-ff origin/' + this.site.sourceBranch);
+ this.doLog('Merge completed');
+ } else {
+ this.doLog('Pulling incoming commits...');
+ yield this.exec('git pull --ff-only');
+ this.doLog('Pull completed');
+ }
- this.doLog('Pull completed');
yield this.runNestedQuietly(site.loadTask());
yield hooks.call('afterPull', this, site);
diff --git a/src/tasks/upgradeToRevision.js b/src/tasks/upgradeToRevision.js
index 87f015f..625d01b 100644
--- a/src/tasks/upgradeToRevision.js
+++ b/src/tasks/upgradeToRevision.js
@@ -5,11 +5,12 @@ var hooks = require('../hooks.js');
/**
* Upgrades a site to a specific revision
*/
-function UpgradeToRevisionTask(site, revision) {
+function UpgradeToRevisionTask(site, revision, allowNonFastForward) {
Task.call(this);
this.site = site;
this.name = 'Upgrade to ' + revision;
this.revision = revision;
+ this.allowNonFastForward = allowNonFastForward;
}
UpgradeToRevisionTask.prototype = Object.create(Task.prototype);
@@ -23,11 +24,12 @@ UpgradeToRevisionTask.prototype.perform = function*() {
var commitsAhead = yield countCommitsBetween(this, 'HEAD', this.revision);
var commitsBehind = yield countCommitsBetween(this, this.revision, 'HEAD');
- if (commitsBehind > 0) {
+ if (commitsBehind > 0 && !this.allowNonFastForward) {
throw new Error('The upgrade is not fast-forward, this site is ' +
commitsBehind + ' commits ahead of ' + this.revision + '. To go back to ' +
'an older version, either restore a backup or do a git revert.');
}
+ var needToMerge = commitsBehind > 0;
if (commitsAhead == 0) {
this.doLog('Already up-to-date.');
@@ -40,8 +42,13 @@ UpgradeToRevisionTask.prototype.perform = function*() {
var oldRevision = site.revision;
try {
- this.doLog('Checking ot new revision...');
- yield this.exec('git checkout ' + this.revision);
+ if (needToMerge) {
+ this.doLog('Merging new revision...');
+ yield this.exec('git merge ' + this.revision);
+ } else {
+ this.doLog('Checking out new revision...');
+ yield this.exec('git checkout ' + this.revision);
+ }
yield this.runNestedQuietly(site.loadTask());
yield hooks.call('afterPull', this, site);
diff --git a/test/resources/remote.git/objects/08/1141e350ff8332ca801799bccb401d4336f2c4 b/test/resources/remote.git/objects/08/1141e350ff8332ca801799bccb401d4336f2c4
new file mode 100644
index 0000000..4b55f68
--- /dev/null
+++ b/test/resources/remote.git/objects/08/1141e350ff8332ca801799bccb401d4336f2c4
@@ -0,0 +1 @@
+xMj0@uFRMI3"r +m] I-L5Tmv.=ya+2;u j9J-I|26Zgt6}Zor&jB}=W NDŽVoR]{oOUwVBIr
\ No newline at end of file
diff --git a/test/resources/remote.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff b/test/resources/remote.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff
new file mode 100644
index 0000000..7a9b019
Binary files /dev/null and b/test/resources/remote.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff differ
diff --git a/test/resources/remote.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05 b/test/resources/remote.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05
new file mode 100644
index 0000000..494047e
Binary files /dev/null and b/test/resources/remote.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05 differ
diff --git a/test/resources/remote.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd b/test/resources/remote.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd
new file mode 100644
index 0000000..f4ca869
Binary files /dev/null and b/test/resources/remote.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd differ
diff --git a/test/resources/remote.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8 b/test/resources/remote.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8
new file mode 100644
index 0000000..a0d4a78
Binary files /dev/null and b/test/resources/remote.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8 differ
diff --git a/test/resources/remote.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f b/test/resources/remote.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f
new file mode 100644
index 0000000..389a0c0
Binary files /dev/null and b/test/resources/remote.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f differ
diff --git a/test/resources/remote.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c b/test/resources/remote.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c
new file mode 100644
index 0000000..722b195
Binary files /dev/null and b/test/resources/remote.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c differ
diff --git a/test/resources/remote.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001 b/test/resources/remote.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001
new file mode 100644
index 0000000..8d7fe6a
Binary files /dev/null and b/test/resources/remote.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001 differ
diff --git a/test/resources/remote.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7 b/test/resources/remote.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7
new file mode 100644
index 0000000..b4c7469
--- /dev/null
+++ b/test/resources/remote.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7
@@ -0,0 +1,2 @@
+xAj1@Ѯ}
+EB6BKM 3Ɠ۷iz}~]Eʒq:e$I C<[&CC2wۀd^P*T1AMUֶ>hZ-CsX̘,-AV3/i5I"QBj9Hqz[t՝:.?xh^
+HO923O>A߰qt_H
\ No newline at end of file
diff --git a/test/resources/remote.git/objects/f8/0a3c020bad71f19d3b44b60955642e11c5d1ea b/test/resources/remote.git/objects/f8/0a3c020bad71f19d3b44b60955642e11c5d1ea
new file mode 100644
index 0000000..7d1e692
Binary files /dev/null and b/test/resources/remote.git/objects/f8/0a3c020bad71f19d3b44b60955642e11c5d1ea differ
diff --git a/test/resources/remote.git/refs/heads/new-feature b/test/resources/remote.git/refs/heads/new-feature
new file mode 100644
index 0000000..60e9eef
--- /dev/null
+++ b/test/resources/remote.git/refs/heads/new-feature
@@ -0,0 +1 @@
+b8731878376e3c8c2e9bbfe5947519f8d852b5d7
diff --git a/test/resources/site-collection/config.yaml b/test/resources/site-collection/config.yaml
index da90b6d..80770ef 100644
--- a/test/resources/site-collection/config.yaml
+++ b/test/resources/site-collection/config.yaml
@@ -15,3 +15,8 @@ notifyLastCommitterOnFailedUpgrade: false
# data base defaults (prototype for site db option)
db:
type: sqlite
+ path: ../db/test.sqlite # default, to prevent errors in the add site tests
+
+# specify which site should be used as base for merge requests into specific branches
+siteBranchMapping:
+ master: dev
diff --git a/test/resources/site-collection/repo.git/FETCH_HEAD b/test/resources/site-collection/repo.git/FETCH_HEAD
index 667ecf2..5cfb471 100644
--- a/test/resources/site-collection/repo.git/FETCH_HEAD
+++ b/test/resources/site-collection/repo.git/FETCH_HEAD
@@ -1 +1 @@
-7bf49e2636c5f54672e970b7fec548acd5b4bc13 branch 'master' of ../../remote
+f2614a5777fad66b7fdc8f582da7f2e200b1438f branch 'second-feature' of ../../remote
diff --git a/test/resources/site-collection/repo.git/objects/04/91924723cf552f2cd4a12ff8c38fe170f90b95 b/test/resources/site-collection/repo.git/objects/04/91924723cf552f2cd4a12ff8c38fe170f90b95
new file mode 100644
index 0000000..51d8659
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/04/91924723cf552f2cd4a12ff8c38fe170f90b95 differ
diff --git a/test/resources/site-collection/repo.git/objects/1c/ccade31b5671504e1eea5147fd31be4f71641d b/test/resources/site-collection/repo.git/objects/1c/ccade31b5671504e1eea5147fd31be4f71641d
new file mode 100644
index 0000000..487e491
--- /dev/null
+++ b/test/resources/site-collection/repo.git/objects/1c/ccade31b5671504e1eea5147fd31be4f71641d
@@ -0,0 +1,2 @@
+xJ1ay$d6(^^|dvvP^
o[FK"zV"T%d3YEɖD+wibѐ'?1))hKTa
+sJ(q;Y*ܷE^',,ZkoFCojr6?'I
\ No newline at end of file
diff --git a/test/resources/site-collection/repo.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff b/test/resources/site-collection/repo.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff
new file mode 100644
index 0000000..7a9b019
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/3d/2080a697697ee95ccce7fb161319a7915879ff differ
diff --git a/test/resources/site-collection/repo.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05 b/test/resources/site-collection/repo.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05
new file mode 100644
index 0000000..494047e
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/43/39ad5a05f3f385aaad49d3d405585ef6dead05 differ
diff --git a/test/resources/site-collection/repo.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd b/test/resources/site-collection/repo.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd
new file mode 100644
index 0000000..f4ca869
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd differ
diff --git a/test/resources/site-collection/repo.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8 b/test/resources/site-collection/repo.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8
new file mode 100644
index 0000000..a0d4a78
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/54/9e603e1a4807a81eae3fdda1713326cf9677b8 differ
diff --git a/test/resources/site-collection/repo.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f b/test/resources/site-collection/repo.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f
new file mode 100644
index 0000000..389a0c0
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/5f/519a9085e69011e6e1044a1623fbf776f0f01f differ
diff --git a/test/resources/site-collection/repo.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c b/test/resources/site-collection/repo.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c
new file mode 100644
index 0000000..722b195
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/7f/2efb17ba04bd394f2315a870ad7e2b330da45c differ
diff --git a/test/resources/site-collection/repo.git/objects/aa/347cc3b0ac927cd0a50e713e7931a2f3b04cb7 b/test/resources/site-collection/repo.git/objects/aa/347cc3b0ac927cd0a50e713e7931a2f3b04cb7
new file mode 100644
index 0000000..547abd0
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/aa/347cc3b0ac927cd0a50e713e7931a2f3b04cb7 differ
diff --git a/test/resources/site-collection/repo.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001 b/test/resources/site-collection/repo.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001
new file mode 100644
index 0000000..8d7fe6a
Binary files /dev/null and b/test/resources/site-collection/repo.git/objects/b4/c9c34f86836cf5fb80e2c79e3e5ca41b338001 differ
diff --git a/test/resources/site-collection/repo.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7 b/test/resources/site-collection/repo.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7
new file mode 100644
index 0000000..b4c7469
--- /dev/null
+++ b/test/resources/site-collection/repo.git/objects/b8/731878376e3c8c2e9bbfe5947519f8d852b5d7
@@ -0,0 +1,2 @@
+xAj1@Ѯ}
+EB6BKM 3Ɠ۷iz}~]Eʒq:e$I C<[&CC2wۀd^P*T1AMUֶ>hZ-CsX̘,-AV3/i5I"QBj9Hqz[t՝:.?xh^
+HO923O>A߰qt_H
\ No newline at end of file
diff --git a/test/resources/site-collection/repo.git/refs/heads/new-feature b/test/resources/site-collection/repo.git/refs/heads/new-feature
new file mode 100644
index 0000000..8a89982
--- /dev/null
+++ b/test/resources/site-collection/repo.git/refs/heads/new-feature
@@ -0,0 +1 @@
+7f2efb17ba04bd394f2315a870ad7e2b330da45c
diff --git a/test/resources/site-collection/repo.git/refs/heads/second-feature b/test/resources/site-collection/repo.git/refs/heads/second-feature
new file mode 100644
index 0000000..7152f7a
--- /dev/null
+++ b/test/resources/site-collection/repo.git/refs/heads/second-feature
@@ -0,0 +1 @@
+f2614a5777fad66b7fdc8f582da7f2e200b1438f
diff --git a/test/resources/site-collection/repo.git/refs/remotes/origin/master b/test/resources/site-collection/repo.git/refs/remotes/origin/master
new file mode 100644
index 0000000..a98c165
--- /dev/null
+++ b/test/resources/site-collection/repo.git/refs/remotes/origin/master
@@ -0,0 +1 @@
+1cccade31b5671504e1eea5147fd31be4f71641d
diff --git a/test/resources/site-collection/repo.git/refs/remotes/origin/new-feature b/test/resources/site-collection/repo.git/refs/remotes/origin/new-feature
new file mode 100644
index 0000000..60e9eef
--- /dev/null
+++ b/test/resources/site-collection/repo.git/refs/remotes/origin/new-feature
@@ -0,0 +1 @@
+b8731878376e3c8c2e9bbfe5947519f8d852b5d7
diff --git a/test/resources/site-collection/repo.git/refs/remotes/origin/second-feature b/test/resources/site-collection/repo.git/refs/remotes/origin/second-feature
new file mode 100644
index 0000000..7152f7a
--- /dev/null
+++ b/test/resources/site-collection/repo.git/refs/remotes/origin/second-feature
@@ -0,0 +1 @@
+f2614a5777fad66b7fdc8f582da7f2e200b1438f
diff --git a/test/resources/site-collection/sites.yaml b/test/resources/site-collection/sites.yaml
index 537f271..afd2e48 100644
--- a/test/resources/site-collection/sites.yaml
+++ b/test/resources/site-collection/sites.yaml
@@ -6,6 +6,8 @@ test:
path: ../db/test.sqlite # only for sqlite, relative to this file
dev:
+ db:
+ path: ../db/test.sqlite # only for sqlite, relative to this file
feature-x:
root: ../feature-x-site # optional, specifies path to repo relative to siteRoot
@@ -18,3 +20,10 @@ staging:
db:
path: ../db/staging.sqlite
stagingOf: production
+
+mr-new-feature:
+ isMergeRequestSite: true
+ stagingOf: dev
+ sourceBranch: new-feature
+ db:
+ path: ../db/test.sqlite # only for sqlite, relative to this file
diff --git a/test/resources/site-collection/sites/mr-new-feature/README b/test/resources/site-collection/sites/mr-new-feature/README
new file mode 100644
index 0000000..45daf39
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/README
@@ -0,0 +1,6 @@
+First commit
+second line
+third line
+fourth line
+
+NEW FEATURE!
diff --git a/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-16-john-doe.sql b/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-16-john-doe.sql
new file mode 100644
index 0000000..4c8875c
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-16-john-doe.sql
@@ -0,0 +1,3 @@
+INSERT INTO customers
+(prename, surname)
+VALUES ('John', 'Doe');
diff --git a/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-17-mary-smith.sql b/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-17-mary-smith.sql
new file mode 100644
index 0000000..a010330
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/database/migrations/2014-04-17-mary-smith.sql
@@ -0,0 +1,3 @@
+INSERT INTO customers
+(prename, surname)
+VALUES ('Mary', 'Smith');
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/FETCH_HEAD b/test/resources/site-collection/sites/mr-new-feature/dot_git/FETCH_HEAD
new file mode 100644
index 0000000..1fae1e5
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/FETCH_HEAD
@@ -0,0 +1,2 @@
+7bf49e2636c5f54672e970b7fec548acd5b4bc13 branch 'master' of ../../repo
+f19b21f71a8fd10c5edf5d130bae783f06a11c5e not-for-merge branch 'new-feature' of ../../repo
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/HEAD b/test/resources/site-collection/sites/mr-new-feature/dot_git/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/ORIG_HEAD b/test/resources/site-collection/sites/mr-new-feature/dot_git/ORIG_HEAD
new file mode 100644
index 0000000..8754ce1
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/ORIG_HEAD
@@ -0,0 +1 @@
+0c3ba58efb54b70c53cc49a24a160bfcc5680c82
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/config b/test/resources/site-collection/sites/mr-new-feature/dot_git/config
new file mode 100644
index 0000000..7d5c157
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/config
@@ -0,0 +1,12 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+[remote "origin"]
+ url = ../../repo.git/
+ fetch = +refs/heads/*:refs/remotes/origin/*
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
+
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/index b/test/resources/site-collection/sites/mr-new-feature/dot_git/index
new file mode 100644
index 0000000..63024dc
Binary files /dev/null and b/test/resources/site-collection/sites/mr-new-feature/dot_git/index differ
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd
new file mode 100644
index 0000000..f4ca869
Binary files /dev/null and b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/45/daf39be6c7862e7fd7b921556b5b205dd01afd differ
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/e4/4c266292b3ffaddf4b35a78b6ccde9c90a4a2f b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/e4/4c266292b3ffaddf4b35a78b6ccde9c90a4a2f
new file mode 100644
index 0000000..10fa58a
Binary files /dev/null and b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/e4/4c266292b3ffaddf4b35a78b6ccde9c90a4a2f differ
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/f1/9b21f71a8fd10c5edf5d130bae783f06a11c5e b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/f1/9b21f71a8fd10c5edf5d130bae783f06a11c5e
new file mode 100644
index 0000000..a61d507
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/f1/9b21f71a8fd10c5edf5d130bae783f06a11c5e
@@ -0,0 +1,2 @@
+xAj1@Ѯ}
+e{!t!dY23x(} ɶ,1*(`JX3nͨyIi=: WBhRF-l*&+U97^[2k}˩sO;~tVS{WdG
\ No newline at end of file
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/info/packs b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/info/packs
new file mode 100644
index 0000000..049a923
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-f74139904d152508e36f507c344da636b58192c4.pack
+
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.idx b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.idx
new file mode 100644
index 0000000..43f3c4b
Binary files /dev/null and b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.idx differ
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.pack b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.pack
new file mode 100644
index 0000000..f935fc7
Binary files /dev/null and b/test/resources/site-collection/sites/mr-new-feature/dot_git/objects/pack/pack-f74139904d152508e36f507c344da636b58192c4.pack differ
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/heads/master b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/heads/master
new file mode 100644
index 0000000..5fc5461
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/heads/master
@@ -0,0 +1 @@
+f19b21f71a8fd10c5edf5d130bae783f06a11c5e
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/master b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/master
new file mode 100644
index 0000000..2e80f8d
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/master
@@ -0,0 +1 @@
+7bf49e2636c5f54672e970b7fec548acd5b4bc13
diff --git a/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/new-feature b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/new-feature
new file mode 100644
index 0000000..5fc5461
--- /dev/null
+++ b/test/resources/site-collection/sites/mr-new-feature/dot_git/refs/remotes/origin/new-feature
@@ -0,0 +1 @@
+f19b21f71a8fd10c5edf5d130bae783f06a11c5e
diff --git a/test/server-unit/_spec.js b/test/server-unit/_spec.js
index 81163f8..4bd5a71 100644
--- a/test/server-unit/_spec.js
+++ b/test/server-unit/_spec.js
@@ -1,6 +1,6 @@
require('../utils/resources.js');
-jasmine.getEnv().defaultTimeoutInterval = 500;
+jasmine.getEnv().defaultTimeoutInterval = 1000;
require('q').longStackSupport = true;
diff --git a/test/server-unit/serverSpec.js b/test/server-unit/serverSpec.js
index ba9c3c8..d7bef66 100644
--- a/test/server-unit/serverSpec.js
+++ b/test/server-unit/serverSpec.js
@@ -12,5 +12,5 @@ describe("server", function() {
}
done();
}.bind(this));
- });
+ }, 5000);
});
diff --git a/test/server-unit/siteManagerSpec.js b/test/server-unit/siteManagerSpec.js
index fcdb7b4..875c7ec 100644
--- a/test/server-unit/siteManagerSpec.js
+++ b/test/server-unit/siteManagerSpec.js
@@ -12,7 +12,7 @@ describe("SiteManager", function() {
manager.schedule(manager.loadTask());
manager.on('load', function() {
- expect(manager.sites.length).toBe(5);
+ expect(manager.sites.length).toBe(6);
expect(manager.sites[0]).toBeInstanceOf(Site);
expect(manager.sites[0].name).toBe('test');
@@ -45,15 +45,15 @@ describe("SiteManager", function() {
manager.schedule(task);
task
.then(function() {
- expect(task.plainLog).toContain('sites test, dev, staging will be upgraded');
- expect(task.plainLog).toContain('branches master have been updated');
+ expect(task.plainLog).toMatch(/.*sites test, dev, staging.* will be upgraded.*/);
+ expect(task.plainLog).toMatch(/.*branches master.* have been updated.*/);
expect(scheduledTasks).toEqual(['Upgrade']);
done();
});
});
});
}.bind(this));
- });
+ }, 5000);
it("can add new site", function(done) {
resources.use(function(path) {
@@ -98,4 +98,25 @@ describe("SiteManager", function() {
}.bind(this));
}.bind(this));
}, 5000);
+
+ it("can add a merge request site", function(done) {
+ resources.use(function(path) {
+ path += '/site-collection';
+ var manager = new SiteManager(path);
+ manager.on('fail', function(task, error) { this.fail(error); done(); }.bind(this));
+ manager.schedule(manager.loadTask());
+
+ manager.once('load', function() {
+ var task = manager.createMergeRequestSiteTask('second-feature', 'master');
+ manager.schedule(task);
+ task.then(function() {
+ var sites = manager.sites.filter(function(s) { return s.name == 'mr-second-feature'; });
+ expect(sites.length).toBeGreaterThan(0);
+ return sites[0].loaded;
+ })
+ .catch(function(err) { this.fail(err); }.bind(this))
+ .then(done);
+ }.bind(this));
+ }.bind(this));
+ }, 5000);
});