Skip to content

Instantly share code, notes, and snippets.

@LucasMetal
Last active October 17, 2017 22:17
Show Gist options
  • Save LucasMetal/6d9b152cf98b1d80db41 to your computer and use it in GitHub Desktop.
Save LucasMetal/6d9b152cf98b1d80db41 to your computer and use it in GitHub Desktop.
Greasemonkey script that adds a button to commits in PRs to add its description to the PR description.
// ==UserScript==
// @name GitHub Description from Commits
// @namespace LucasMetal
// @description Adds a button to commits in PRs to add its description to the PR description.
// @version 1
// @match https://github.com/**/compare/*
// @grant none
// @author @LucasMetal
// @require https://code.jquery.com/jquery-2.2.3.min.js
// ==/UserScript==
console.log("GitHub Description from Commits: Loaded");
// TODO: Improve, we need the timeout so it's fully loaded.
// But maybe it has loaded by Ajax, in some cases it will not fire.
setTimeout(function(){
// Add the button to each commit
//$('td.commit-message').append("<br/><a href='#' class='btn btn-sm tooltipped tooltipped-n add-description' aria-label='Add commit description to PR description'>Add to description</a>");
$('td.commit-message code').append("<span class='hidden-text-expander inline'><a href='#' class='js-details-target add-description'>+</a></span>");
// Attach click event to each added button
// TODO: Maybe we could use "on" on the document, with a filter, should be better I guess
$('.add-description').on('click', function(){
var jCommitMessage = $(this).parents("td.commit-message");
var commitTitle = jCommitMessage.find('a.message').text();
var commitDescription = jCommitMessage.find('div.commit-desc').text();
// TODO: Format the message better
/*
- Create separator in config files for migrated keys
Config keys that are now consumed from the IAmsSettings configuration object are grouped together so it's easier to detected possible DB overrides when modifying the config files.
- Create separator in config files for migrated keys
Config keys that are now consumed from the IAmsSettings configuration object are grouped together so it's easier to detected possible DB overrides when modifying the config files.
*/
var textToAdd = '\n- ' + commitTitle + ' \n' + commitDescription;
// Add the text to the PR comment body
$('#pull_request_body')[0].value = $('#pull_request_body')[0].value + '\n' + textToAdd;
console.log("Commit description added!");
// Return false to avoid opening/closing the comments
return false;
});
}, 5 * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment