Skip to content

Commit

Permalink
github token from credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
kolov committed Jul 6, 2017
1 parent 449a893 commit d990f55
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ project/plugins/lib_managed/
project/plugins/src_managed/
project/plugins/target/
target/
*.idea
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")

scalacOptions := Seq("-deprecation", "-unchecked")

credentials += Credentials(Path.userHome / ".github" / "token")
resolvers += "Maven.org" at "http://repo1.maven.org/maven2"
pomIncludeRepository := { _ => false }
publishMavenStyle := true
Expand Down
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.5")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.akolov" % "sbt-pantarhei" % "0.0.3")
24 changes: 24 additions & 0 deletions src/it/scala/GithubIT.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.akolov.pantarhei.Github
import org.scalatest.WordSpecLike

class GithubIT extends WordSpecLike {

"The class Github" should {


"contain a parseUrl method" should {

"query pull requests" in {
val gh = Github("[email protected]:kolov/sbt-pantarhei.git")
val reqs = gh.getPullRequests(2)
reqs.foreach(println)
}

"query commits" in {
val gh = Github("[email protected]:kolov/sbt-pantarhei.git")
val reqs = gh.getCommits(1)
reqs.foreach(println)
}
}
}
}
5 changes: 2 additions & 3 deletions src/main/scala/Domain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import spray.json.{DefaultJsonProtocol, RootJsonFormat}

case class PullRequest(title: String, htmlUrl: String, number: Int)

case class Commit(message: String, url: String)
case class Commit(message: String)

case class CommitRecord(htmlUrl: String, commit: Commit)

Expand All @@ -19,8 +19,7 @@ object MyJsonProtocol extends DefaultJsonProtocol {

implicit val commitFormat: RootJsonFormat[Commit] = jsonFormat(
Commit,
"message",
"url")
"message")

implicit val commitRecordFormat: RootJsonFormat[CommitRecord] = jsonFormat(
CommitRecord,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/Github.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Github(remoteUrl: String, val token: String) {
.elements.take(max).map(e => pullRequestFormat.read(e))
}

def getCommits(number: Int): Seq[Commit] = {
def getCommits(number: Int): Seq[CommitRecord] = {
val response: HttpResponse[String] = Http(s"$apiUrl/pulls/$number/commits")
.header("Accept", "application/vnd.github.v3+json")
.header("Authorization", s"token $token")
.asString

response.body.parseJson.asInstanceOf[JsArray]
.elements.map(e => commitRecordFormat.read(e)).map(_.commit)
.elements.map(e => commitRecordFormat.read(e))
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/NotesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ object NotesPlugin extends AutoPlugin {
pullRequests.foreach { pr =>
println(s"[#${pr.number}](${pr.htmlUrl})")
val commits = github.getCommits(pr.number)
commits.foreach { commit =>
println(s"* [${commit.message}](${commit.url})")
commits.foreach { record =>
println(s"* [${record.commit.message}](${record.htmlUrl})")
}
}
}
Expand Down

0 comments on commit d990f55

Please sign in to comment.