Skip to content

Commit e482698

Browse files
committed
Update to latests play-git-hub
Now shared with gu-who & prout.
1 parent 6109796 commit e482698

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

app/lib/Bot.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package lib
22

3-
import java.nio.file.Paths
3+
import com.madgag.github.GitHubCredentials
44

5-
import com.madgag.github.OkGitHub
5+
import scalax.file.ImplicitConversions._
6+
import scalax.file.Path
67

78
object Bot {
89

9-
val okGitHub = new OkGitHub(Paths.get("/tmp/submitgit/working-dir/http-response-cache/"))
10+
val workingDir = Path.fromString("/tmp") / "bot" / "working-dir"
1011

1112
import play.api.Play.current
1213
val config = play.api.Play.configuration
1314

1415
val accessToken = config.getString("github.botAccessToken").get
1516

16-
def conn() = okGitHub.conn(accessToken)
17+
val ghCreds = GitHubCredentials.forAccessKey(accessToken, workingDir.toPath).get
18+
19+
def conn() = ghCreds.conn()
1720
}

app/lib/actions/Actions.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package lib.actions
22

33
import com.madgag.github.Implicits._
44
import com.madgag.github.{PullRequestId, RepoId}
5-
import com.madgag.playgithub.auth.GHRequest
5+
import com.madgag.playgithub.auth.AuthenticatedSessions.AccessToken
6+
import com.madgag.playgithub.auth.{Client, GHRequest}
67
import controllers.Application._
78
import controllers.Auth
89
import lib._
@@ -15,26 +16,30 @@ import play.api.mvc._
1516
import scala.concurrent.ExecutionContext.Implicits.global
1617
import scala.concurrent.Future
1718
import scala.util.{Failure, Success, Try}
19+
import scalax.file.ImplicitConversions._
1820

1921

2022
object Actions {
2123
private val authScopes = Seq("user:email")
2224

23-
val GitHubAuthenticatedAction = com.madgag.playgithub.auth.Actions.githubAction(authScopes)(Auth.authClient)
25+
implicit val authClient: Client = Auth.authClient
26+
27+
implicit val provider = AccessToken.FromSession
28+
29+
val GitHubAuthenticatedAction = com.madgag.playgithub.auth.Actions.gitHubAction(authScopes, Bot.workingDir.toPath)
2430

2531
def githubRepoAction(repoId: RepoId) = GitHubAuthenticatedAction andThen new ActionRefiner[GHRequest, GHRepoRequest] {
2632
override protected def refine[A](request: GHRequest[A]): Future[Either[Result, GHRepoRequest[A]]] = Future {
2733
Either.cond(Project.byRepoId.contains(repoId), {
28-
val gitHub = request.gitHub
2934
val repo = Bot.conn().getRepository(repoId.fullName)
30-
new GHRepoRequest(gitHub, repo, request)}, Forbidden("Not a supported repo"))
35+
new GHRepoRequest(request.gitHubCredentials, repo, request)}, Forbidden("Not a supported repo"))
3136
}
3237
}
3338

3439
def githubPRAction(prId: PullRequestId) = githubRepoAction(prId.repo) andThen new ActionRefiner[GHRepoRequest, GHPRRequest] {
3540
override protected def refine[A](request: GHRepoRequest[A]): Future[Either[Result, GHPRRequest[A]]] = Future {
3641
Try(request.repo.getPullRequest(prId.num)) match {
37-
case Success(pr) => Right(new GHPRRequest[A](request.gitHub, pr, request))
42+
case Success(pr) => Right(new GHPRRequest[A](request.gitHubCredentials, pr, request))
3843
case Failure(e) => Left(NotFound(s"${request.repo.getFullName} doesn't seem to have PR #${prId.num}"))
3944
}
4045
}

app/lib/actions/requests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lib.actions
22

33
import com.madgag.git._
4+
import com.madgag.github.GitHubCredentials
45
import com.madgag.github.Implicits._
56
import com.madgag.okhttpscala._
67
import com.madgag.playgithub.auth.GHRequest
@@ -20,9 +21,9 @@ object Requests {
2021
lazy val userEmail = req.user.primaryEmail
2122
}
2223

23-
class GHRepoRequest[A](gitHub: GitHub, val repo: GHRepository, request: Request[A]) extends GHRequest[A](gitHub, request)
24+
class GHRepoRequest[A](gitHubCredentials: GitHubCredentials, val repo: GHRepository, request: Request[A]) extends GHRequest[A](gitHubCredentials, request)
2425

25-
class GHPRRequest[A](gitHub: GitHub, val pr: GHPullRequest, request: Request[A]) extends GHRepoRequest[A](gitHub, pr.getRepository, request) {
26+
class GHPRRequest[A](gitHubCredentials: GitHubCredentials, val pr: GHPullRequest, request: Request[A]) extends GHRepoRequest[A](gitHubCredentials, pr.getRepository, request) {
2627
lazy val userOwnsPR = user == pr.getUser
2728

2829
lazy val patchCommitsF: Future[Seq[PatchCommit]] = {

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resolvers ++= Seq(
3333
libraryDependencies ++= Seq(
3434
cache,
3535
filters,
36-
"com.madgag" %% "play-git-hub" % "1.1",
36+
"com.madgag" %% "play-git-hub" % "2.3",
3737
"com.typesafe.akka" %% "akka-agent" % "2.3.2",
3838
"org.webjars" % "bootstrap" % "3.3.5",
3939
"com.adrianhurt" %% "play-bootstrap3" % "0.4.4-P24",

0 commit comments

Comments
 (0)