Created
October 16, 2015 05:41
-
-
Save dalpert-korewireless/c44740390ffc5ef8d4f3 to your computer and use it in GitHub Desktop.
TamperMonkey Script
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
| // ==UserScript== | |
| // @name JIRA Incident Cleanup | |
| // @namespace http://blog.spinthemoose.com/ | |
| // @version 0.1 | |
| // @description Adds some helpful capabilities to JIRA | |
| // @author David Alpert | |
| // @match https://koresystemsgroup.atlassian.net/browse/* | |
| // @grant none | |
| // ==/UserScript== | |
| function JIRAIncidentCleanup() { | |
| if (window.jQuery == 'undefined') { | |
| window.setTimeout(JIRAIncidentCleanup, 100); | |
| } else { | |
| var $ = jQuery; | |
| var editToolbar = $('#opsbar-edit-issue_container'); | |
| var cleanButton = [ | |
| '<li class="toolbar-item">', | |
| ' <a id="clean-issue-description" class="toolbar-trigger" href="#">', | |
| ' <span class="trigger-label">Clean Description</span>', | |
| ' </a>', | |
| '</li>' | |
| ].join(''); | |
| editToolbar.append(cleanButton); | |
| cleanButton = $('#clean-issue-description'); | |
| cleanButton.click(function(ev){ | |
| // according to: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/updating-an-issue-via-the-jira-rest-apis | |
| // | |
| // PUT https://koresystemsgroup.atlassian.net/rest/api/2/issue/KEY | |
| var key = $('a#key-val').text(); | |
| var issue_url = 'https://koresystemsgroup.atlassian.net/rest/api/2/issue/'+key; | |
| $.get(issue_url , function( data ) { | |
| var desc = data.fields.description; | |
| desc = sanitize_image_tags(desc); | |
| desc = sanitize_created_tag(desc); | |
| console.log(desc); | |
| if (confirm(desc)) { | |
| $.ajax({ | |
| url: issue_url, | |
| type: 'PUT', | |
| contentType : 'application/json', | |
| headers : { | |
| authorization : 'Basic ZGFscGVydDpDQXQkYWZyMQ==' | |
| }, | |
| data : JSON.stringify({ fields : { description : desc } }), | |
| error : function(xhr, textStatus, errorThrown) { | |
| alert('error:\r\n'+textStatus+'\r\n\r\n'+errorThrown); | |
| }, | |
| success: function(result) { | |
| location.reload(true); | |
| } | |
| }); | |
| } | |
| }); | |
| }); | |
| function sanitize_image_tags(markdown) | |
| { | |
| return markdown.replace(/\[cid:(image\d+.[^@]+)@[^\]]+\]/g,'!$1|thumbnail!'); | |
| } | |
| function sanitize_created_tag(markdown) | |
| { | |
| return markdown.replace(/(\[Created via e-mail received from: )(.*?) <(.*?)>(\])/,'\\$1[$2|mailto:$3]\\]'); | |
| } | |
| // [cid:[email protected]] --> !image001.png|thumbnail! | |
| // [Created via e-mail received from: David Alpert <[email protected]>] --> \[Created via e-mail received from: [David Alpert|mailto:[email protected]]\] | |
| } | |
| } | |
| JIRAIncidentCleanup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment