Added more stuff to git commit macro
This commit is contained in:
@@ -8,11 +8,27 @@ class GitCommitMacro {
|
||||
/**
|
||||
* Returns the current commit number
|
||||
*/
|
||||
public static var commitNumber(get, null):Int;
|
||||
public static var commitNumber(get, never):Int;
|
||||
/**
|
||||
* Returns the current commit hash
|
||||
*/
|
||||
public static var commitHash(get, null):String;
|
||||
public static var commitHash(get, never):String;
|
||||
/**
|
||||
* Returns the current commit hash in long format
|
||||
*/
|
||||
public static var commitHashLong(get, never):String;
|
||||
/**
|
||||
* Returns the current commit message
|
||||
*/
|
||||
public static var commitMessage(get, never):String;
|
||||
/**
|
||||
* Returns the current commit author
|
||||
*/
|
||||
public static var commitAuthor(get, never):String;
|
||||
/**
|
||||
* Returns the current commit date + time
|
||||
**/
|
||||
public static var commitDate(get, never):Date;
|
||||
|
||||
// GETTERS
|
||||
#if REGION
|
||||
@@ -21,6 +37,15 @@ class GitCommitMacro {
|
||||
|
||||
private static inline function get_commitHash()
|
||||
return __getCommitHash();
|
||||
private static inline function get_commitHashLong()
|
||||
return __getCommitHashLong();
|
||||
|
||||
private static inline function get_commitMessage()
|
||||
return __getCommitMessage();
|
||||
private static inline function get_commitAuthor()
|
||||
return __getCommitAuthor();
|
||||
private static inline function get_commitDate()
|
||||
return __getCommitDate();
|
||||
#end
|
||||
|
||||
// INTERNAL MACROS
|
||||
@@ -52,5 +77,77 @@ class GitCommitMacro {
|
||||
return macro $v{0}
|
||||
#end
|
||||
}
|
||||
|
||||
private static macro function __getCommitHashLong() {
|
||||
#if display
|
||||
return macro $v{"-"};
|
||||
#else
|
||||
try {
|
||||
var proc = new Process('git', ['rev-parse', 'HEAD'], false);
|
||||
proc.exitCode(true);
|
||||
|
||||
return macro $v{proc.stdout.readLine()};
|
||||
} catch(e) {}
|
||||
return macro $v{"-"}
|
||||
#end
|
||||
}
|
||||
|
||||
private static macro function __getCommitMessage() {
|
||||
#if display
|
||||
return macro $v{"-"};
|
||||
#else
|
||||
try {
|
||||
var proc = new Process('git', ['log', '-1', '--pretty=%B'], false);
|
||||
proc.exitCode(true);
|
||||
var all = proc.stdout.readAll().toString();
|
||||
while(StringTools.endsWith(all, "\r\n")) all = all.substr(0, all.length - 2);
|
||||
while(StringTools.endsWith(all, "\n")) all = all.substr(0, all.length - 1);
|
||||
while(StringTools.endsWith(all, "\r")) all = all.substr(0, all.length - 1);
|
||||
|
||||
return macro $v{all};
|
||||
} catch(e) {}
|
||||
return macro $v{"-"}
|
||||
#end
|
||||
}
|
||||
|
||||
private static macro function __getCommitAuthor() {
|
||||
#if display
|
||||
return macro $v{"-"};
|
||||
#else
|
||||
try {
|
||||
var proc = new Process('git', ['log', '-1', '--pretty=%an'], false);
|
||||
proc.exitCode(true);
|
||||
|
||||
return macro $v{StringTools.trim(proc.stdout.readLine())};
|
||||
} catch(e) {}
|
||||
return macro $v{"-"}
|
||||
#end
|
||||
}
|
||||
|
||||
private static macro function __getCommitDate() {
|
||||
#if display
|
||||
return macro $v{Date.now()};
|
||||
#else
|
||||
try {
|
||||
// get the time in UTC format
|
||||
var oldTz = Sys.getEnv("TZ");
|
||||
Sys.putEnv("TZ", "UTC0");
|
||||
var proc = new Process('git', ['log', "--date='format-local:%Y-%m-%dT%H:%M:%SZ'", '-1', '--pretty=%cd'], false);
|
||||
proc.exitCode(true);
|
||||
Sys.putEnv("TZ", oldTz);
|
||||
|
||||
var rawDate = StringTools.trim(proc.stdout.readLine());
|
||||
|
||||
try {
|
||||
Date.fromString(rawDate);
|
||||
} catch(e) {
|
||||
throw 'Invalid date format: $rawDate';
|
||||
}
|
||||
|
||||
return macro Date.fromString($v{rawDate});
|
||||
} catch(e) {}
|
||||
return macro Date.fromString("1970-01-01T00:00:00"); // failed to parse date
|
||||
#end
|
||||
}
|
||||
#end
|
||||
}
|
||||
Reference in New Issue
Block a user