Skip to content

Commit 5916284

Browse files
committed
Tweak Heroku commit id parsing
Slightly less logging when there isn't one
1 parent a624a50 commit 5916284

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

app/controllers/Application.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package controllers
22

3-
import java.io.File
3+
import java.io.{File, FileInputStream}
44

55
import com.madgag.github.Implicits._
66
import com.madgag.github.{PullRequestId, RepoId}
@@ -112,25 +112,24 @@ object Application extends Controller {
112112
}
113113
}
114114

115-
lazy val gitCommitId = {
116-
val g = gitCommitIdFromHerokuFile
117-
Logger.info(s"Heroku dyno commit id $g")
118-
g.getOrElse(app.BuildInfo.gitCommitId)
119-
}
115+
lazy val gitCommitId = gitCommitIdFromHerokuFile.getOrElse(app.BuildInfo.gitCommitId)
120116

121117
def gitCommitIdFromHerokuFile: Option[String] = {
122-
val file = new File("/etc/heroku/dyno")
123-
val existingFile = if (file.exists && file.isFile) Some(file) else None
118+
val existingFileOpt: Option[File] = herokuMetadataFile()
124119

125-
Logger.info(s"Heroku dyno metadata $existingFile")
120+
Logger.info(s"Heroku dyno metadata: $existingFileOpt")
126121

127122
for {
128-
f <- existingFile
129-
text <- (Json.parse(scala.io.Source.fromFile(f).mkString) \ "release" \ "commit").asOpt[String]
130-
objectId <- Try(ObjectId.fromString(text)).toOption
131-
} yield objectId.name
123+
existingFile <- existingFileOpt
124+
commitId <- (Json.parse(new FileInputStream(existingFile)) \ "release" \ "commit").asOpt[String]
125+
} yield {
126+
Logger.info(s"Heroku dyno commit id: $commitId")
127+
commitId
128+
}
132129
}
133-
}
134-
135-
136130

131+
def herokuMetadataFile(): Option[File] = {
132+
val file = new File("/etc/heroku/dyno")
133+
if (file.exists && file.isFile) Some(file) else None
134+
}
135+
}

0 commit comments

Comments
 (0)