|
1 | 1 | package controllers
|
2 | 2 |
|
3 |
| -import java.io.File |
| 3 | +import java.io.{File, FileInputStream} |
4 | 4 |
|
5 | 5 | import com.madgag.github.Implicits._
|
6 | 6 | import com.madgag.github.{PullRequestId, RepoId}
|
@@ -112,25 +112,24 @@ object Application extends Controller {
|
112 | 112 | }
|
113 | 113 | }
|
114 | 114 |
|
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) |
120 | 116 |
|
121 | 117 | 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() |
124 | 119 |
|
125 |
| - Logger.info(s"Heroku dyno metadata $existingFile") |
| 120 | + Logger.info(s"Heroku dyno metadata: $existingFileOpt") |
126 | 121 |
|
127 | 122 | 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 | + } |
132 | 129 | }
|
133 |
| -} |
134 |
| - |
135 |
| - |
136 | 130 |
|
| 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