 
   # Public
   open: (lineRange) ->
-    if @isOpenable()
-      @blobUrl().then (blobUrl) =>
-        @openUrlInBrowser(blobUrl + @getLineRangeSuffix(lineRange))
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @blobUrl().then (blobUrl) =>
+          @openUrlInBrowser(blobUrl + @getLineRangeSuffix(lineRange))
+      else
+        @reportValidationErrors()
 
   # Public
   openOnMaster: (lineRange) ->
-    if @isOpenable()
-      @blobUrlForMaster().then (blobUrlForMaster) =>
-        @openUrlInBrowser(blobUrlForMaster + @getLineRangeSuffix(lineRange))
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @blobUrlForMaster().then (blobUrlForMaster) =>
+          @openUrlInBrowser(blobUrlForMaster + @getLineRangeSuffix(lineRange))
+      else
+        @reportValidationErrors()
 
   # Public
   blame: (lineRange) ->
-    if @isOpenable()
-      @blameUrl().then (blameUrl) =>
-        @openUrlInBrowser(blameUrl + @getLineRangeSuffix(lineRange))
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @blameUrl().then (blameUrl) =>
+          @openUrlInBrowser(blameUrl + @getLineRangeSuffix(lineRange))
+      else
+        @reportValidationErrors()
 
   history: ->
-    if @isOpenable()
-      @openUrlInBrowser(@historyUrl())
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @historyUrl().then (historyUrl) =>
+          @openUrlInBrowser(historyUrl)
+      else
+        @reportValidationErrors()
 
   copyUrl: (lineRange) ->
-    if @isOpenable()
-      @shaUrl().then (shaUrl) =>
-        atom.clipboard.write(shaUrl + @getLineRangeSuffix(lineRange))
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @shaUrl().then (shaUrl) =>
+          atom.clipboard.write(shaUrl + @getLineRangeSuffix(lineRange))
+      else
+        @reportValidationErrors()
 
   openBranchCompare: ->
-    if @isOpenable()
-      @branchCompareUrl().then (branchCompareUrl) =>
-        @openUrlInBrowser(branchCompareUrl)
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @branchCompareUrl().then (branchCompareUrl) =>
+          @openUrlInBrowser(branchCompareUrl)
+      else
+        @reportValidationErrors()
 
   openIssues: ->
-    if @isOpenable()
-      @issuesUrl().then (issuesUrl) =>
-        @openUrlInBrowser(issuesUrl
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @issuesUrl().then (issuesUrl) =>
+          @openUrlInBrowser(issuesUrl)
+      else
+        @reportValidationErrors()
 
   openRepository: ->
-    if @isOpenable()
-      @gitHubRepoUrl().then (gitHubRepoUrl) =>
-        @openUrlInBrowser(gitHubRepoUrl)
-    else
-      @reportValidationErrors()
+    @isOpenable().then (isOpenable) =>
+      if isOpenable
+        @gitHubRepoUrl().then (gitHubRepoUrl) =>
+          @openUrlInBrowser(gitHubRepoUrl)
+      else
+        @reportValidationErrors()
 
   getLineRangeSuffix: (lineRange) ->
     if lineRange and atom.config.get('open-on-github.includeLineNumbersInUrls')


  # Internal
  gitUrl: ->
    @remoteName().then (remoteOrBestGuess = 'origin') =>
      @repo.getConfigValue("remote.#{remoteOrBestGuess}.url", @filePath)

  # Internal
  gitHubRepoUrl: ->


  # Public
  isOpenable: ->
    @validationErrors().then (validationErrors) ->
      validationErrors.length is 0

  # Public
  validationErrors: ->
    unless @repo
      return Promise.resolve(["No repository found for path: #{@filePath}."])

    @gitUrl().then (gitUrl) =>
      unless gitUrl
        return @remoteName().then (remoteName) ->
          ["No URL defined for remote: #{remoteName}"]

      @gitHubRepoUrl().then (gitHubRepoUrl) =>
        unless gitHubRepoUrl
          return ["Remote URL is not hosted on GitHub: #{gitUrl}"]

        []

  # Internal
  reportValidationErrors: ->
    @validationErrors().then (validationErrors) ->
      message = validationErrors.join('\n')
      atom.notifications.addWarning(message)

  # Internal
  openUrlInBrowser: (url) ->
