Created
May 26, 2013 18:47
-
-
Save vmx/5653675 to your computer and use it in GitHub Desktop.
Bookmarklet for Gerrit that displays all changesets for a certain Change-Id. This way you can link commits across different projects.
This file contains hidden or 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
function getChangeId(container) { | |
for (var i in container.childNodes) { | |
var node = container.childNodes[i]; | |
if (node.nodeName === 'P' && | |
node.innerText.indexOf('Change-Id:') === 0) { | |
var changeId = node.innerText.substr('Change-Id: '.length, 41); | |
return changeId; | |
} | |
} | |
return 'error'; | |
}; | |
function sendRequest(requestData, cb) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', window.location.origin + '/' + 'gerrit/rpc/ChangeListService'); | |
xhr.setRequestHeader('Content-type', 'application/json;charset=UTF-8'); | |
xhr.setRequestHeader('Accept', 'application/json'); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState !== 4) { | |
return; | |
} | |
var resp = JSON.parse(xhr.responseText); | |
cb(resp); | |
}; | |
xhr.send(JSON.stringify(requestData)); | |
} | |
function createItem(url, infoText) { | |
var link = document.createElement('a'); | |
var info = document.createTextNode(infoText); | |
var item = document.createElement('li'); | |
link.href = url; | |
link.innerText = url; | |
item.appendChild(link); | |
item.appendChild(info); | |
return item; | |
} | |
function insertItems(container, items) { | |
var list = document.createElement('ul'); | |
for (var i in items) { | |
list.appendChild(items[i]); | |
} | |
container.appendChild(list); | |
} | |
function displayAllChanges() { | |
var container = document.getElementsByClassName("GJEA35ODLB")[0]; | |
var changeId = getChangeId(container); | |
var requestData = { | |
jsonrpc: "2.0", | |
method: "allQueryNext", | |
params: [changeId, "z", 0], | |
id: 2 | |
}; | |
sendRequest(requestData, function(resp) { | |
var items = resp.result.changes.map(function(change) { | |
var url = window.location.origin + '/' + change.id.id; | |
var info = ' (' + change.project.key.name + ', ' + | |
change.status + ')'; | |
var item = createItem(url, info); | |
return item; | |
}); | |
insertItems(container, items); | |
}); | |
} | |
displayAllChanges(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment