Skip to content

Instantly share code, notes, and snippets.

@peschee
Last active August 29, 2015 14:18
Show Gist options
  • Save peschee/3db1a4ab69ad72e79740 to your computer and use it in GitHub Desktop.
Save peschee/3db1a4ab69ad72e79740 to your computer and use it in GitHub Desktop.
JIRA bug report update script
<script type="text/javascript">
(function ($) {
$(function () {
var descriptionTemplate = "What URL were you on? Who were you logged in as? Is there anything else about your environment that is important (Browser, Browser Version)?\n\nh3. What did you expected it to do?\n\nh3. What did it actually do?\n\nh3. What are the detailed steps to recreate this behavior?\n\n# Step 1\n# Step 2\n# Step 3\n# ...";
var updateDescription = function updateDescription($issueTypeField, $description) {
if ($issueTypeField.length > 0 && $description.length > 0) {
var issueType = $issueTypeField.get('selector') === '#issue-create-issue-type' ? $issueTypeField.html() : $issueTypeField.val();
// Update description
if (issueType === 'Bug' && !$description.val()) {
$description.val(descriptionTemplate);
}
// Reset
else if (issueType !== 'Bug' && $description.val() === descriptionTemplate) {
$description.val('');
}
}
};
// Update description field on issue type field change
$(document).on('change', '#issuetype-field', function () {
updateDescription($(this), $('#description'));
});
// Update description initially
var $staticIssueType = $('#issue-create-issue-type');
var $issueTypeDropdown = $('#issuetype-field');
var $targetInitialIssueType = $staticIssueType.length > 0 ? $staticIssueType : $issueTypeDropdown;
updateDescription($targetInitialIssueType, $('#description'));
});
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment