Skip to content

Commit

Permalink
update version check to check for upcoming repo rename
Browse files Browse the repository at this point in the history
  • Loading branch information
wilg committed May 1, 2017
1 parent d692ad7 commit a23ea9c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/version_checker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ semver = require('semver')

module.exports = (callback) ->

url = "#{npmPackage.repository.url.split("github.com").join("api.github.com/repos")}/releases/latest"
for repoUrl in [npmPackage.repository.url, "https://github.com/looker/lookerbot"]

request {url: url, headers: {"User-Agent": npmPackage.repository.url}}, (error, response, body) ->
if error
console.error "Could not check version at #{url}"
callback(null)
else if response.statusCode == 200
json = JSON.parse(body)
if semver.gt(json.tag_name, npmPackage.version)
console.log "Found update: #{json.tag_name} is newer than #{npmPackage.version}"
callback(json)
else
url = "#{repoUrl.split("github.com").join("api.github.com/repos")}/releases/latest"

request {url: url, headers: {"User-Agent": npmPackage.repository.url}}, (error, response, body) ->
if error
console.error "Could not check version at #{url}"
callback(null)
else
console.error "Version check at #{url} returned a non-200 status code."
console.error body
callback(null)
else if response.statusCode == 200
json = JSON.parse(body)
if semver.gt(json.tag_name, npmPackage.version)
console.log "Found update: #{json.tag_name} is newer than #{npmPackage.version}"
callback(json)
else
console.log "Checked for updates from #{url}. No new version available."
callback(null)
else
console.error "Version check at #{url} returned a non-200 status code."
console.error body

4 comments on commit a23ea9c

@reedloden
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when is the rename happening? Right now, the update check is failing due to missing repo. :)

@wilg
Copy link
Contributor Author

@wilg wilg commented on a23ea9c May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently should be doing two update checks, one against the current repo name and one against the old one. Unless I screwed that up...

@reedloden
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilg ah, that makes sense, and now I see it from reading the code. I just kept seeing version check failures because of the 404.

@wilg
Copy link
Contributor Author

@wilg wilg commented on a23ea9c May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I'm waiting a while to hopefully get people to upgrade to the version that includes this change before making the migration. I think GitHub may end up redirecting when I rename anyway, but better safe than sorry!

Please sign in to comment.