Skip to content

Instantly share code, notes, and snippets.

@zwily
Created March 9, 2012 19:14
Show Gist options
  • Save zwily/2008155 to your computer and use it in GitHub Desktop.
Save zwily/2008155 to your computer and use it in GitHub Desktop.
<div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" />
<script src="static/jquery.extensions.js" type="text/javascript" />
<script src="static/ui-modifications.js" type="text/javascript" />
</div>
(function() {
var hash_change_hooks = [];
var document_ready_hooks = [];
var currentHash = null;
function updateGerritUI() {
try {
if (window.location.hash == currentHash) {
return;
}
currentHash = window.location.hash;
$.each(hash_change_hooks, function(i, hook) { hook(); });
} catch (err) {
currentHash = null;
}
}
$(document).ready(function() {
setInterval(updateGerritUI, 1000);
$.each(document_ready_hooks, function(i, hook) { hook(); });
});
// SELENIUM BUTTON
hash_change_hooks.push(function() {
if (!(window.location.hash && window.location.hash.match(/^#change,/) &&
$("span:contains('git fetch')").last().text().match(/canvas-lms/)))
return;
$("button:contains('Diff All')").parent().append(
"<button type='button' tabindex='0' " +
"class='gwt-Button selenium-trigger'>Trigger Selenium Test</button>");
});
document_ready_hooks.push(function() {
$(".selenium-trigger").live('click', function() {
var patchset = /refs\/changes\/(\d+\/\d+\/\d+) /.exec(
$("span:contains('git fetch')").last().text())[1];
var xsrfKey = $.cookie('GerritAccount');
var matches = /^\d+\/(\d+)\/(\d+)$/.exec(patchset)
var changeid = matches[1]
var patchid = matches[2]
var hudsonurl = "http://hudson/url/to/trigger/a/build/" + patchset;
$.get(hudsonurl)
.error(function(p1, p2, p3) {})
.success(function() {})
.complete(function() {
$.ajax({
type: 'POST',
url: "/gerrit/rpc/PatchDetailService",
data: $.toJSON({
"jsonrpc": "2.0",
"method": "publishComments",
"params": [
{
"changeId": {
"id": changeid
},
"patchSetId": patchid
},
"Selenium Build Triggered",
[]
],
"xsrfKey": xsrfKey
}),
contentType: "application/json; charset=utf-8",
dataType: 'json'
})
.error(function() {})
.complete(function() {})
.success(function() { window.location.reload(); })
});
// window.location = url;
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment