Replace github refference with link travis-ci/travis-ci#1266
Github issue refference is now replaced with github issue url. This covers following refferences: * #Num * User#Num * User/Project#Num
This commit is contained in:
parent
072a5de579
commit
44c7c627fb
|
@ -28,8 +28,8 @@ Ember.registerBoundHelper 'formatSha', (sha, options) ->
|
||||||
Ember.registerBoundHelper 'pathFrom', (url, options) ->
|
Ember.registerBoundHelper 'pathFrom', (url, options) ->
|
||||||
safe Travis.Helpers.pathFrom(url)
|
safe Travis.Helpers.pathFrom(url)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatMessage', (message, options) ->
|
Ember.Handlebars.helper 'formatMessage', (message, options) ->
|
||||||
safe Travis.Helpers.formatMessage(message, options)
|
safe Travis.Helpers.formatMessage(message, options.hash)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatConfig', (config, options) ->
|
Ember.registerBoundHelper 'formatConfig', (config, options) ->
|
||||||
safe Travis.Helpers.formatConfig(config)
|
safe Travis.Helpers.formatConfig(config)
|
||||||
|
|
|
@ -37,7 +37,10 @@ require 'config/emoij'
|
||||||
formatMessage: (message, options) ->
|
formatMessage: (message, options) ->
|
||||||
message = message || ''
|
message = message || ''
|
||||||
message = message.split(/\n/)[0] if options.short
|
message = message.split(/\n/)[0] if options.short
|
||||||
@_emojize(@_escape(message)).replace /\n/g, '<br/>'
|
message = @_emojize(@_escape(message))
|
||||||
|
if !!options.repo
|
||||||
|
message = @githubify(message, options.repo.get('owner'), options.repo.get('name'))
|
||||||
|
message.replace /\n/g, '<br/>'
|
||||||
|
|
||||||
pathFrom: (url) ->
|
pathFrom: (url) ->
|
||||||
(url || '').split('/').pop()
|
(url || '').split('/').pop()
|
||||||
|
@ -66,6 +69,26 @@ require 'config/emoij'
|
||||||
result.push seconds + ' sec' if seconds > 0
|
result.push seconds + ' sec' if seconds > 0
|
||||||
if result.length > 0 then result.join(' ') else '-'
|
if result.length > 0 then result.join(' ') else '-'
|
||||||
|
|
||||||
|
githubify: (text, owner, repo) ->
|
||||||
|
refferences = text.match(@_githubRefferenceRegexp('g'))
|
||||||
|
if !!refferences
|
||||||
|
self = this
|
||||||
|
for refference in refferences
|
||||||
|
do (refference) ->
|
||||||
|
text = text.replace refference, (refference) ->
|
||||||
|
self._githubRefferenceLink(refference, owner, repo)
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
_githubRefferenceLink: (refference, owner, repo) ->
|
||||||
|
[newOwner, newRepo, issue] = refference.match(@_githubRefferenceRegexp())[1..3]
|
||||||
|
actualOwner = if newOwner? then newOwner else owner
|
||||||
|
actualRepo = if newRepo? then newRepo else repo
|
||||||
|
"<a href=\"http://github.com/#{actualOwner}/#{actualRepo}/issues/#{issue}\">#{refference}</a>"
|
||||||
|
|
||||||
|
_githubRefferenceRegexp: (flags) ->
|
||||||
|
new RegExp("([\\w-]+)?\\/?([\\w-]+)?#(\\d+)", flags)
|
||||||
|
|
||||||
_normalizeDateString: (string) ->
|
_normalizeDateString: (string) ->
|
||||||
if window.JHW
|
if window.JHW
|
||||||
string = string.replace('T', ' ').replace(/-/g, '/')
|
string = string.replace('T', ' ').replace(/-/g, '/')
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
<td class="message">
|
<td class="message">
|
||||||
{{{formatMessage commit.message short="true"}}}
|
{{{formatMessage commit.message short="true" repoBinding=build.repo}}}
|
||||||
</td>
|
</td>
|
||||||
<td class="commit">
|
<td class="commit">
|
||||||
<a {{bindAttr href="view.urlGithubCommit"}}>
|
<a {{bindAttr href="view.urlGithubCommit"}}>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
{{/with}}
|
{{/with}}
|
||||||
|
|
||||||
<dt>{{t builds.message}}</dt>
|
<dt>{{t builds.message}}</dt>
|
||||||
<dd class="message">{{formatMessage build.commit.message}}</dd>
|
<dd class="message">{{formatMessage build.commit.message repoBinding=build.repo}}</dd>
|
||||||
|
|
||||||
{{#unless isMatrix}}
|
{{#unless isMatrix}}
|
||||||
<dt>{{t builds.config}}</dt>
|
<dt>{{t builds.config}}</dt>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/with}}
|
{{/with}}
|
||||||
<dt>{{t jobs.message}}</dt>
|
<dt>{{t jobs.message}}</dt>
|
||||||
<dd class="message">{{formatMessage job.commit.message}}</dd>
|
<dd class="message">{{formatMessage job.commit.message repoBinding=job.repo}}</dd>
|
||||||
<dt>{{t jobs.config}}</dt>
|
<dt>{{t jobs.config}}</dt>
|
||||||
<dd class="config">{{formatConfig job.config}}</dd>
|
<dd class="config">{{formatConfig job.config}}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
31
assets/scripts/spec/unit/helpers_spec.coffee
Normal file
31
assets/scripts/spec/unit/helpers_spec.coffee
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module "Travis.Helpers.githubify"
|
||||||
|
|
||||||
|
test 'replaces #Num with github issues link', ->
|
||||||
|
message = 'Solved #11hey'
|
||||||
|
result = Travis.Helpers.githubify(message, 'travis-ci', 'travis-web')
|
||||||
|
expected = 'Solved <a href="http://github.com/travis-ci/travis-web/issues/11">#11</a>hey'
|
||||||
|
|
||||||
|
equal(result, expected, "#num should be converted to a link")
|
||||||
|
|
||||||
|
test 'replaces User#Num with github issues link to forked repo', ->
|
||||||
|
message = 'Solved test#11hey'
|
||||||
|
result = Travis.Helpers.githubify(message, 'travis-ci', 'travis-web')
|
||||||
|
expected = 'Solved <a href="http://github.com/test/travis-web/issues/11">test#11</a>hey'
|
||||||
|
|
||||||
|
equal(result, expected, "user#num should be converted to a link")
|
||||||
|
|
||||||
|
test 'replaces User#Num with github issues link to another repo', ->
|
||||||
|
message = 'Solved test/testing#11hey'
|
||||||
|
result = Travis.Helpers.githubify(message, 'travis-ci', 'travis-web')
|
||||||
|
expected = 'Solved <a href="http://github.com/test/testing/issues/11">test/testing#11</a>hey'
|
||||||
|
|
||||||
|
equal(result, expected, "owner/repo#num should be converted to a link")
|
||||||
|
|
||||||
|
test 'replaces multiple refferences with github issues links', ->
|
||||||
|
message = 'Try #1 and test#2 and test/testing#3'
|
||||||
|
result = Travis.Helpers.githubify(message, 'travis-ci', 'travis-web')
|
||||||
|
expected = 'Try <a href="http://github.com/travis-ci/travis-web/issues/1">#1</a> and '
|
||||||
|
expected += '<a href="http://github.com/test/travis-web/issues/2">test#2</a> and '
|
||||||
|
expected += '<a href="http://github.com/test/testing/issues/3">test/testing#3</a>'
|
||||||
|
|
||||||
|
equal(result, expected, "references should be converted to links")
|
Loading…
Reference in New Issue
Block a user