Skip to content

Commit

Permalink
use obejct params for callGitHubAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
loddit committed Aug 16, 2015
1 parent 7f3bb5e commit d9979ad
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions legilimens.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repoName = 'reponame'

repoUrl = "#{GITHUB_REPO_API_ROOT}#{repoOwner}/#{repoName}"

callGithubAPI = (url, callback = (error, response, body) -> {}) ->
callGithubAPI = ({url, callback}) ->
request
url: url
headers:
Expand All @@ -21,31 +21,37 @@ callGithubAPI = (url, callback = (error, response, body) -> {}) ->
password: password
, callback

getClosedPullRequestsAfter = (time) ->
callGithubAPI (repoUrl + RECENT_CLOSED_PR_PATH), (error, response, body) ->
if (!error and response.statusCode isnt 200)
console.log error, body
else
pullRequests = JSON.parse(body).filter (pullRequest) ->
new Date(pullRequest.merged_at) > time
if pullRequests.length
printPullRequestsReport(pullRequests)
getLastedReleaseTime = new Promise (resolve, reject) ->
callGithubAPI
url: repoUrl + LATEST_RELEASE_PATH
callback: (error, response, body) ->
if (!error and response.statusCode isnt 200)
console.log error, body
reject error
else
console.log 'No new pull requests be merged.'
lastedReleaseTime = new Date(JSON.parse(body).created_at)
console.log "Last release time is #{lastedReleaseTime.toLocaleTimeString()} #{lastedReleaseTime.toLocaleDateString()}"
resolve(lastedReleaseTime)

getLastedReleaseTime = new Promise (resolve, reject) ->
callGithubAPI (repoUrl + LATEST_RELEASE_PATH), (error, response, body) ->
if (!error and response.statusCode isnt 200)
reject error
else
lastedReleaseTime = new Date(JSON.parse(body).created_at)
console.log "Last release time is #{lastedReleaseTime.toLocaleTimeString()} #{lastedReleaseTime.toLocaleDateString()}"
resolve(lastedReleaseTime)
getClosedPullRequestsAfter = (time) ->
callGithubAPI
url: repoUrl + RECENT_CLOSED_PR_PATH
callback: (error, response, body) ->
if (!error and response.statusCode isnt 200)
console.log error, body
else
pullRequests = JSON.parse(body).filter (pullRequest) ->
new Date(pullRequest.merged_at) > time
if pullRequests.length
printPullRequestsReport(pullRequests)
else
console.log 'No new pull requests be merged.'

printPullRequestsReport = (pullRequests) ->
index = 1
pullRequests.forEach (pullRequest) ->
console.log "#{index}. #{pullRequest.title} by @#{pullRequest.user.login}"
index++

getLastedReleaseTime.then getClosedPullRequestsAfter
getLastedReleaseTime.then (lastedReleaseTime) ->
getClosedPullRequestsAfter(lastedReleaseTime)

0 comments on commit d9979ad

Please sign in to comment.