-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCommand.scala
34 lines (28 loc) · 904 Bytes
/
Command.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package codecheck.github.app
import codecheck.github.api.GitHubAPI
import codecheck.github.api.RepositoryAPI
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import codecheck.github.utils.Json4s
trait Command {
implicit val formats = Json4s.formats
val api: GitHubAPI
def parseRepo(str: String, origin: Option[Repo] = None): Repo = {
val split = str.split("/")
if (split.length == 2) {
Repo(split(0), split(1))
} else {
Repo(origin.map(_.owner).getOrElse(api.user.login), str)
}
}
def withRepo(repo: Option[Repo])(f: RepositoryAPI => Future[Any]): Future[Any] = {
repo.map { v =>
val rapi = api.repositoryAPI(v.owner, v.name)
f(rapi)
}.getOrElse {
println("Repository not specified")
Future(false)
}
}
def run(setting: CommandSetting, args: List[String]): Future[CommandSetting]
}