Skip to content

feat: add Built-in parameters: DIRNAME, #1628, #1633 #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">Template Name:</x:String>
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">CUSTOM ACTION</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">Arguments:</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters: ${REPO} - repository's path; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters: ${REPO} - repository's path; ${DIRNAME} - repository's directory name; ${BRANCH} - selected branch; {CURRENT_BRANCH} - current branch; ${SHA} - selected commit's hash; ${TAG} - selected tag</x:String>
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">Executable File:</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">Input Controls:</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">Edit</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">模板名 :</x:String>
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自定义操作</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">命令行参数 :</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:${REPO} 仓库路径、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:${REPO} 仓库路径、${DIRNAME} 仓库文件夹名、${BRANCH} 选中的分支、${CURRENT_BRANCH} 当前的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签</x:String>
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可执行文件路径 :</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">输入控件 :</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">编辑</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">範本名稱:</x:String>
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自訂動作</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">指令參數:</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">內建參數: ${REPO} 存放庫路徑、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤</x:String>
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">內建參數: ${REPO} 存放庫路徑、${DIRNAME} 存放庫資料夾名、${BRANCH} 所選的分支、${CURRENT_BRANCH} 當前分支、${SHA} 所選的提交編號、${TAG} 所選的標籤</x:String>
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可執行檔案路徑:</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">輸入控件:</x:String>
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">編輯</x:String>
Expand Down
14 changes: 13 additions & 1 deletion src/ViewModels/ExecuteCustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ private void PrepareControlParameters()
private string PrepareStringByTarget(string org)
{
org = org.Replace("${REPO}", GetWorkdir());
org = org.Replace("${DIRNAME}", GetWorkdirname());
org = org.Replace("${CURRENT_BRANCH}", GetCurrentBranch());

return Target switch
{
Models.Branch b => org.Replace("${BRANCH}", b.FriendlyName),
Models.Commit c => org.Replace("${SHA}", c.SHA),
Models.Tag t => org.Replace("${TAG}", t.Name),
_ => org
_ => org,
};
}

Expand All @@ -218,6 +220,16 @@ private string GetWorkdir()
return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath;
}

private string GetWorkdirname()
{
return _repo.FullPath.Replace("\\", "/").Split('/')[^1];
}

private string GetCurrentBranch()
{
return _repo.CurrentBranch?.FriendlyName ?? string.Empty;
}

private void Run(string args)
{
var start = new ProcessStartInfo();
Expand Down
Loading