Skip to content

Commit 22ba61e

Browse files
committed
Add Contributor class
1 parent 00b1a68 commit 22ba61e

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

github/git/Contributor.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package git
2+
3+
final case class Contributor(author: String, commits: Int)

github/git/Repo.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import scala.util.Success
1111

1212
import git.Lang.*
1313
import git.Commit
14+
import git.Contributor
1415

1516
class Repo(val owner: String, val repoName: String):
1617
lazy val localRepo = cloneRepo()
@@ -29,11 +30,12 @@ class Repo(val owner: String, val repoName: String):
2930
val commits = Commit.commitsFromJson(json)
3031
if (isLast(response)) commits else commits ++= getCommits(page + 1)
3132

32-
def getContributors(): Map[String, Int] =
33+
def getContributors(): List[Contributor] =
3334
getCommits()
3435
.groupBy(_.author)
3536
.mapValues(seq => seq.length)
36-
.toMap
37+
.map((author, commits) => Contributor(author, commits))
38+
.toList
3739

3840
def getOpenIssuesWithoutAnswers(page: Int = 1): ArrayBuffer[Uri] =
3941
val request = basicRequest

github/main.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import sttp.client3._
77
import sys.error
88
import git.Repo
99
import git.Commit
10+
import git.Contributor
1011
import java.nio.file.Path
1112

1213
@main
1314
def main(operation: String, owner: String, repoName: String) =
1415
val repo = Repo(owner, repoName)
1516
operation match
1617
case "contributors" => repo.getContributors()
17-
.toSeq
18-
.sortWith(_._2 > _._2)
19-
.foreach((author, count) => println(s"$author,$count"))
18+
.sortWith(_.commits > _.commits)
19+
.foreach(c => println(s"$c.author,$c.count"))
2020
case "commits" => repo.getCommits()
2121
.foreach(commit => println(s"$commit.author,$commit.date"))
2222
case "lines" => repo.lineCountPerLanguage()

github/test/RepoTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class RepoTest extends munit.FunSuite:
2424
// when
2525
val contributorsObtained = repo.getContributors()
2626
// then
27-
val contributorsExpected = Map(
28-
"octocat" -> 3
27+
val contributorsExpected = List(
28+
Contributor("octocat", 3)
2929
)
3030
assertEquals(contributorsObtained, contributorsExpected)
3131
}

0 commit comments

Comments
 (0)