Skip to content

Commit 8ee0d66

Browse files
committed
Fix rate limits for bot
1 parent a5245eb commit 8ee0d66

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

bot/src/dotty/tools/bot/Main.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import scalaz.concurrent.Task
77

88
object Main extends ServerApp with PullRequestService {
99

10-
val githubUser = sys.env("GITHUB_USER")
11-
val githubToken = sys.env("GITHUB_TOKEN")
12-
val droneToken = sys.env("DRONE_TOKEN")
13-
val port = sys.env("PORT").toInt
10+
val githubUser = sys.env("GITHUB_USER")
11+
val githubToken = sys.env("GITHUB_TOKEN")
12+
val githubClientId = sys.env("GITHUB_CLIENT_ID")
13+
val githubClientSecret = sys.env("GITHUB_CLIENT_SECRET")
14+
val droneToken = sys.env("DRONE_TOKEN")
15+
val port = sys.env("PORT").toInt
1416

1517
/** Services mounted to the server */
1618
final val services = prService

bot/src/dotty/tools/bot/PullRequestService.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ trait PullRequestService {
3434
/** OAuth token for drone, needed to cancel builds */
3535
def droneToken: String
3636

37+
/** OAuthed application's "client_id" */
38+
def githubClientId: String
39+
40+
/** OAuthed application's "client_secret" */
41+
def githubClientSecret: String
42+
3743
/** Pull Request HTTP service */
3844
val prService = HttpService {
3945
case request @ POST -> Root =>
@@ -68,21 +74,23 @@ trait PullRequestService {
6874
)
6975

7076
private[this] val githubUrl = "https://api.github.com"
77+
private[this] def withGithubSecret(url: String, extras: String*): String =
78+
s"$url?client_id=$githubClientId&client_secret=$githubClientSecret" + extras.mkString("&", "&", "")
7179

7280
def claUrl(userName: String): String =
7381
s"https://www.lightbend.com/contribute/cla/scala/check/$userName"
7482

7583
def commitsUrl(prNumber: Int): String =
76-
s"$githubUrl/repos/lampepfl/dotty/pulls/$prNumber/commits?per_page=100"
84+
withGithubSecret(s"$githubUrl/repos/lampepfl/dotty/pulls/$prNumber/commits", "per_page=100")
7785

7886
def statusUrl(sha: String): String =
79-
s"$githubUrl/repos/lampepfl/dotty/statuses/$sha"
87+
withGithubSecret(s"$githubUrl/repos/lampepfl/dotty/statuses/$sha")
8088

8189
def issueCommentsUrl(issueNbr: Int): String =
82-
s"$githubUrl/repos/lampepfl/dotty/issues/$issueNbr/comments"
90+
withGithubSecret(s"$githubUrl/repos/lampepfl/dotty/issues/$issueNbr/comments")
8391

8492
def reviewUrl(issueNbr: Int): String =
85-
s"$githubUrl/repos/lampepfl/dotty/pulls/$issueNbr/reviews"
93+
withGithubSecret(s"$githubUrl/repos/lampepfl/dotty/pulls/$issueNbr/reviews")
8694

8795
sealed trait CommitStatus {
8896
def commit: Commit

bot/test/PRServiceTests.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import org.http4s.client.Client
1515
import scalaz.concurrent.Task
1616

1717
class PRServiceTests extends PullRequestService {
18-
val githubUser = sys.env("GITHUB_USER")
19-
val githubToken = sys.env("GITHUB_TOKEN")
20-
val droneToken = sys.env("DRONE_TOKEN")
18+
val githubUser = sys.env("GITHUB_USER")
19+
val githubToken = sys.env("GITHUB_TOKEN")
20+
val droneToken = sys.env("DRONE_TOKEN")
21+
val githubClientId = sys.env("GITHUB_CLIENT_ID")
22+
val githubClientSecret = sys.env("GITHUB_CLIENT_SECRET")
2123

2224
private def withClient[A](f: Client => Task[A]): A = {
2325
val httpClient = PooledHttp1Client()

0 commit comments

Comments
 (0)