Skip to content

Commit 0729c30

Browse files
committed
enhance: supports to use ${BRANCH}/${COMMIT}/${TAG} in Default field of TextBox/PathSelector in custom actions (#1466)
Signed-off-by: leo <[email protected]>
1 parent fbcb3a9 commit 0729c30

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,7 @@ public override Task<bool> Sure()
127127
ProgressDescription = "Run custom action ...";
128128

129129
var cmdline = CustomAction.Arguments.Replace("${REPO}", GetWorkdir());
130-
if (Target is Models.Branch b)
131-
cmdline = cmdline.Replace("${BRANCH}", b.FriendlyName);
132-
else if (Target is Models.Commit c)
133-
cmdline = cmdline.Replace("${SHA}", c.SHA);
134-
else if (Target is Models.Tag t)
135-
cmdline = cmdline.Replace("${TAG}", t.Name);
130+
cmdline = PrepareStringByTarget(cmdline);
136131

137132
for (var i = ControlParameters.Count - 1; i >= 0; i--)
138133
{
@@ -165,18 +160,30 @@ private void PrepareControlParameters()
165160
switch (ctl.Type)
166161
{
167162
case Models.CustomActionControlType.TextBox:
168-
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, ctl.StringValue));
163+
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
169164
break;
170165
case Models.CustomActionControlType.CheckBox:
171166
ControlParameters.Add(new CustomActionControlCheckBox(ctl.Label, ctl.Description, ctl.StringValue, ctl.BoolValue));
172167
break;
173168
case Models.CustomActionControlType.PathSelector:
174-
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, ctl.StringValue));
169+
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));
175170
break;
176171
}
177172
}
178173
}
179174

175+
private string PrepareStringByTarget(string org)
176+
{
177+
if (Target is Models.Branch b)
178+
return org.Replace("${BRANCH}", b.FriendlyName);
179+
else if (Target is Models.Commit c)
180+
return org.Replace("${SHA}", c.SHA);
181+
else if (Target is Models.Tag t)
182+
return org.Replace("${TAG}", t.Name);
183+
184+
return org;
185+
}
186+
180187
private string GetWorkdir()
181188
{
182189
return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath;

0 commit comments

Comments
 (0)