Created
December 4, 2014 21:52
-
-
Save robcolburn/7e8e38558021aae5685b to your computer and use it in GitHub Desktop.
This file contains 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
jQuery(function ($) { | |
var $commits = $('.commit-message'); | |
var message = $commits.text(); | |
var rally_tickets = $.unique(message.match(/(US|DE|TA)-\d{3,}/g) || []).sort(); | |
var rally_references = rally_tickets.map(function (ticket) { | |
return '* [' + ticket + '](https://rally1.rallydev.com/#/search?keywords=' + ticket + ')'; | |
}).filter(identity); | |
var $files = $('.file .meta .info .js-selectable-text'); | |
var files = $files.text(); | |
var has_contrib = false; | |
var has_core = false; | |
var module_tokens = $.unique(files.match(/[a-z\_\-]+\/modules\/[a-z\_\-]+\/[a-z\_\-]+/g) || []); | |
var module_references = module_tokens.map(function (module) { | |
var parts = module.split('/'); | |
console.log(parts); | |
if (parts[2] === 'contrib') { | |
has_contrib = true; | |
return '[`' + parts[3] + '`](https://www.drupal.org/project/' + parts[3] + ')'; | |
} | |
if (parts[0] === 'docroot') { | |
has_core = true; | |
return '*Core:* `' + parts[3] + '`'; | |
} | |
if (parts[0] === 'publisher') { | |
return '`' + parts[3] + '`'; | |
} | |
}).filter(identity); | |
var $textarea = $('textarea[name="pull_request[body]"]'); | |
var old_message = $textarea.val(); | |
var message = []; | |
if (old_message) { | |
message.push(old_message); | |
} | |
if (has_contrib) { | |
message.push('> This PR contains changes to contrib - be sure to updated PATCHES\n'); | |
} | |
if (has_core) { | |
message.push('> This PR contains changes to Drupal - be sure to updated PATCHES\n'); | |
} | |
if (rally_references.length) { | |
message.push("### Rally!:" + "\n* " + rally_references.sort().join("\n* ")); | |
} | |
if (module_references.length) { | |
message.push("### Module(s) Changed:" + "\n* " + module_references.sort().join("\n* ")); | |
} | |
$textarea.val(message.join("\n")); | |
function identity (a) { | |
return a; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment