github: Remove `get_repo_last_issue`
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 11 Jul 2019 01:20:16 +0000 (21:20 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 11 Jul 2019 01:42:15 +0000 (21:42 -0400)
This was a terrible hack...

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/github/api.nit
lib/github/loader.nit

index beb9bad..3cd1567 100644 (file)
@@ -263,16 +263,6 @@ class GithubAPI
                return deserialize(arr.to_json).as(Array[Issue])
        end
 
-       # Get the last published issue.
-       fun get_repo_last_issue(repo: Repo): nullable Issue do
-               var array = get("/repos/{repo.full_name}/issues")
-               if not array isa JsonArray then return null
-               if array.is_empty then return null
-               var obj = array.first
-               if not obj isa JsonObject then return null
-               return deserialize(obj.to_json).as(nullable Issue)
-       end
-
        # List of labels associated with their names.
        fun get_repo_labels(repo: Repo, page, per_page: nullable Int): Array[Label] do
                return new GithubArray[Label].from(get(
index 175f3d7..a58e25e 100644 (file)
@@ -329,24 +329,18 @@ class Loader
        fun get_issues(job: LoaderJob) do
                if config.no_issues then return
 
-               var i = job.last_issue
-               var last_issue = get_last_issue(job)
-               if last_issue != null then
-                       while i <= last_issue.number do
-                               get_issue(job, i)
-                               job.last_issue = i
+               var api = config.wallet.api
+               var page = 1
+               var issues = api.get_repo_issues(job.repo.full_name, page, 100)
+               while issues.not_empty do
+                       for issue in issues do
+                               get_issue(job, issue.number)
+                               job.last_issue = issue.number
                                jobs.save job
-                               i += 1
                        end
                end
        end
 
-       # Load the `repo` last issue or abort.
-       private fun get_last_issue(job: LoaderJob): nullable Issue do
-               var api = config.wallet.api
-               return api.get_repo_last_issue(job.repo)
-       end
-
        # Load an issue or abort.
        private fun get_issue(job: LoaderJob, issue_number: Int) do
                if issues.find_by_id("{job.repo.mongo_id}/{issue_number}") != null then return