Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Forked from xuwei-k/Build.scala
Last active October 5, 2024 07:43
Show Gist options
  • Save eed3si9n/ea4ceef0c5e5c07d6e62c87bea029f88 to your computer and use it in GitHub Desktop.
Save eed3si9n/ea4ceef0c5e5c07d6e62c87bea029f88 to your computer and use it in GitHub Desktop.
sbt plugin star ranking (using Gigahorse)
name := "sbt-plugin-ranking"
scalaVersion := "2.12.20"
libraryDependencies ++= List(
"com.eed3si9n" %% "gigahorse-github" % "gigahorse0.3.1_0.2.0",
"com.eed3si9n" %% "gigahorse-okhttp" % "0.3.1"
)
package sbt_plugin_ranking
import gigahorse._, support.okhttp.Gigahorse
import gigahorse.github.Github
import scala.concurrent._, duration._
import ExecutionContext.Implicits._
object Main extends App {
val repo = """https:\/\/github.com\/([a-zA-Z0-9_\-]+)\/([a-zA-Z0-9_\-]+)""".r
val url = "https://www.scala-sbt.org/1.x/docs/Community-Plugins.html"
Gigahorse.withHttp { http =>
val r = Gigahorse.url(url).get
val f = http.run(r, Gigahorse.asString)
val html = Await.result(f, 120.seconds)
val repoList = repo.findAllIn(html).map { case repo(user,name) => user -> name }.toList.distinct
val client = Github.localConfigClient
val promises = repoList map { case (u,r) =>
http.run(client(Github.repo(u, r)), Github.asRepo)
}
val info0 = for {
p <- promises
} yield Await.ready(p, 1.minutes).value.get
val info = info0.collect {
case t if t.isSuccess => t.get
}
info.sortBy(_.watchers_count).reverse foreach{ repo =>
println("- " + repo.html_url.get + " " + repo.watchers_count.get)}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment