Skip to content

Commit

Permalink
Merge pull request #29 from nkdAgility/topic/fix-workitemname
Browse files Browse the repository at this point in the history
Update with new Work item Name
  • Loading branch information
MrHinsh authored Jul 3, 2024
2 parents 82ae319 + 896f6b8 commit a958e99
Show file tree
Hide file tree
Showing 6 changed files with 1,320 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ await AnsiConsole.Progress()
AnsiConsole.WriteLine($"Processing {buildItems.Count()} items");
task6.Description = $"[bold]Stage 6[/]: Create Work Items (0/{buildItems.Count()})";
task6.StartTask();
await foreach ((WorkItemToBuild witb, string status, int skipped, int failed, int created) result in CreateWorkItemsToBuild(buildItems, projectItem, targetApi))
await foreach ((WorkItemToBuild witb, string status, int skipped, int failed, int created) result in CreateWorkItemsToBuild(buildItems, projectItem, targetApi, config.targetWorkItemType))
{
//AnsiConsole.WriteLine($"Stage 6: Processing {witb.guid} for output of {witb.relations.Count - 1} relations");
task6.Increment(1);
Expand Down Expand Up @@ -309,7 +309,7 @@ private async IAsyncEnumerable<WorkItemToBuild> generateWorkItemsToBuildRelation
}
}

private async IAsyncEnumerable<(WorkItemToBuild, string status, int skipped, int failed, int created)> CreateWorkItemsToBuild(List<WorkItemToBuild> workItemsToBuild, WorkItemFull projectItem, AzureDevOpsApi targetApi)
private async IAsyncEnumerable<(WorkItemToBuild, string status, int skipped, int failed, int created)> CreateWorkItemsToBuild(List<WorkItemToBuild> workItemsToBuild, WorkItemFull projectItem, AzureDevOpsApi targetApi, string workItemTypeToCreate)
{
int skipped = 0;
int failed = 0;
Expand All @@ -323,7 +323,7 @@ private async IAsyncEnumerable<WorkItemToBuild> generateWorkItemsToBuildRelation
} else
{
WorkItemAdd itemToAdd = CreateWorkItemAddOperation(item, workItemsToBuild, projectItem);
WorkItemFull newWorkItem = await targetApi.CreateWorkItem(itemToAdd, "Dependancy");
WorkItemFull newWorkItem = await targetApi.CreateWorkItem(itemToAdd, workItemTypeToCreate);
if (newWorkItem != null)
{
created++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ internal class WorkItemCloneCommandSettings : BaseCommandSettings
[Description("The project name for the target location")]
[CommandOption("--targetProject")]
public string? targetProject { get; set; }
[Description("The Name of the work item type to use when creating")]
[CommandOption("--targetWorkItemType|--wit")]
[DefaultValue("Deliverable")]
public string? targetWorkItemType { get; set; }
[Description("The ID of the work item in the target environment that will be the parent of all created work items.")]
[CommandOption("-p|--parentId|--targetParentId")]
public int? targetParentId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,24 @@ internal void CombineValuesFromConfigAndSettings(WorkItemCloneCommandSettings se
config.targetProject = EnsureProjectAskIfMissing(config.targetProject = settings.targetProject != null ? settings.targetProject : config.targetProject, config.targetOrganization);
config.targetAccessToken = EnsureAccessTokenAskIfMissing(settings.targetAccessToken != null ? settings.targetAccessToken : config.targetAccessToken, config.targetOrganization);
config.targetParentId = EnsureParentIdAskIfMissing(config.targetParentId = settings.targetParentId != null ? settings.targetParentId : config.targetParentId);
config.targetWorkItemType = EnsureWorkItemTypeAskIfMissing(config.targetWorkItemType = settings.targetWorkItemType != null ? settings.targetWorkItemType : config.targetWorkItemType);
}

private string? EnsureWorkItemTypeAskIfMissing(string? v)
{
if (v == null)
{
v = AnsiConsole.Prompt(
new TextPrompt<string>("What is the target Work Item Type?")
.Validate(v
=> !string.IsNullOrWhiteSpace(v)
? ValidationResult.Success()
: ValidationResult.Error("[yellow]Invalid Work Item Type[/]")));
}
return v;

}

internal int EnsureParentIdAskIfMissing(int? parentId)
{
if (parentId == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"Clone": {
"commandName": "Project",
"commandLineArgs": "clone --RunName Run1 --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration.json --jsonFile ..\\..\\..\\..\\..\\TestData\\ADO_TESTProjPipline_V03.json "
"commandLineArgs": "clone --RunName Allessandro2 --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration.json --jsonFile ..\\..\\..\\..\\..\\TestData\\new.json "
},
"empty": {
"commandName": "Project"
Expand Down
25 changes: 15 additions & 10 deletions AzureDevOps.WorkItemClone/AzureDevOpsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace AzureDevOps.WorkItemClone
Expand Down Expand Up @@ -122,17 +123,21 @@ private async Task<string> GetResult(string apiToCall, string? post, string? med
}
catch (Exception ex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"-----------------------------");
sb.AppendLine($"Azure DevOps API Call Failed!");
sb.AppendLine($"apiCallUrl: {apiCallUrl}");
sb.AppendLine($"mediaType: {mediaType}");
sb.AppendLine($"Post: {post}");
sb.AppendLine($"Result: {result}");
sb.AppendLine($"ObjectType: {typeof(T).ToString}");
sb.AppendLine($"-----------------------------");
sb.AppendLine(ex.ToString());
sb.AppendLine($"-----------------------------");
// Should be logger
Console.WriteLine($"-----------------------------");
Console.WriteLine($"Azure DevOps API Call Failed!");
Console.WriteLine($"apiCallUrl: {apiCallUrl}");
Console.WriteLine($"mediaType: {mediaType}");
Console.WriteLine($"Post: {post}");
Console.WriteLine($"Result: {result}");
Console.WriteLine($"ObjectType: {typeof(T).ToString}");
Console.WriteLine($"-----------------------------");
Console.WriteLine(ex.ToString());
Console.WriteLine($"-----------------------------");
Console.WriteLine(sb.ToString());
System.IO.File.WriteAllText($"./.errors/{DateTime.Today.ToString("yyyyyMMddHHmmss")}.txt", sb.ToString());

}
return default(T);
}
Expand Down
Loading

0 comments on commit a958e99

Please sign in to comment.