A small library (like https://github.com/sbt/sbt-buildinfo) to obtain git informations (hash, commit time, author,...) but at compile time.
This help to illustrate how macros work
build.sbt :
works for scala 2.12 and 2.13
resolvers += Resolver.bintrayRepo("dgouyette", "maven")
libraryDependencies ++= Seq(
"org.cestpasdur" %% "git-info" % "0.2.2",
)
class VersionController extends Controller {
def index = Action {
Ok(
Json.obj(
"lastCommit" -> Json.obj(
"branch" -> GitInfo.currentBranch(),
"message" -> GitInfo.lastRevCommitMessage(),
"author" -> GitInfo.lastRevCommitAuthor(),
"hash" -> GitInfo.lastRevCommitName(),
"date" -> GitInfo.lastRevCommitTime()
))
)
}
}
That will display :
{
"lastCommit": {
"branch": "master",
"message": "add git-info to display last commit info",
"author": "Damien GOUYETTE <[email protected]> 1469442718 +0200",
"hash": "6024dcc98bd563b0ab78c7a663c52ebadbbaf456",
"date": "Mon Jul 25 12:32:15 CEST 2016"
}
}