Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch Pull Request info only when workspace is a GitHub Repository #7

Merged
merged 1 commit into from Mar 2, 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
52 changes: 27 additions & 25 deletions lib/gh-client.coffee
Expand Up @@ -156,29 +156,31 @@ module.exports = new class GitHubClient
_tick: ->
@updateRepoBranch() # Sometimes the branch name does not update

unless @repoOwner and @repoName and @branchName
@emitter.emit 'did-update', []
if @repoOwner and @repoName and @branchName
@_fetchComments()
.then (comments) =>
@emitter.emit('did-update', comments)
.then undefined, (err) ->
unless @hasShownConnectionError
@hasShownConnectionError = true
try
# If the rate limit was exceeded show a specific Error message
url = JSON.parse(err.message).documentation_url
if url is 'https://developer.github.com/v3/#rate-limiting'
atom.notifications.addError 'Rate limit exceeded for talking to GitHub API',
dismissable: true
detail: 'You have exceeded the rate limit for anonymous access to the GitHub API. You will need to wait an hour or create a token from https://github.com/settings/tokens and add it to the settings for this plugin'
# yield [] so consumers still run
return []
catch error

atom.notifications.addError 'Error fetching Pull Request data from GitHub',
dismissable: true
detail: 'Make sure you are connected to the internet and if this is a private repository then you will need to create a token from https://github.com/settings/tokens'

# yield [] so consumers still run
[]

@_fetchComments()
.then (comments) =>
@emitter.emit('did-update', comments)
.then undefined, (err) ->
unless @hasShownConnectionError
@hasShownConnectionError = true
try
# If the rate limit was exceeded show a specific Error message
url = JSON.parse(err.message).documentation_url
if url is 'https://developer.github.com/v3/#rate-limiting'
atom.notifications.addError 'Rate limit exceeded for talking to GitHub API',
dismissable: true
detail: 'You have exceeded the rate limit for anonymous access to the GitHub API. You will need to wait an hour or create a token from https://github.com/settings/tokens and add it to the settings for this plugin'
# yield [] so consumers still run
return []
catch error

atom.notifications.addError 'Error fetching Pull Request data from GitHub',
dismissable: true
detail: 'Make sure you are connected to the internet and if this is a private repository then you will need to create a token from https://github.com/settings/tokens'

# yield [] so consumers still run
[]
else
# No repo info (not a GitHub Repo)
@emitter.emit 'did-update', []
2 changes: 1 addition & 1 deletion lib/pr-linter.coffee
Expand Up @@ -164,4 +164,4 @@ module.exports = new class # This only needs to be a class to bind lint()

# Filter out all the comments that no longer apply since the source was changed
allMessages = allMessages.concat(lintWarningsOrNull.filter (lintWarning) -> !!lintWarning)
@linter?.setMessages(allMessages)
@linter.setMessages(allMessages)