Skip to content

Instantly share code, notes, and snippets.

@lrytz
Created November 27, 2014 18:01
Show Gist options
  • Save lrytz/7fb6cb2cc6c87f0558ff to your computer and use it in GitHub Desktop.
Save lrytz/7fb6cb2cc6c87f0558ff to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Typesafe GitHub CLA checker
// @namespace http://typesafe.com/
// @version 1.6
// @description Checks a GitHub committer to see if they've signed the CLA
// @match https://github.com/scala/scala/pull/*
// @require http://code.jquery.com/jquery-1.8.2.min.js
// @copyright 2012, James Roper <james@jazzy.id.au>
// ==/UserScript==
// Usage instructions: Modify the @match tag above to point to your projects pull requests (you can have
// multiple @match tags) and then install the script into greasemonkey/tampermonkey/etc.
var typseafeClaChecker = (function() {
var checkCla = function(user, signed, signedold, notsigned) {
GM_xmlhttpRequest({
method: "GET",
url: "http://typesafe.com/contribute/cla/scala/check/" + user,
onload: function(response) {
var responseJson = JSON.parse(response.responseText);
if (responseJson.signed) {
var currentVersion = responseJson.currentVersion;
if (!currentVersion) {
currentVersion = "2.2";
}
if (responseJson.version == currentVersion) {
signed(responseJson.version);
} else {
signedold(responseJson.version, currentVersion);
}
} else {
notsigned();
}
}
});
}
var prepareCommentBox = function(text) {
var commentBox = $('textarea[name="comment[body]"]');
if (commentBox.val() == null || commentBox.val() == "") {
commentBox.val(text);
}
}
var author;
author = $(".pull-header-username").first();
if (author) {
var user = author.text().trim();
var checkButton = $('<a href="#" class="minibutton">Check CLA for ' + user + '</a>');
var checkDiv = $("<div>");
checkDiv.css({"margin-top": "15px"});
checkButton.click(function() {
checkDiv.text("Checking...");
checkCla(user, function(version) {
checkDiv.text(user + " has signed version " + version + " of the Scala CLA");
checkDiv.css({ color: "green", "font-weight": "bold"});
}, function(oldVersion, newVersion) {
checkDiv.text(user + " has signed version " + oldVersion + " of the Scala CLA, but the current version is " + newVersion);
checkDiv.css({ color: "orange", "font-weight": "bold"});
prepareCommentBox("Hi @" + user + ",\n\nThankyou for your contribution. We see that you have signed our CLA before, however the CLA has since been updated. Would you mind reviewing the new version and signing it?\n\nhttp://www.typesafe.com/contribute/cla/scala\n\nThanks!");
}, function() {
checkDiv.text(user + " has not signed the Scala CLA");
checkDiv.css({ color: "red", "font-weight": "bold"});
prepareCommentBox("Hi @" + user + ",\n\nThankyou for your contribution. Would you mind signing our CLA?\n\nhttp://www.typesafe.com/contribute/cla/scala\n\nThanks!");
});
});
checkDiv.append(checkButton);
$("#partial-discussion-header").first().append(checkDiv);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment