Skip to content

Commit d008373

Browse files
committed
Replace ArrayBuffer with List
1 parent 22ba61e commit d008373

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

github/git/Commit.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import scala.util.Try
55

66
case class Commit(author: String, sha: String, date: String)
77
object Commit:
8-
def commitsFromJson(json: String): ArrayBuffer[Commit] =
9-
for commit <- ujson.read(json).arr
8+
def commitsFromJson(json: String): List[Commit] =
9+
for commit <- ujson.read(json).arr.toList
1010
yield
1111
val author = Try(commit("author")("login").str)
1212
.orElse(Try(commit("commit")("author")("name").str))
1313
.getOrElse("Unknown")
1414
val sha = commit("sha").str
1515
val date = Try(commit("commit")("author")("date").str).getOrElse("")
1616
Commit(author, sha, date)
17+

github/git/Repo.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import sttp.client3._
55
import sttp.model._
66
import os.Path
77

8-
import scala.collection.mutable.ArrayBuffer
98
import scala.util.Try
109
import scala.util.Success
1110

@@ -17,7 +16,7 @@ class Repo(val owner: String, val repoName: String):
1716
lazy val localRepo = cloneRepo()
1817
val client = SimpleHttpClient()
1918

20-
def getCommits(page: Int = 1): ArrayBuffer[Commit] =
19+
def getCommits(page: Int = 1): List[Commit] =
2120
val request = basicRequest
2221
.header("Accept", "application/vnd.github+json")
2322
.get(uri"https://api.github.com/repos/$owner/$repoName/commits?per_page=100&page=$page")
@@ -28,7 +27,7 @@ class Repo(val owner: String, val repoName: String):
2827
case Left(value) => error(value)
2928

3029
val commits = Commit.commitsFromJson(json)
31-
if (isLast(response)) commits else commits ++= getCommits(page + 1)
30+
if (isLast(response)) commits else commits ++ getCommits(page + 1)
3231

3332
def getContributors(): List[Contributor] =
3433
getCommits()
@@ -37,7 +36,7 @@ class Repo(val owner: String, val repoName: String):
3736
.map((author, commits) => Contributor(author, commits))
3837
.toList
3938

40-
def getOpenIssuesWithoutAnswers(page: Int = 1): ArrayBuffer[Uri] =
39+
def getOpenIssuesWithoutAnswers(page: Int = 1): List[Uri] =
4140
val request = basicRequest
4241
.header("Accept", "application/vnd.github+json")
4342
.get(uri"https://api.github.com/repos/$owner/$repoName/issues?per_page=100&page=$page")
@@ -47,13 +46,14 @@ class Repo(val owner: String, val repoName: String):
4746
case Right(content) => content
4847
case Left(value) => error(value)
4948

50-
val issues = for issue <- ujson.read(json).arr
51-
if issue("state").str == "open"
52-
if Try(issue("pull_request")).isFailure
53-
if hasNoComments(issue("comments_url").str)
54-
yield uri"${issue("html_url").str}"
49+
val issues =
50+
for issue <- ujson.read(json).arr.toList
51+
if issue("state").str == "open"
52+
if Try(issue("pull_request")).isFailure
53+
if hasNoComments(issue("comments_url").str)
54+
yield uri"${issue("html_url").str}"
5555

56-
if (isLast(response)) issues else issues ++= getOpenIssuesWithoutAnswers(page + 1)
56+
if (isLast(response)) issues else issues ++ getOpenIssuesWithoutAnswers(page + 1)
5757

5858
def lineCountPerLanguage(): Map[Lang, Int] =
5959
os.walk(localRepo, skip = _.last.equals(".git"))

github/test/RepoTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import munit._
22
import git._
33
import git.Lang.*
4-
import scala.collection.mutable.ArrayBuffer
54

65
class RepoTest extends munit.FunSuite:
76
test("getCommits") {
@@ -10,7 +9,7 @@ class RepoTest extends munit.FunSuite:
109
// when
1110
val commitsObtained = repo.getCommits()
1211
// then
13-
val commitsExpected = ArrayBuffer(
12+
val commitsExpected = List(
1413
Commit("octocat", "d0dd1f61b33d64e29d8bc1372a94ef6a2fee76a9", "2014-02-12T23:20:44Z"),
1514
Commit("octocat", "bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f", "2014-02-04T22:38:36Z"),
1615
Commit("octocat", "a30c19e3f13765a3b48829788bc1cb8b4e95cee4", "2014-02-04T22:38:24Z")

0 commit comments

Comments
 (0)