Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Use bit.ly instead of git.io. #114

Merged
merged 2 commits into from Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 4 additions & 10 deletions lib/notification-issue.coffee
Expand Up @@ -40,16 +40,10 @@ class NotificationIssue
getIssueUrlForSystem: ->
new Promise (resolve, reject) =>
@getIssueUrl().then (issueUrl) ->
if UserUtilities.getPlatform() is 'win32'
# win32 can only handle a 2048 length link, so we use the shortener.
$.ajax 'https://git.io',
type: 'POST'
data: url: issueUrl
success: (data, status, xhr) ->
resolve(xhr.getResponseHeader('Location'))
error: -> resolve(issueUrl)
else
resolve(issueUrl)
issueUrl = encodeURIComponent(issueUrl)
$.ajax "https://api-ssl.bitly.com/v3/shorten?access_token=04ffc90d972077e493f9958177db31410cb23973&format=json&longUrl=#{issueUrl}",
success: (data) -> resolve(data.data.url)
error: -> resolve(issueUrl)
return

getIssueUrl: ->
Expand Down
62 changes: 9 additions & 53 deletions spec/notifications-spec.coffee
Expand Up @@ -314,10 +314,7 @@ describe "Notifications", ->

button = fatalError.querySelector('.btn')
expect(button.textContent).toContain 'Create issue on the notifications package'
unless process.platform is 'win32'
expect(button.getAttribute('href')).toContain 'atom/notifications/issues/new'
else
expect(button.getAttribute('href')).toContain 'git.io/cats'
expect(button.getAttribute('href')).toContain 'bit.ly/cats'

expect(issueTitle).toContain '$ATOM_HOME'
expect(issueTitle).not.toContain process.env.ATOM_HOME
Expand Down Expand Up @@ -586,10 +583,7 @@ describe "Notifications", ->

button = fatalError.querySelector('.btn')
expect(button.textContent).toContain 'Create issue on atom/atom'
unless process.platform is 'win32'
expect(button.getAttribute('href')).toContain 'atom/atom/issues/new'
else
expect(button.getAttribute('href')).toContain 'git.io/cats'
expect(button.getAttribute('href')).toContain 'bit.ly/cats'

expect(issueBody).toContain 'ReferenceError: a is not defined'
expect(issueBody).toContain '**Thrown From**: Atom Core'
Expand Down Expand Up @@ -628,10 +622,7 @@ describe "Notifications", ->
fatalNotification = fatalError.querySelector('.fatal-notification')
expect(button.textContent).toContain 'Create issue'
expect(fatalNotification.textContent).toContain 'You can help by creating an issue'
unless process.platform is 'win32'
expect(button.getAttribute('href')).toContain 'github.com/atom/notifications/issues/new'
else
expect(button.getAttribute('href')).toContain 'git.io/cats'
expect(button.getAttribute('href')).toContain 'bit.ly/cats'

describe "when the error has not been reported", ->
beforeEach ->
Expand Down Expand Up @@ -660,44 +651,7 @@ describe "Notifications", ->
button = fatalError.querySelector('.btn')
encodedMessage = encodeURI(truncatedMessage)
expect(button.textContent).toContain 'Create issue'
unless process.platform is 'win32'
expect(button.getAttribute('href')).toContain "github.com/atom/notifications/issues/new?title=#{encodedMessage}&body="
else
expect(button.getAttribute('href')).toContain 'git.io/cats'

describe "when the system is darwin", ->
beforeEach ->
UserUtilities = require '../lib/user-utilities'
spyOn(UserUtilities, 'getPlatform').andReturn 'darwin'

generateFakeAjaxResponses()
generateException()
fatalError = notificationContainer.querySelector('atom-notification.fatal')
waitsForPromise ->
fatalError.getRenderPromise().then -> issueBody = fatalError.issue.issueBody

it "asks the user to create an issue", ->
button = fatalError.querySelector('.btn')
fatalNotification = fatalError.querySelector('.fatal-notification')
expect(button.textContent).toContain 'Create issue'
expect(fatalNotification.textContent).toContain 'You can help by creating an issue'
expect(button.getAttribute('href')).toContain 'github.com/atom/notifications/issues/new'

describe "when the system is win32", ->
beforeEach ->
UserUtilities = require '../lib/user-utilities'
spyOn(UserUtilities, 'getPlatform').andReturn 'win32'

generateFakeAjaxResponses()
generateException()
fatalError = notificationContainer.querySelector('atom-notification.fatal')
waitsForPromise ->
fatalError.getRenderPromise().then -> issueBody = fatalError.issue.issueBody

it "uses a shortened url via git.io", ->
button = fatalError.querySelector('.btn')
expect(button.textContent).toContain 'Create issue'
expect(button.getAttribute('href')).toContain 'git.io'
expect(button.getAttribute('href')).toContain 'bit.ly/cats'

describe "when the package is out of date", ->
beforeEach ->
Expand Down Expand Up @@ -921,9 +875,11 @@ generateException = ->
# issuesResponse
generateFakeAjaxResponses = (options) ->
$.ajax.andCallFake (url, settings) ->
if url.indexOf('git.io') > -1
response = options?.shortenerResponse ? ['--', '201', {getResponseHeader: -> 'https://git.io/cats'}]
settings.success.apply(settings, response)
if url.indexOf('bitly.com') > -1
response = options?.shortenerResponse ? {
data: url: 'http://bit.ly/cats'
}
settings.success(response)
else if url.indexOf('atom.io/api/packages') > -1
response = options?.packageResponse ? {
repository: url: 'https://github.com/atom/notifications'
Expand Down