Greasy Fork 还支持 简体中文。

Jira Deployment Helper

Adds Jira Code Review button to Subversion Commits tab, highlights database changes in the comments or description that have "dbo." in them or say "ERRORFIXED", "ERRORIGNORED" or "STILLOCCURRING", highlights tasks in list view and dashboard gadgets based on original time estimate and due date.

目前為 2017-10-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Jira Deployment Helper
  3. // @namespace http://www.mapyourshow.com/
  4. // @description Adds Jira Code Review button to Subversion Commits tab, highlights database changes in the comments or description that have "dbo." in them or say "ERRORFIXED", "ERRORIGNORED" or "STILLOCCURRING", highlights tasks in list view and dashboard gadgets based on original time estimate and due date.
  5. // @include */secure/dashboard*
  6. // @include */browse/*
  7. // @include */issues/*
  8. // @grant GM_log
  9. // @version 1.6.0
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  11. // ==/UserScript==
  12.  
  13. function scriptLoader(callback) {
  14. var script = document.createElement("script");
  15. script.textContent = "(" + callback.toString() + ")(window.AJS.$);";
  16. document.body.appendChild(script);
  17. }
  18.  
  19. mainCode = function($) {
  20. var version = 0,
  21. task = '',
  22. project = '';
  23.  
  24. // This is for the main Dashboard Gadgets
  25. $(document).on('DOMNodeInserted', 'div.gadget', function(e) {
  26. var $elem = $(e.target);
  27.  
  28. $elem.on('DOMNodeInserted', function(e) {
  29. if (typeof $('div.gadget-inline') !== 'undefined') {
  30. initJiraPlugin($('div.gadget-inline').contents().find('table'));
  31. } else {
  32. initJiraPlugin($('iframe').contents().find('table'));
  33. }
  34. });
  35. });
  36.  
  37. // These are for the Issues page
  38. JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
  39. initJiraPlugin($('table#issuetable'));
  40. });
  41.  
  42. if (typeof JIRA.ViewIssueTabs !== 'undefined') {
  43. JIRA.ViewIssueTabs.onTabReady(function() {
  44. initJiraPlugin($('table#issuetable'));
  45. });
  46. }
  47.  
  48. function initJiraPlugin(issueTable) {
  49. version = parseFloat($('meta[name=ajs-version-number]').attr('content'));
  50. if ($('meta[name=ajs-issue-key]').length) {
  51. task = $('meta[name=ajs-issue-key]').attr('content');
  52. project = task.split('-')[0];
  53. }
  54.  
  55. // This colorizes the tasks in list view based on Original Estimate and Due Date
  56. colorTasks(issueTable, version);
  57.  
  58. // This highlights all instances of database names with "dbo." in them
  59. highlightDB(version);
  60.  
  61. // This highlights all instances of "ERRORFIXED"
  62. highlightErrorNotes(version);
  63.  
  64. // Clears duplicated highlight tags when editing a comment/description with a highlighted term in it
  65. clearInvalidHighlightTags(version);
  66.  
  67. // This adds the Code Review button in the Subversion tab
  68. addCodeReviewButton(version);
  69.  
  70. // Defaults the issues page to "All Issues" instead of "Open Issues"
  71. allIssuesDefault(version);
  72. }
  73.  
  74. function Change(label, url) {
  75. this.label = label;
  76. var s = url.split(url.indexOf('#') > 0 ? '#' : '?r=');
  77. this.ref = s[0];
  78. this.revision = s[1];
  79. this.commits = 1;
  80. this.pref = new RegExp('/[a-zA-Z-_]+/', '');
  81.  
  82. this.asA = function() {
  83. return this.label;
  84. };
  85.  
  86. this.setMaxRevision = function(revision) {
  87. if (revision > this.revision) {
  88. this.revision = revision;
  89. }
  90. this.commits++;
  91. };
  92.  
  93. this.samePrefix = function(prefix) {
  94. return getPrefix() == prefix;
  95. };
  96.  
  97. this.getPrefix = function() {
  98. return this.label.match(this.pref)[0];
  99. };
  100. }
  101.  
  102. function createReviewView() {
  103. var index = 0;
  104. var changes = [];
  105. var mapChanges = [];
  106. //select dev with id issueContent
  107. //select div with id issue_actions_container in it
  108. //select tables in it
  109. //find rows with text 'Files Changed'
  110. //select next sibling tr (in terminology of jquery it is 'next adjacent selector'
  111. //select td in it
  112. //select a in it
  113. $('div#issue_actions_container table tr:contains("Files Changed") + tr td').each(function() {
  114. var lines = $(this).text().split('\n');
  115. $.each(lines, function() {
  116. if (this.trim().substr(0, 7) == '/trunk/' || this.trim().substr(0, 10) == '/branches/') {
  117. var change = new Change(this, this);
  118. if (mapChanges[change.label]) {
  119. mapChanges[change.label].setMaxRevision(change.revision);
  120. } else {
  121. changes[index++] = change;
  122. mapChanges[change.label] = change;
  123. }
  124. }
  125. });
  126. });
  127. changes.sort(function(a, b) {
  128. return (b.label.toLowerCase() < a.label.toLowerCase()) - (a.label.toLowerCase() < b.label.toLowerCase());
  129. });
  130. var res = '<div class="issuePanelContainer" id="issue_actions_container"><table cellpadding="2" cellspacing="0" border="0" width="100%">';
  131. res += '<tbody><tr><td bgcolor="#f0f0f0"><b>Commits</b></td><td bgcolor="#f0f0f0"><b>Changed File</b></td></tr>';
  132. var prefix;
  133. var sep = false;
  134. for (var i = 0; i < index; i++) {
  135. sep = (prefix && (prefix != changes[i].getPrefix()));
  136. res = res + '<tr><td' + style(sep) + '>' + changes[i].commits + '</td><td' + style(sep) + '>' + changes[i].asA() + '</td></tr>';
  137. prefix = changes[i].getPrefix();
  138. }
  139. return res + '</tbody></table></div>';
  140. }
  141.  
  142. function style(sep) {
  143. return sep ? ' style="border-top: solid #BBB 1px;"' : '';
  144. }
  145.  
  146. function highlightDB(version) {
  147. if ($('#description-val').length) {
  148. var $descriptionDiv = $('#description-val');
  149. } else if ($('#issue-description').length) {
  150. var $descriptionDiv = $('#issue-description');
  151. }
  152. if ($descriptionDiv) {
  153. var result = $descriptionDiv.html();
  154. var regex = new RegExp('[\\w.*_]*dbo\\.[\\w]*','ig');
  155. $descriptionDiv.html(result.replace(regex, '<span style="background-color:yellow;">$&</span>'));
  156. }
  157.  
  158. $('.action-body').each(function() {
  159. result = $(this).html();
  160. regex = new RegExp('[\\w.*_]*dbo\\.[\\w]*','ig');
  161. $(this).html(result.replace(regex, '<span style="background-color:yellow;">$&</span>'));
  162. });
  163. }
  164.  
  165. function highlightErrorNotes(version) {
  166. if ($('#description-val').length) {
  167. var $descriptionDiv = $('#description-val');
  168. } else if ($('#issue-description').length) {
  169. var $descriptionDiv = $('#issue-description');
  170. }
  171. if ($descriptionDiv) {
  172. var result = $descriptionDiv.html();
  173. var regex = new RegExp('ERRORFIXED','g');
  174. $descriptionDiv.html(result.replace(regex, '<span style="background-color:#ffff00;">$&</span>'));
  175.  
  176. result = $descriptionDiv.html();
  177. regex = new RegExp('ERRORIGNORED','g');
  178. $descriptionDiv.html(result.replace(regex, '<span style="background-color:#90ee90;">$&</span>'));
  179.  
  180. result = $descriptionDiv.html();
  181. regex = new RegExp('STILLOCCURRING','g');
  182. $descriptionDiv.html(result.replace(regex, '<span style="background-color:#ffa500;">$&</span>'));
  183. }
  184.  
  185. $('.action-body').each(function() {
  186. if (project == 'ERRORS') {
  187. result = $(this).html();
  188. regex = new RegExp('boothsales','gi');
  189. $(this).html(result.replace(regex, '<span style="background-color:#ff0000;">$&</span>'));
  190.  
  191. result = $(this).html();
  192. regex = new RegExp('/checkout/checkout.cfm','gi');
  193. $(this).html(result.replace(regex, '<span style="background-color:#ff0000;">$&</span>'));
  194. }
  195.  
  196. result = $(this).html();
  197. regex = new RegExp('ERRORFIXED','g');
  198. $(this).html(result.replace(regex, '<span style="background-color:#ffff00;">$&</span>'));
  199.  
  200. result = $(this).html();
  201. regex = new RegExp('ERRORIGNORED','g');
  202. $(this).html(result.replace(regex, '<span style="background-color:#90ee90;">$&</span>'));
  203.  
  204. result = $(this).html();
  205. regex = new RegExp('STILLOCCURRING','g');
  206. $(this).html(result.replace(regex, '<span style="background-color:#ffa500;">$&</span>'));
  207. });
  208. }
  209.  
  210. function clearInvalidHighlightTags(version) {
  211. if ($('#description-val').length) {
  212. var $descriptionDiv = $('#description-val');
  213. } else if ($('#issue-description').length) {
  214. var $descriptionDiv = $('#issue-description');
  215. }
  216. if ($descriptionDiv) {
  217. $descriptionDiv.html($descriptionDiv.html().replace('&lt;span style="background-color:yellow;"&gt;', ''));
  218. $descriptionDiv.html($descriptionDiv.html().replace('&lt;/span&gt;', ''));
  219. }
  220.  
  221. $('.action-body').each(function() {
  222. $(this).html($(this).html().replace('&lt;span style="background-color:yellow;"&gt;', ''));
  223. $(this).html($(this).html().replace('&lt;/span&gt;', ''));
  224. });
  225. }
  226.  
  227. function addCodeReviewButton(version) {
  228. console.log(version);
  229. if (!$('#review_button_div').length) {
  230. if (version >= 7) {
  231. if ($('li#svnplus-subversion-commits-tabpanel').hasClass('active') == 1) { //where the Subversion Commits is but not inside a tag
  232. $('div#issue_actions_container:first').prepend('<div id="review_button_div" style="width: 100%;margin-bottom:10px;"><button id="review_button">Code Review</button></div>');
  233. var view = createReviewView();
  234. var revView = false;
  235. $('#review_button').click(function() {
  236. var oldView = $('table', 'div#issue_actions_container').detach();
  237. $('div#review_button_div').after(view);
  238. $('#review_button').text(revView ? 'Code Review' : 'All Commits');
  239. view = oldView;
  240. revView = !revView;
  241. });
  242. }
  243. } else if (version >= 6) {
  244. if ($('li#subversion-commits-tabpanel').hasClass('active') == 1) { //where the Subversion Commits is but not inside a tag
  245. $('div#issue_actions_container:first').prepend('<div id="review_button_div" style="width: 100%;margin-bottom:10px;"><button id="review_button">Code Review</button></div>');
  246. var view = createReviewView();
  247. var revView = false;
  248. $('#review_button').click(function() {
  249. var oldView = $('table', 'div#issue_actions_container').detach();
  250. $('div#review_button_div').after(view);
  251. $('#review_button').text(revView ? 'Code Review' : 'All Commits');
  252. view = oldView;
  253. revView = !revView;
  254. });
  255. }
  256. } else {
  257. if ($('li#subversion-commits-tabpanel').hasClass('active') == 1) { //where the Subversion Commits is but not inside a tag
  258. $('ul#issue-tabs').closest('div').after('<div id="review_button_div" style="width: 100%;margin-bottom:10px;"><button id="review_button">Code Review</button></div>');
  259. var view = createReviewView();
  260. var revView = false;
  261. $('#review_button').click(function() {
  262. var oldView = $('div#issue_actions_container').detach();
  263. $('div#review_button_div').after(view);
  264. $('#review_button').text(revView ? 'Code Review' : 'All Commits');
  265. view = oldView;
  266. revView = !revView;
  267. });
  268. }
  269. }
  270. }
  271. }
  272.  
  273. function allIssuesDefault(version) {
  274. if ($('*[data-item-id="allissues"]').length) {
  275. $('*[data-item-id="allissues"]').trigger('click');
  276. }
  277. }
  278.  
  279. function colorTasks(issueTable, version) {
  280. if (issueTable.length && (issueTable.find('td.timeoriginalestimate').length || issueTable.find('td.aggregatetimeoriginalestimate').length) && issueTable.find('td.duedate').length) {
  281. var $issueTable = issueTable,
  282. $issueTableRows = issueTable.find('tr:gt(0)'); // skip the header row
  283.  
  284. $issueTableRows.each(function(index) {
  285. var $originalEstimate = ($.trim($('td.timeoriginalestimate', this).html()) == '' ? $.trim($('td.aggregatetimeoriginalestimate', this).html()) : $.trim($('td.timeoriginalestimate', this).html())),
  286. $dueDate = (typeof($('td.duedate', this).html()) == 'string' ? $('td.duedate', this).html() : ''),
  287. $originalEstimateDays,
  288. $originalEstimateMinutes,
  289. $numberDays,
  290. thisdate,
  291. today;
  292.  
  293. // Get total estimated minutes
  294. $originalEstimateMinutes = ($originalEstimate.match(/\d+(?= week)/ig) == null ? 0 : parseInt($originalEstimate.match(/\d+(?= week)/ig)) * 2400)
  295. + ($originalEstimate.match(/\d+(?= day)/ig) == null ? 0 : parseInt($originalEstimate.match(/\d+(?= day)/ig)) * 480)
  296. + ($originalEstimate.match(/\d+(?= hour)/ig) == null ? 0 : parseInt($originalEstimate.match(/\d+(?= hour)/ig)) * 60)
  297. + ($originalEstimate.match(/\d+(?= minute)/ig) == null ? 0 : parseInt($originalEstimate.match(/\d+(?= minute)/ig)));
  298.  
  299. // Now let's account for weekends
  300. $numberDays = Math.ceil($originalEstimateMinutes / 480);
  301.  
  302. thisdate = new Date();
  303. today = thisdate.getDay();
  304.  
  305. switch (true) {
  306. case ($numberDays == 0):
  307. if (today == 6) {
  308. $originalEstimateMinutes += 480;
  309. } else if (today == 5) {
  310. $originalEstimateMinutes += 960;
  311. }
  312. break;
  313. case ($numberDays == 1):
  314. if (today == 6) {
  315. $originalEstimateMinutes += 480;
  316. } else if (today == 5) {
  317. $originalEstimateMinutes += 960;
  318. }
  319. break;
  320. case ($numberDays == 2):
  321. if (today == 6) {
  322. $originalEstimateMinutes += 480;
  323. } else if (today >= 4) {
  324. $originalEstimateMinutes += 960;
  325. }
  326. break;
  327. case ($numberDays == 3):
  328. if (today == 6) {
  329. $originalEstimateMinutes += 480;
  330. } else if (today >= 3) {
  331. $originalEstimateMinutes += 960;
  332. }
  333. break;
  334. case ($numberDays == 4):
  335. if (today == 6) {
  336. $originalEstimateMinutes += 480;
  337. } else if (today >= 2) {
  338. $originalEstimateMinutes += 960;
  339. }
  340. break;
  341. case ($numberDays == 5):
  342. if (today == 6) {
  343. $originalEstimateMinutes += 480;
  344. } else if (today >= 1) {
  345. $originalEstimateMinutes += 960;
  346. }
  347. break;
  348. case ($numberDays >= 6 && $numberDays < 11):
  349. if (today == 6) {
  350. $originalEstimateMinutes += 1440;
  351. } else if (today >= 5) {
  352. $originalEstimateMinutes += 1920;
  353. } else if (today == 0) {
  354. $originalEstimateMinutes += 960;
  355. }
  356. break;
  357. case ($numberDays >= 11 && $numberDays < 16):
  358. if (today == 6) {
  359. $originalEstimateMinutes += 2400;
  360. } else if (today >= 5) {
  361. $originalEstimateMinutes += 2880;
  362. } else if (today == 0) {
  363. $originalEstimateMinutes += 1920;
  364. }
  365. break;
  366. case ($numberDays >= 16 && $numberDays < 21):
  367. if (today == 6) {
  368. $originalEstimateMinutes += 3360;
  369. } else if (today >= 5) {
  370. $originalEstimateMinutes += 3840;
  371. } else if (today == 0) {
  372. $originalEstimateMinutes += 2880;
  373. }
  374. break;
  375. case ($numberDays >= 21 && $numberDays < 26):
  376. if (today == 6) {
  377. $originalEstimateMinutes += 4350;
  378. } else if (today >= 5) {
  379. $originalEstimateMinutes += 4800;
  380. } else if (today == 0) {
  381. $originalEstimateMinutes += 3840;
  382. }
  383. break;
  384. default:
  385. break;
  386. }
  387.  
  388. // The number of total days estimated, including weekends
  389. $originalEstimateDays = Math.ceil($originalEstimateMinutes / 480);
  390. $daysTilDueDate = Math.ceil(dateDiff($dueDate));
  391.  
  392. if ($originalEstimate.trim() != '') { // If an Original Estimate was given
  393. if (($daysTilDueDate - $originalEstimateDays) < 1) {
  394. $(this).css('background-color','#ff9999'); // Red
  395. } else if (($daysTilDueDate - $originalEstimateDays) <= 2) {
  396. $(this).css('background-color','#fed080'); // Orange
  397. } else if (($daysTilDueDate - $originalEstimateDays) <= 4) {
  398. $(this).css('background-color','#fffeab'); // Yellow
  399. }
  400. } else {
  401. if (($daysTilDueDate - $originalEstimateDays) < 1) {
  402. $(this).css('background-color','#ff9999'); // Red
  403. } else if (($daysTilDueDate - $originalEstimateDays) == 1) {
  404. $(this).css('background-color','#fed080'); // Orange
  405. } else if (($daysTilDueDate - $originalEstimateDays) == 2) {
  406. $(this).css('background-color','#fffeab'); // Yellow
  407. }
  408. }
  409. });
  410. } else if ($('.issue-list').length) {
  411. // Do nothing for now
  412. }
  413. }
  414.  
  415. function dateDiff(dueDate) {
  416. var dueDate = dueDate.replace('Jan', '0')
  417. .replace('Feb', '1')
  418. .replace('Mar', '2')
  419. .replace('Apr', '3')
  420. .replace('May', '4')
  421. .replace('Jun', '5')
  422. .replace('Jul', '6')
  423. .replace('Aug', '7')
  424. .replace('Sep', '8')
  425. .replace('Oct', '9')
  426. .replace('Nov', '10')
  427. .replace('Dec', '11');
  428. var arrDueDate = dueDate.split('/');
  429. var dt1 = new Date();
  430. var dt2 = new Date('20' + arrDueDate[2], arrDueDate[1], arrDueDate[0]);
  431. var one_day = 1000 * 60 * 60 * 24;
  432.  
  433. return (parseInt(dt2.getTime() - dt1.getTime()) / (one_day));
  434. }
  435. }
  436.  
  437. scriptLoader(mainCode);