-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactored/extracted bash util * -> we should print config file path, which is started as log.info -> we see in log file on server which commit is used * Feedback incorporated * Feedback incorporated and warnings fixed * Feedback incorporated
- Loading branch information
1 parent
d8a4f43
commit ad8d892
Showing
3 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package beam.utils | ||
|
||
import java.io.{BufferedReader, InputStreamReader} | ||
|
||
object BashUtils { | ||
|
||
/** | ||
* Method returns the git commit hash or HEAD if git not present | ||
* git rev-parse --abbrev-ref HEAD | ||
* | ||
* @return returns the git commit hash or HEAD if git not present | ||
*/ | ||
def getCommitHash: String = { | ||
val resp = readCommandResponse("git rev-parse HEAD") | ||
if (resp != null) return resp | ||
"HEAD" //for the env where git is not present | ||
|
||
} | ||
|
||
/** | ||
* Method returns the git branch or master if git not present | ||
* | ||
* @return returns the current git branch | ||
*/ | ||
def getBranch: String = { | ||
val resp = readCommandResponse("git rev-parse --abbrev-ref HEAD") | ||
if (resp != null) return resp | ||
"master" | ||
} | ||
|
||
private def readCommandResponse(command: String) = { | ||
val runtime = Runtime.getRuntime | ||
try { | ||
val process = runtime.exec(command) | ||
try { | ||
val reader = new BufferedReader(new InputStreamReader(process.getInputStream)) | ||
try | ||
reader.readLine | ||
finally if (reader != null) reader.close() | ||
} | ||
} catch { | ||
case _: Exception => | ||
null //for the env where command is not recognized | ||
|
||
} | ||
} | ||
} |