Skip to content

Commit ad7aaa3

Browse files
committed
feature: add Tag scope for custom actions (#1457)
Signed-off-by: leo <[email protected]>
1 parent 743be54 commit ad7aaa3

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

src/Models/CustomAction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum CustomActionScope
88
Repository,
99
Commit,
1010
Branch,
11+
Tag,
1112
}
1213

1314
public enum CustomActionControlType

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">Template Name:</x:String>
161161
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">CUSTOM ACTION</x:String>
162162
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">Arguments:</x:String>
163-
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">${REPO} - Repository's path; ${BRANCH} - Selected branch; ${SHA} - Selected commit's SHA</x:String>
163+
<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 SHA; ${TAG} - Selected tag</x:String>
164164
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">Executable File:</x:String>
165165
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">Input Controls:</x:String>
166166
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">Edit</x:String>
@@ -170,6 +170,7 @@
170170
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" xml:space="preserve">Branch</x:String>
171171
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">Commit</x:String>
172172
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">Repository</x:String>
173+
<x:String x:Key="Text.Configure.CustomAction.Scope.Tag" xml:space="preserve">Tag</x:String>
173174
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">Wait for action exit</x:String>
174175
<x:String x:Key="Text.Configure.Email" xml:space="preserve">Email Address</x:String>
175176
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">Email address</x:String>
@@ -747,6 +748,7 @@
747748
<x:String x:Key="Text.Sure" xml:space="preserve">OK</x:String>
748749
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">Copy Tag Name</x:String>
749750
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">Copy Tag Message</x:String>
751+
<x:String x:Key="Text.TagCM.CustomAction" xml:space="preserve">Custom Action</x:String>
750752
<x:String x:Key="Text.TagCM.Delete" xml:space="preserve">Delete ${0}$...</x:String>
751753
<x:String x:Key="Text.TagCM.Merge" xml:space="preserve">Merge ${0}$ into ${1}$...</x:String>
752754
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">Push ${0}$...</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">模板名 :</x:String>
165165
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自定义操作</x:String>
166166
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">命令行参数 :</x:String>
167-
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">请使用${REPO}代替仓库路径,${BRANCH}代替选中的分支,${SHA}代替提交哈希</x:String>
167+
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:${REPO} 仓库路径、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签</x:String>
168168
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可执行文件路径 :</x:String>
169169
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">输入控件 :</x:String>
170170
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">编辑</x:String>
@@ -174,6 +174,7 @@
174174
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" xml:space="preserve">选中的分支</x:String>
175175
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">选中的提交</x:String>
176176
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">仓库</x:String>
177+
<x:String x:Key="Text.Configure.CustomAction.Scope.Tag" xml:space="preserve">选中的标签</x:String>
177178
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待操作执行完成</x:String>
178179
<x:String x:Key="Text.Configure.Email" xml:space="preserve">电子邮箱</x:String>
179180
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">邮箱地址</x:String>
@@ -751,6 +752,7 @@
751752
<x:String x:Key="Text.Sure" xml:space="preserve">确 定</x:String>
752753
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">复制标签名</x:String>
753754
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">复制标签信息</x:String>
755+
<x:String x:Key="Text.TagCM.CustomAction" xml:space="preserve">自定义操作</x:String>
754756
<x:String x:Key="Text.TagCM.Delete" xml:space="preserve">删除 ${0}$...</x:String>
755757
<x:String x:Key="Text.TagCM.Merge" xml:space="preserve">合并 ${0}$ 到 ${1}$...</x:String>
756758
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">範本名稱:</x:String>
165165
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自訂動作</x:String>
166166
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">指令參數:</x:String>
167-
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">使用 ${REPO} 表示存放庫路徑、${BRANCH} 表示所選的分支、${SHA} 表示所選的提交編號</x:String>
167+
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">內建參數: ${REPO} 存放庫路徑、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤</x:String>
168168
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可執行檔案路徑:</x:String>
169169
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">輸入控件:</x:String>
170170
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">編輯</x:String>
@@ -174,6 +174,7 @@
174174
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" xml:space="preserve">選取的分支</x:String>
175175
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">選取的提交</x:String>
176176
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">存放庫</x:String>
177+
<x:String x:Key="Text.Configure.CustomAction.Scope.Tag" xml:space="preserve">選取的標籤</x:String>
177178
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待自訂動作執行結束</x:String>
178179
<x:String x:Key="Text.Configure.Email" xml:space="preserve">電子郵件</x:String>
179180
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">電子郵件地址</x:String>
@@ -751,6 +752,7 @@
751752
<x:String x:Key="Text.Sure" xml:space="preserve">確 定</x:String>
752753
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">複製標籤名稱</x:String>
753754
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">複製標籤訊息</x:String>
755+
<x:String x:Key="Text.TagCM.CustomAction" xml:space="preserve">自訂動作</x:String>
754756
<x:String x:Key="Text.TagCM.Delete" xml:space="preserve">刪除 ${0}$...</x:String>
755757
<x:String x:Key="Text.TagCM.Merge" xml:space="preserve">合併 ${0}$ 到 ${1}$...</x:String>
756758
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.C
111111
PrepareControlParameters();
112112
}
113113

