update git

This commit is contained in:
leedongmyung[desktop] 2023-11-25 15:22:05 +09:00
parent b7b0a32d64
commit edbd6c4eac
5 changed files with 85 additions and 10 deletions

View file

@ -6,6 +6,8 @@ pipeline:
id: main
workflow:
- exe: git
- exe: git-rev
- exe: git-count
#동기식 실행, 해당 수행이 끝나야만 다음 스텝실행, command일경우 해당 id 기입
- async: appData
@ -30,11 +32,17 @@ commands:
- restore .
- clean -f
# ### 깃 리비전 정보 저장
# - command: GitRev
# id: git-rev
# param:
# result-value: <!property.git_rev>
### 깃 리비전 정보 저장
- command: GitRev
id: git-rev
param:
result-value: <!property.git-rev>
### 깃 커밋카운트 저장
- command: GitCount
id: git-count
param:
result-value: <!property.git-count>
# ### Json value read
# - command: JsonValue

View file

@ -44,7 +44,9 @@ enum CommandType {
SlackBuild,
Zip,
Shell,
Git
Git,
GitRev,
GitCount
}
abstract class Command {
@ -68,7 +70,9 @@ abstract class Command {
CommandType.SlackBuild: SlackBuild(),
CommandType.Zip: Zip(),
CommandType.Shell: Shell(),
CommandType.Git: Git()
CommandType.Git: Git(),
CommandType.GitRev: GitRev(),
CommandType.GitCount: GitCount(),
};
factory Command.byType(CommandType type) {
@ -77,10 +81,11 @@ abstract class Command {
Command();
static RegExp regEx = RegExp(r'(<!)([_a-zA-Z0-9.-]+)(>)');
static final Map<String, dynamic> _cache = <String, dynamic>{};
static void setReturnValue(String tag, dynamic value) {
var regEx = RegExp(r'(<!)([a-zA-Z0-9.]+)(>)');
var match = regEx.firstMatch(tag);
tag = match!.group(2)!;
if (tag.startsWith('property')) {
@ -113,7 +118,6 @@ abstract class Command {
}
static String replaceTagValue(String raw) {
var regEx = RegExp(r'(<!)([a-zA-Z0-9.]+)(>)');
var list = regEx.allMatches(raw);
for (var match in list) {
var param = match.group(2);
@ -158,6 +162,10 @@ abstract class Command {
return Command.replaceTagValue(raw);
}
void setReturn(String tag, dynamic value) {
Command.setReturnValue(tag, value);
}
Future execute(DataCommand command) async {
return simpleFuture;
}

View file

@ -20,3 +20,37 @@ class Git extends Command {
errorMessage: process.stderr.toString());
}
}
class GitCount extends Command {
@override
Future execute(DataCommand command) async {
var data = DataGitCount.fromJson(command.param);
var workspace = getWorkspace(data.workspace);
var shell = StringBuffer(getCDPath(workspace));
shell.write(' && git rev-list --all HEAD --all --count');
var process = await ProcessExecutor.start(shell);
var exitCode = await process.process.exitCode;
var number = int.parse(process.stdoutArr.last);
setReturn(data.result_value, number);
return complete(exitCode, command, errorMessage: process.stderr.toString());
}
}
class GitRev extends Command {
@override
Future execute(DataCommand command) async {
var data = DataGitRev.fromJson(command.param);
var workspace = getWorkspace(data.workspace);
var shell = StringBuffer(getCDPath(workspace));
shell.write(' && git rev-parse HEAD');
var process = await ProcessExecutor.start(shell);
var exitCode = await process.process.exitCode;
var hash = process.stdoutArr.last;
setReturn(data.result_value, hash);
return complete(exitCode, command, errorMessage: process.stderr.toString());
}
}

View file

@ -324,7 +324,20 @@ class DataGit extends DataParam {
Map<String, dynamic> toJson() => _$DataGitToJson(this);
}
//Git
//GitCount
@JsonSerializable()
class DataGitCount extends DataParam {
DataGitCount();
@JsonKey(name: 'result-value')
late String result_value;
factory DataGitCount.fromJson(Map<String, dynamic> json) =>
_$DataGitCountFromJson(json);
Map<String, dynamic> toJson() => _$DataGitCountToJson(this);
}
//GitRev
@JsonSerializable()
class DataGitRev extends DataParam {
DataGitRev();

View file

@ -54,6 +54,8 @@ const _$CommandTypeEnumMap = {
CommandType.Zip: 'Zip',
CommandType.Shell: 'Shell',
CommandType.Git: 'Git',
CommandType.GitRev: 'GitRev',
CommandType.GitCount: 'GitCount',
};
DataParam _$DataParamFromJson(Map<String, dynamic> json) =>
@ -366,6 +368,16 @@ Map<String, dynamic> _$DataGitToJson(DataGit instance) => <String, dynamic>{
'commands': instance.commands,
};
DataGitCount _$DataGitCountFromJson(Map<String, dynamic> json) => DataGitCount()
..workspace = json['workspace'] as String?
..result_value = json['result-value'] as String;
Map<String, dynamic> _$DataGitCountToJson(DataGitCount instance) =>
<String, dynamic>{
'workspace': instance.workspace,
'result-value': instance.result_value,
};
DataGitRev _$DataGitRevFromJson(Map<String, dynamic> json) => DataGitRev()
..workspace = json['workspace'] as String?
..result_value = json['result-value'] as String;