git branch list up
This commit is contained in:
parent
369b4fb743
commit
c59903750c
5 changed files with 119 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ pipeline:
|
|||
id: main
|
||||
workflow:
|
||||
- exe: read
|
||||
- exe: branch
|
||||
- exe: param-modify
|
||||
- exe: write
|
||||
|
||||
|
|
@ -35,6 +36,15 @@ commands:
|
|||
to: <test>
|
||||
setValue: <@property.content>
|
||||
|
||||
### List up branches
|
||||
- command: GitBranch
|
||||
id: branch
|
||||
param:
|
||||
path: /Users/toki/works/lgup-mcs-aos
|
||||
startDay: 20
|
||||
setBranches: <@property.value>
|
||||
|
||||
### Modify param
|
||||
- command: JenkinsParameterModify
|
||||
id: param-modify
|
||||
param:
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ enum CommandType {
|
|||
GitReset,
|
||||
GitStashPush,
|
||||
GitStashApply,
|
||||
GitBranch,
|
||||
GitHub,
|
||||
GitHubPullRequestCreate,
|
||||
GitHubPullRequestList,
|
||||
|
|
@ -177,6 +178,7 @@ abstract class Command {
|
|||
CommandType.GitReset: () => GitReset(),
|
||||
CommandType.GitStashPush: () => GitStashPush(),
|
||||
CommandType.GitStashApply: () => GitStashApply(),
|
||||
CommandType.GitBranch: () => GitBranch(),
|
||||
CommandType.GitHub: () => GitHub(),
|
||||
CommandType.GitHubPullRequestCreate: () => GitHubPullRequestCreate(),
|
||||
CommandType.GitHubPullRequestList: () => GitHubPullRequestList(),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/oto/commands/command.dart';
|
||||
|
|
@ -220,3 +223,40 @@ class GitStashApply extends Command {
|
|||
return await completeProcess(process, command, passExitCodes: [1]);
|
||||
}
|
||||
}
|
||||
|
||||
//무시가가능한 에러 무시
|
||||
class GitBranch extends Command {
|
||||
@override
|
||||
Future execute(DataCommand command) async {
|
||||
var data = DataGitBranch.fromJson(getParam(command));
|
||||
|
||||
var shell = StringBuffer('cd ${data.path}');
|
||||
shell.write(
|
||||
' $and git for-each-ref --format=\'{"ref": "%(refname:short)", "sha": "%(objectname)", "date": "%(committerdate:iso8601)"}\' refs/remotes | jq -s . > branches.json');
|
||||
|
||||
var process =
|
||||
await ProcessExecutor.start(shell, logHandler: Application.logWithType);
|
||||
|
||||
var file = File('${data.path}/branches.json');
|
||||
var content = file.readAsStringSync();
|
||||
final List<dynamic> decoded = jsonDecode(content);
|
||||
final branches = decoded.map((e) => BranchInfo.fromJson(e)).toList();
|
||||
var list = <String>[];
|
||||
var fixedBranch = ['main', 'master', 'develop'];
|
||||
var startDate =
|
||||
DateTime.now().subtract(Duration(days: data.startDay!)).millisecond;
|
||||
for (var branch in branches) {
|
||||
var branchName = branch.ref!.replaceFirst('origin/', '');
|
||||
if (DateTime.parse(branch.date!).millisecond > startDate) {
|
||||
list.add(branchName);
|
||||
} else {
|
||||
if (fixedBranch.contains(branchName)) {
|
||||
list.add(branchName);
|
||||
}
|
||||
}
|
||||
}
|
||||
setProperty(data.setBranches!, list, showPrint: true);
|
||||
|
||||
return await completeProcess(process, command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -721,6 +721,35 @@ class DataGitCommit extends DataParam {
|
|||
Map<String, dynamic> toJson() => _$DataGitCommitToJson(this);
|
||||
}
|
||||
|
||||
//GitBranch
|
||||
@JsonSerializable()
|
||||
class DataGitBranch extends DataParam {
|
||||
DataGitBranch();
|
||||
|
||||
late String? path;
|
||||
late int? startDay;
|
||||
late String? setBranches;
|
||||
|
||||
factory DataGitBranch.fromJson(Map<String, dynamic> json) =>
|
||||
_$DataGitBranchFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$DataGitBranchToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class BranchInfo {
|
||||
BranchInfo();
|
||||
|
||||
late String? ref;
|
||||
late String? sha;
|
||||
late String? date;
|
||||
|
||||
factory BranchInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$BranchInfoFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$BranchInfoToJson(this);
|
||||
}
|
||||
|
||||
//GitPush
|
||||
@JsonSerializable()
|
||||
class DataGitPush extends DataParam {
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ const _$CommandTypeEnumMap = {
|
|||
CommandType.GitReset: 'GitReset',
|
||||
CommandType.GitStashPush: 'GitStashPush',
|
||||
CommandType.GitStashApply: 'GitStashApply',
|
||||
CommandType.GitBranch: 'GitBranch',
|
||||
CommandType.GitHub: 'GitHub',
|
||||
CommandType.GitHubPullRequestCreate: 'GitHubPullRequestCreate',
|
||||
CommandType.GitHubPullRequestList: 'GitHubPullRequestList',
|
||||
|
|
@ -1278,6 +1279,43 @@ Map<String, dynamic> _$DataGitCommitToJson(DataGitCommit instance) =>
|
|||
'message': instance.message,
|
||||
};
|
||||
|
||||
DataGitBranch _$DataGitBranchFromJson(Map<String, dynamic> json) =>
|
||||
DataGitBranch()
|
||||
..workspace = json['workspace'] as String?
|
||||
..passExitCodes = (json['passExitCodes'] as List<dynamic>?)
|
||||
?.map((e) => (e as num).toInt())
|
||||
.toList()
|
||||
..setResult = json['setResult'] as String?
|
||||
..setExitCode = json['setExitCode'] as String?
|
||||
..showPrint = json['showPrint'] as bool?
|
||||
..path = json['path'] as String?
|
||||
..startDay = (json['startDay'] as num?)?.toInt()
|
||||
..setBranches = json['setBranches'] as String?;
|
||||
|
||||
Map<String, dynamic> _$DataGitBranchToJson(DataGitBranch instance) =>
|
||||
<String, dynamic>{
|
||||
'workspace': instance.workspace,
|
||||
'passExitCodes': instance.passExitCodes,
|
||||
'setResult': instance.setResult,
|
||||
'setExitCode': instance.setExitCode,
|
||||
'showPrint': instance.showPrint,
|
||||
'path': instance.path,
|
||||
'startDay': instance.startDay,
|
||||
'setBranches': instance.setBranches,
|
||||
};
|
||||
|
||||
BranchInfo _$BranchInfoFromJson(Map<String, dynamic> json) => BranchInfo()
|
||||
..ref = json['ref'] as String?
|
||||
..sha = json['sha'] as String?
|
||||
..date = json['date'] as String?;
|
||||
|
||||
Map<String, dynamic> _$BranchInfoToJson(BranchInfo instance) =>
|
||||
<String, dynamic>{
|
||||
'ref': instance.ref,
|
||||
'sha': instance.sha,
|
||||
'date': instance.date,
|
||||
};
|
||||
|
||||
DataGitPush _$DataGitPushFromJson(Map<String, dynamic> json) => DataGitPush()
|
||||
..workspace = json['workspace'] as String?
|
||||
..passExitCodes = (json['passExitCodes'] as List<dynamic>?)
|
||||
|
|
|
|||
Loading…
Reference in a new issue