Revision | a81938a8f6c6dd827008ed2cf3484765725c9de5 (tree) |
---|---|
Zeit | 2017-04-02 17:00:29 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2420 AutoTicketLink: Support title for ticket link
@@ -293,11 +293,23 @@ $ticket_link_sites = array( | ||
293 | 293 | /* |
294 | 294 | array( |
295 | 295 | 'key' => 'phpbug', |
296 | - 'type' => 'redmine', // type: redmine or jira | |
297 | - 'name' => 'PHP :: Bug #$1', | |
296 | + 'type' => 'redmine', // type: redmine, jira or git | |
297 | + 'title' => 'PHP :: Bug #$1', | |
298 | 298 | 'base_url' => 'https://bugs.php.net/bug.php?id=', |
299 | 299 | ), |
300 | - */ | |
300 | + array( | |
301 | + 'key' => 'asfjira', | |
302 | + 'type' => 'jira', | |
303 | + 'title' => 'ASF JIRA [$1]', | |
304 | + 'base_url' => 'https://issues.apache.org/jira/browse/', | |
305 | + ), | |
306 | + array( | |
307 | + 'key' => 'pukiwiki-commit', | |
308 | + 'type' => 'git', | |
309 | + 'title' => 'PukiWiki revision $1', | |
310 | + 'base_url' => 'https://ja.osdn.net/projects/pukiwiki/scm/git/pukiwiki/commits/', | |
311 | + ), | |
312 | +*/ | |
301 | 313 | ); |
302 | 314 | |
303 | 315 | ///////////////////////////////////////////////// |
@@ -7,16 +7,24 @@ if (window.addEventListener) { | ||
7 | 7 | var headReText = '([\\s\\b]|^)'; |
8 | 8 | var tailReText = '\\b'; |
9 | 9 | var _siteList = getSiteListFromBody(); |
10 | - function ticketToUrl(keyText) { | |
10 | + function ticketToLink(keyText) { | |
11 | 11 | var siteList = getSiteList(); |
12 | 12 | for (var i = 0; i < siteList.length; i++) { |
13 | 13 | var site = siteList[i]; |
14 | 14 | var m = keyText.match(site.re); |
15 | 15 | if (m) { |
16 | - return site.base_url + m[3]; | |
16 | + var title = site.title; | |
17 | + var ticketKey = m[3] | |
18 | + if (title) { | |
19 | + title = title.replace(/\$1/g, ticketKey); | |
20 | + } | |
21 | + return { | |
22 | + url: site.base_url + m[3], | |
23 | + title: title | |
24 | + }; | |
17 | 25 | } |
18 | 26 | } |
19 | - return ''; | |
27 | + return null; | |
20 | 28 | } |
21 | 29 | function regexEscape(key) { |
22 | 30 | return key.replace(/[\-\.]/g, function (m) { |
@@ -65,7 +73,7 @@ if (window.addEventListener) { | ||
65 | 73 | function textToSiteInfo(siteDef) { |
66 | 74 | if (!siteDef) return null; |
67 | 75 | var info = JSON.parse(siteDef); |
68 | - if (info && info.key && info.type && info.name && info.base_url) { | |
76 | + if (info && info.key && info.type && info.base_url) { | |
69 | 77 | return info; |
70 | 78 | } |
71 | 79 | return null; |
@@ -101,7 +109,9 @@ if (window.addEventListener) { | ||
101 | 109 | } |
102 | 110 | var a = document.createElement('a'); |
103 | 111 | a.textContent = m[2]; |
104 | - a.href = ticketToUrl(a.textContent); | |
112 | + var linkInfo = ticketToLink(a.textContent); | |
113 | + a.href = linkInfo.url; | |
114 | + a.title = linkInfo.title; | |
105 | 115 | f.appendChild(a); |
106 | 116 | text = text.substr(m.index + m[0].length); |
107 | 117 | } |