From 1eb1329d86b8d726767575a55b085503bb7bfac0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 2 Aug 2025 18:06:13 +0800 Subject: [PATCH 1/2] feat: add Built-in parameters: `DIRNAME`, Fixes #1628 --- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 2 +- src/Resources/Locales/zh_TW.axaml | 2 +- src/ViewModels/ExecuteCustomAction.cs | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 655dc0cd8..3f0fc538c 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -174,7 +174,7 @@ Template Name: CUSTOM ACTION Arguments: - Built-in parameters: ${REPO} - repository's path; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag + Built-in parameters: ${REPO} - repository's path; ${DIRNAME} - repository's directory name; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag Executable File: Input Controls: Edit diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index f18372fd5..9636c1791 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -178,7 +178,7 @@ 模板名 : 自定义操作 命令行参数 : - 内置变量:${REPO} 仓库路径、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签 + 内置变量:${REPO} 仓库路径、${DIRNAME} 仓库文件夹名、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签 可执行文件路径 : 输入控件 : 编辑 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index daf0caec4..f7178660b 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -178,7 +178,7 @@ 範本名稱: 自訂動作 指令參數: - 內建參數: ${REPO} 存放庫路徑、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤 + 內建參數: ${REPO} 存放庫路徑、${DIRNAME} 存放庫資料夾名、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤 可執行檔案路徑: 輸入控件: 編輯 diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index fb0f2f819..241d3238a 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -203,13 +203,14 @@ private void PrepareControlParameters() private string PrepareStringByTarget(string org) { org = org.Replace("${REPO}", GetWorkdir()); + org = org.Replace("${DIRNAME}", GetWorkdirname()); 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, }; } @@ -218,6 +219,11 @@ private string GetWorkdir() return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath; } + private string GetWorkdirname() + { + return _repo.FullPath.Replace("\\", "/").Split('/')[^1]; + } + private void Run(string args) { var start = new ProcessStartInfo(); From 018f0507fbeccd6b2c1e7690571b83f1f6ec0a53 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 2 Aug 2025 18:18:03 +0800 Subject: [PATCH 2/2] feat: add Built-in parameters: `CURRENT_BRANCH`, Fixes #1633 --- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 2 +- src/Resources/Locales/zh_TW.axaml | 2 +- src/ViewModels/ExecuteCustomAction.cs | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 3f0fc538c..f4d9f73fb 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -174,7 +174,7 @@ Template Name: CUSTOM ACTION Arguments: - Built-in parameters: ${REPO} - repository's path; ${DIRNAME} - repository's directory name; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag + 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 Executable File: Input Controls: Edit diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 9636c1791..763c8bf3a 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -178,7 +178,7 @@ 模板名 : 自定义操作 命令行参数 : - 内置变量:${REPO} 仓库路径、${DIRNAME} 仓库文件夹名、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签 + 内置变量:${REPO} 仓库路径、${DIRNAME} 仓库文件夹名、${BRANCH} 选中的分支、${CURRENT_BRANCH} 当前的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签 可执行文件路径 : 输入控件 : 编辑 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index f7178660b..909426a6f 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -178,7 +178,7 @@ 範本名稱: 自訂動作 指令參數: - 內建參數: ${REPO} 存放庫路徑、${DIRNAME} 存放庫資料夾名、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤 + 內建參數: ${REPO} 存放庫路徑、${DIRNAME} 存放庫資料夾名、${BRANCH} 所選的分支、${CURRENT_BRANCH} 當前分支、${SHA} 所選的提交編號、${TAG} 所選的標籤 可執行檔案路徑: 輸入控件: 編輯 diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index 241d3238a..3cb293b42 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -204,6 +204,7 @@ private string PrepareStringByTarget(string org) { org = org.Replace("${REPO}", GetWorkdir()); org = org.Replace("${DIRNAME}", GetWorkdirname()); + org = org.Replace("${CURRENT_BRANCH}", GetCurrentBranch()); return Target switch { @@ -224,6 +225,11 @@ 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();