@@ -18,6 +18,9 @@ package lt.dvim.authors
1818
1919import java .io .File
2020
21+ import scala .collection .JavaConverters ._
22+ import scala .concurrent .{ExecutionContext , Future }
23+
2124import akka .NotUsed
2225import akka .actor .ActorSystem
2326import akka .event .{Logging , LoggingAdapter }
@@ -27,47 +30,31 @@ import akka.http.scaladsl.marshalling.PredefinedToRequestMarshallers._
2730import akka .http .scaladsl .model .{HttpRequest , Uri }
2831import akka .stream .scaladsl .{Flow , Source }
2932import akka .util .ByteString
33+
34+ import com .madgag .git ._
3035import com .tradeshift .reaktive .marshal .stream .{ActsonReader , ProtocolReader }
3136import org .eclipse .jgit .diff .DiffFormatter
3237import org .eclipse .jgit .internal .storage .file .FileRepository
33- import org .eclipse .jgit .util .io .DisabledOutputStream
34- import com .madgag .git ._
35- import lt .dvim .authors .GithubProtocol .{AuthorStats , Commit , Stats }
3638import org .eclipse .jgit .storage .file .FileRepositoryBuilder
39+ import org .eclipse .jgit .util .io .DisabledOutputStream
3740
38- import scala .collection .JavaConverters ._
39- import scala .concurrent .{Await , ExecutionContext , Future }
40- import scala .concurrent .duration ._
41+ import lt .dvim .authors .GithubProtocol .{AuthorStats , Commit , Stats }
4142
4243object Authors {
4344 final val MaxAuthors = 1024
4445 final val GithubApiUrl = " api.github.com"
4546
46- def main (args : Array [String ]) = {
47- val (repo, from, to, path) = args.toList match {
48- case repo :: from :: to :: path :: Nil => (repo, from, to, path)
49- case _ =>
50- println("""
51- |Usage:
52- | <repo> <from> <to> <path>
53- """ .stripMargin)
54- System .exit(1 )
55- ???
56- }
57-
58- val future = summary(repo, from, to, path)
59- println(Await .result(future, 30 .seconds))
60- }
61-
62- def summary (repo : String , from : String , to : String , path : String ): Future [String ] = {
47+ def summary (repo : Option [String ], from : String , to : String , path : String ): Future [String ] = {
6348 val cld = classOf [ActorSystem ].getClassLoader
6449 implicit val sys = ActorSystem (" Authors" , classLoader = Some (cld))
6550 implicit val gitRepository = Authors .gitRepo(path)
6651 implicit val log = Logging (sys, this .getClass)
6752
6853 import sys .dispatcher
54+ def parsedRepo =
55+ parseRepo(gitRepository.getConfig().getString(" remote" , " origin" , " url" ))
6956
70- DiffSource (repo, from, to)
57+ DiffSource (repo.getOrElse(parsedRepo) , from, to)
7158 .via(ActsonReader .instance)
7259 .via(ProtocolReader .of(GithubProtocol .compareProto))
7360 .via(StatsAggregator ())
@@ -82,6 +69,9 @@ object Authors {
8269 }
8370 }
8471
72+ def parseRepo (originUrl : String ): String =
73+ originUrl.split(" github.com" ).tail.head.drop(1 ).split(" .git" ).head
74+
8575 def gitRepo (path : String ): FileRepository =
8676 FileRepositoryBuilder
8777 .create(new File (if (path.contains(" .git" )) path else path + " /.git" ))
0 commit comments