From d035a2d584311d97a4d2b59391cf10094a86de36 Mon Sep 17 00:00:00 2001 From: loddit Date: Sun, 16 Aug 2015 15:26:56 +0800 Subject: [PATCH] use Promise --- legilimens.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/legilimens.coffee b/legilimens.coffee index f217224..4200ae0 100644 --- a/legilimens.coffee +++ b/legilimens.coffee @@ -30,14 +30,14 @@ getClosedPullRequestsAfter = (time) -> new Date(pullRequest.merged_at) > time printPullRequestsReport(pullRequests) -getLastedReleaseTime = (callback) -> +getLastedReleaseTime = new Promise (resolve, reject) -> callGithubAPI (repoUrl + LATEST_RELEASE_PATH), (error, response, body) -> if (!error and response.statusCode isnt 200) - console.log error, body + reject error else lastedReleaseTime = new Date(JSON.parse(body).created_at) console.log lastedReleaseTime - callback(lastedReleaseTime) + resolve(lastedReleaseTime) printPullRequestsReport = (pullRequests) -> index = 1 @@ -45,4 +45,4 @@ printPullRequestsReport = (pullRequests) -> console.log "#{index}. #{pullRequest.title} by @#{pullRequest.user.login}" index++ -getLastedReleaseTime(getClosedPullRequestsAfter) +getLastedReleaseTime.then getClosedPullRequestsAfter