114+
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Tag tag)
115+
{
116+
_repo = repo;
117+
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${TAG}", tag.Name);
118+
CustomAction = action;
119+
PrepareControlParameters();
120+
}
121+
114122
public override Task<bool> Sure()
115123
{
116124
_repo.SetWatcherEnabled(false);

src/ViewModels/Repository.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ public void ExecCustomAction(Models.CustomAction action, object scope)
834834
popup = new ExecuteCustomAction(this, action, b);
835835
else if (scope is Models.Commit c)
836836
popup = new ExecuteCustomAction(this, action, c);
837+
else if (scope is Models.Tag t)
838+
popup = new ExecuteCustomAction(this, action, t);
837839
else
838840
popup = new ExecuteCustomAction(this, action);
839841

@@ -2388,6 +2390,41 @@ public ContextMenu CreateContextMenuForTag(Models.Tag tag)
23882390
ev.Handled = true;
23892391
};
23902392

2393+
var menu = new ContextMenu();
2394+
menu.Items.Add(createBranch);
2395+
menu.Items.Add(new MenuItem() { Header = "-" });
2396+
menu.Items.Add(pushTag);
2397+
menu.Items.Add(deleteTag);
2398+
menu.Items.Add(new MenuItem() { Header = "-" });
2399+
menu.Items.Add(archive);
2400+
menu.Items.Add(new MenuItem() { Header = "-" });
2401+
2402+
var actions = GetCustomActions(Models.CustomActionScope.Tag);
2403+
if (actions.Count > 0)
2404+
{
2405+
var custom = new MenuItem();
2406+
custom.Header = App.Text("TagCM.CustomAction");
2407+
custom.Icon = App.CreateMenuIcon("Icons.Action");
2408+
2409+
foreach (var action in actions)
2410+
{
2411+
var dup = action;
2412+
var item = new MenuItem();
2413+
item.Icon = App.CreateMenuIcon("Icons.Action");
2414+
item.Header = dup.Name;
2415+
item.Click += (_, e) =>
2416+
{
2417+
ExecCustomAction(dup, tag);
2418+
e.Handled = true;
2419+
};
2420+
2421+
custom.Items.Add(item);
2422+
}
2423+
2424+
menu.Items.Add(custom);
2425+
menu.Items.Add(new MenuItem() { Header = "-" });
2426+
}
2427+
23912428
var copy = new MenuItem();
23922429
copy.Header = App.Text("TagCM.Copy");
23932430
copy.Icon = App.CreateMenuIcon("Icons.Copy");
@@ -2407,14 +2444,6 @@ public ContextMenu CreateContextMenuForTag(Models.Tag tag)
24072444
ev.Handled = true;
24082445
};
24092446

2410-
var menu = new ContextMenu();
2411-
menu.Items.Add(createBranch);
2412-
menu.Items.Add(new MenuItem() { Header = "-" });
2413-
menu.Items.Add(pushTag);
2414-
menu.Items.Add(deleteTag);
2415-
menu.Items.Add(new MenuItem() { Header = "-" });
2416-
menu.Items.Add(archive);
2417-
menu.Items.Add(new MenuItem() { Header = "-" });
24182447
menu.Items.Add(copy);
24192448
menu.Items.Add(copyMessage);
24202449
return menu;

src/Views/Preferences.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@
644644
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Repository}"/>
645645
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Commit}"/>
646646
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Branch}"/>
647+
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Tag}"/>
647648
</ComboBox>
648649

649650
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Executable}"/>

src/Views/RepositoryConfigure.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@
472472
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Repository}"/>
473473
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Commit}"/>
474474
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Branch}"/>
475+
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Tag}"/>
475476
</ComboBox>
476477

477478
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Executable}"/>

0 commit comments

Comments
 (0)