From edbd6c4eacd6836efa693dee487917abb8c574a8 Mon Sep 17 00:00:00 2001 From: "leedongmyung[desktop]" Date: Sat, 25 Nov 2023 15:22:05 +0900 Subject: [PATCH] update git --- assets/pipeline-test.yaml | 18 ++++++++++++----- lib/oto/commands/command.dart | 16 +++++++++++---- lib/oto/commands/git/git.dart | 34 ++++++++++++++++++++++++++++++++ lib/oto/data/command_data.dart | 15 +++++++++++++- lib/oto/data/command_data.g.dart | 12 +++++++++++ 5 files changed, 85 insertions(+), 10 deletions(-) diff --git a/assets/pipeline-test.yaml b/assets/pipeline-test.yaml index 8787ab8..e2129f9 100644 --- a/assets/pipeline-test.yaml +++ b/assets/pipeline-test.yaml @@ -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: +### 깃 리비전 정보 저장 +- command: GitRev + id: git-rev + param: + result-value: + +### 깃 커밋카운트 저장 +- command: GitCount + id: git-count + param: + result-value: # ### Json value read # - command: JsonValue diff --git a/lib/oto/commands/command.dart b/lib/oto/commands/command.dart index 1eba0fc..2d5261e 100644 --- a/lib/oto/commands/command.dart +++ b/lib/oto/commands/command.dart @@ -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'()'); + static final Map _cache = {}; static void setReturnValue(String tag, dynamic value) { - var regEx = RegExp(r'()'); 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'()'); 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; } diff --git a/lib/oto/commands/git/git.dart b/lib/oto/commands/git/git.dart index f423e47..4a2a736 100644 --- a/lib/oto/commands/git/git.dart +++ b/lib/oto/commands/git/git.dart @@ -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()); + } +} diff --git a/lib/oto/data/command_data.dart b/lib/oto/data/command_data.dart index b817114..266f716 100644 --- a/lib/oto/data/command_data.dart +++ b/lib/oto/data/command_data.dart @@ -324,7 +324,20 @@ class DataGit extends DataParam { Map toJson() => _$DataGitToJson(this); } -//Git +//GitCount +@JsonSerializable() +class DataGitCount extends DataParam { + DataGitCount(); + + @JsonKey(name: 'result-value') + late String result_value; + + factory DataGitCount.fromJson(Map json) => + _$DataGitCountFromJson(json); + Map toJson() => _$DataGitCountToJson(this); +} + +//GitRev @JsonSerializable() class DataGitRev extends DataParam { DataGitRev(); diff --git a/lib/oto/data/command_data.g.dart b/lib/oto/data/command_data.g.dart index 678e280..9bdfede 100644 --- a/lib/oto/data/command_data.g.dart +++ b/lib/oto/data/command_data.g.dart @@ -54,6 +54,8 @@ const _$CommandTypeEnumMap = { CommandType.Zip: 'Zip', CommandType.Shell: 'Shell', CommandType.Git: 'Git', + CommandType.GitRev: 'GitRev', + CommandType.GitCount: 'GitCount', }; DataParam _$DataParamFromJson(Map json) => @@ -366,6 +368,16 @@ Map _$DataGitToJson(DataGit instance) => { 'commands': instance.commands, }; +DataGitCount _$DataGitCountFromJson(Map json) => DataGitCount() + ..workspace = json['workspace'] as String? + ..result_value = json['result-value'] as String; + +Map _$DataGitCountToJson(DataGitCount instance) => + { + 'workspace': instance.workspace, + 'result-value': instance.result_value, + }; + DataGitRev _$DataGitRevFromJson(Map json) => DataGitRev() ..workspace = json['workspace'] as String? ..result_value = json['result-value'] as String;