last ...
This commit is contained in:
@@ -17,9 +17,10 @@ namespace xApi.Constants
|
||||
|
||||
//
|
||||
#region WorkItems(s)/Issues ...
|
||||
public const string WorkItemFieldsEndpoint = "/wit/fields";
|
||||
public const string WorkItemsQueryEndpoint = "/wit/wiql";
|
||||
public const string WorkItemsBaseEndpoint = "/wit/workitems";
|
||||
public const string WorkItemTypesEndpoint = "/wit/workitemtype";
|
||||
public const string WorkItemTypesEndpoint = "/wit/workitemtypes";
|
||||
public const string WorkItemsODataEndpoint = "Issue%20Tracker/_odata/v4.0-preview/WorkItems?$top=1&$select=WorkItemId,Title";
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using xApi.Models;
|
||||
using xApi.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xApi.Models;
|
||||
|
||||
namespace xApi.Controllers
|
||||
{
|
||||
@@ -110,10 +110,12 @@ namespace xApi.Controllers
|
||||
/// <summary>
|
||||
/// Get WorkItem Types from Azure Services ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetWorkItemTypes")]
|
||||
public async Task<ActionResult<string>> GetWorkItemTypes(
|
||||
[HttpGet("WorkItem/{id}")]
|
||||
public async Task<ActionResult<AzureWorkItemDto>> GetWorkItem(
|
||||
[FromRoute] long id,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -122,7 +124,10 @@ namespace xApi.Controllers
|
||||
{
|
||||
//
|
||||
var response = await azureServices
|
||||
.GetWorkItemTypesAsync(cancellationToken);
|
||||
.GetWorkItemAsync(
|
||||
workItemId: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(response);
|
||||
@@ -134,5 +139,101 @@ namespace xApi.Controllers
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get WorkItem Types from Azure Services ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("WorkItem/{id}/Revisions")]
|
||||
public async Task<ActionResult<AzureWorkItemDto>> GetWorkItemRevisions(
|
||||
[FromRoute] long id,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var response = await azureServices
|
||||
.GetWorkItemRevisionsAsync(
|
||||
workItemId: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
logger.LogError(ex, "Error occurred ...");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Work Item Fields ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("WorkItems/Fields")]
|
||||
public async Task<ActionResult<AzureListDto<AzureWorkItemFieldDto>>> GetWorkItemFields(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var response = await azureServices
|
||||
.GetWorkItemFieldsAsync(
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
logger.LogError(ex, "Error occurred ...");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified Project's WorkItem Types ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("projects/{id}/WorkItemTypes")]
|
||||
public async Task<ActionResult<AzureListDto<AzureWorkItemTypeDto>>> GetProjectWorkItemTypes(
|
||||
[FromRoute] Guid id,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var response = await azureServices
|
||||
.GetProjectWorkItemTypesAsync(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
logger.LogError(ex, "Error occurred ...");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,5 +52,26 @@ namespace xApi.Extensions
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a URL Segment ...
|
||||
/// </summary>
|
||||
/// <param name="segment"></param>
|
||||
/// <returns></returns>
|
||||
public static string NormalizeUrlSegent(
|
||||
this string segment
|
||||
)
|
||||
{
|
||||
//
|
||||
if (!string.IsNullOrWhiteSpace(segment) &&
|
||||
segment.StartsWith("/")
|
||||
)
|
||||
{
|
||||
segment = segment[1..];
|
||||
}
|
||||
|
||||
//
|
||||
return segment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
using xApi.Models;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace xApi.Helpers
|
||||
{
|
||||
public struct AzureWorkItemJsonProperties
|
||||
{
|
||||
public const string State = "System.State";
|
||||
public const string Title = "System.Title";
|
||||
public const string Reason = "System.Reason";
|
||||
public const string AreaPath = "System.AreaPath";
|
||||
public const string CreatedBy = "System.CreatedBy";
|
||||
public const string ChangedBy = "System.ChangedBy";
|
||||
public const string AssignedTo = "System.AssignedTo";
|
||||
public const string ChangedDate = "System.ChangedDate";
|
||||
public const string BoardColumn = "System.BoardColumn";
|
||||
public const string Description = "System.Description";
|
||||
public const string CreatedDate = "System.CreatedDate";
|
||||
public const string TeamProject = "System.TeamProject";
|
||||
public const string CommentCount = "System.CommentCount";
|
||||
public const string WorkItemType = "System.WorkItemType";
|
||||
public const string IterationPath = "System.IterationPath";
|
||||
public const string BoardColumnDone = "System.BoardColumnDone";
|
||||
}
|
||||
|
||||
public class AzureWorkItemFieldsDtoConverter : JsonConverter<AzureWorkItemFieldsDto>
|
||||
{
|
||||
public override AzureWorkItemFieldsDto Read(
|
||||
ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options
|
||||
)
|
||||
{
|
||||
//
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
{
|
||||
throw new JsonException("WorkItem fields must be a JSON object.");
|
||||
}
|
||||
|
||||
//
|
||||
var dto = new AzureWorkItemFieldsDto();
|
||||
while (reader.Read())
|
||||
{
|
||||
//
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
return dto;
|
||||
}
|
||||
|
||||
//
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
|
||||
//
|
||||
var propertyName = reader.GetString()!;
|
||||
reader.Read();
|
||||
switch (propertyName)
|
||||
{
|
||||
//
|
||||
case AzureWorkItemJsonProperties.AreaPath:
|
||||
dto.AreaPath = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.TeamProject:
|
||||
dto.TeamProject = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.IterationPath:
|
||||
dto.IterationPath = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.WorkItemType:
|
||||
dto.WorkItemType = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.State:
|
||||
dto.State = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.Reason:
|
||||
dto.Reason = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.AssignedTo:
|
||||
dto.AssignedTo = ReadAssignee(ref reader, options);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.CreatedDate:
|
||||
dto.CreatedDate = ReadDateTimeOffset(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.CreatedBy:
|
||||
dto.CreatedBy = ReadAssignee(ref reader, options);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.ChangedDate:
|
||||
dto.ChangedDate = ReadDateTimeOffset(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.ChangedBy:
|
||||
dto.ChangedBy = ReadAssignee(ref reader, options);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.CommentCount:
|
||||
dto.CommentCount = ReadInt32(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.Title:
|
||||
dto.Title = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.BoardColumn:
|
||||
dto.BoardColumn = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.BoardColumnDone:
|
||||
dto.BoardColumnDone = ReadBoolean(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
case AzureWorkItemJsonProperties.Description:
|
||||
dto.Description = ReadString(ref reader);
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
dto.OtherFields[propertyName] = ReadValueAsString(ref reader);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
throw new JsonException("Unexpected end of JSON.");
|
||||
}
|
||||
|
||||
public override void Write(
|
||||
Utf8JsonWriter writer,
|
||||
AzureWorkItemFieldsDto value,
|
||||
JsonSerializerOptions options
|
||||
)
|
||||
{
|
||||
//
|
||||
writer.WriteStartObject();
|
||||
|
||||
//
|
||||
WriteString(writer, AzureWorkItemJsonProperties.AreaPath, value.AreaPath);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.TeamProject, value.TeamProject);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.IterationPath, value.IterationPath);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.WorkItemType, value.WorkItemType);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.State, value.State);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.Reason, value.Reason);
|
||||
|
||||
//
|
||||
WriteAssignee(writer, AzureWorkItemJsonProperties.AssignedTo, value.AssignedTo, options);
|
||||
WriteDateTimeOffset(writer, AzureWorkItemJsonProperties.CreatedDate, value.CreatedDate);
|
||||
WriteAssignee(writer, AzureWorkItemJsonProperties.CreatedBy, value.CreatedBy, options);
|
||||
WriteDateTimeOffset(writer, AzureWorkItemJsonProperties.ChangedDate, value.ChangedDate);
|
||||
WriteAssignee(writer, AzureWorkItemJsonProperties.ChangedBy, value.ChangedBy, options);
|
||||
|
||||
//
|
||||
writer.WriteNumber(AzureWorkItemJsonProperties.CommentCount, value.CommentCount);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.Title, value.Title);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.BoardColumn, value.BoardColumn);
|
||||
|
||||
//
|
||||
writer.WriteBoolean(AzureWorkItemJsonProperties.BoardColumnDone, value.BoardColumnDone);
|
||||
WriteString(writer, AzureWorkItemJsonProperties.Description, value.Description);
|
||||
|
||||
//
|
||||
foreach (var item in value.OtherFields)
|
||||
{
|
||||
writer.WriteString(item.Key, item.Value);
|
||||
}
|
||||
|
||||
//
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
private static string? ReadString(ref Utf8JsonReader reader)
|
||||
=> reader.TokenType == JsonTokenType.Null
|
||||
? null
|
||||
: reader.GetString();
|
||||
|
||||
private static AzureAssigneeDto? ReadAssignee(
|
||||
ref Utf8JsonReader reader,
|
||||
JsonSerializerOptions options
|
||||
)
|
||||
{
|
||||
//
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
var result = doc.RootElement.Deserialize<AzureAssigneeDto>(options);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DateTimeOffset? ReadDateTimeOffset(ref Utf8JsonReader reader)
|
||||
=> reader.TokenType == JsonTokenType.Null
|
||||
? null
|
||||
: reader.GetDateTimeOffset();
|
||||
|
||||
private static int ReadInt32(ref Utf8JsonReader reader)
|
||||
=> reader.TokenType == JsonTokenType.Null
|
||||
? 0
|
||||
: reader.GetInt32();
|
||||
|
||||
private static bool ReadBoolean(ref Utf8JsonReader reader)
|
||||
=> reader.TokenType != JsonTokenType.Null && reader.GetBoolean();
|
||||
|
||||
private static string ReadValueAsString(ref Utf8JsonReader reader)
|
||||
{
|
||||
//
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
//
|
||||
case JsonTokenType.String:
|
||||
return reader.GetString() ?? "null";
|
||||
|
||||
//
|
||||
case JsonTokenType.Null:
|
||||
return "null";
|
||||
|
||||
//
|
||||
case JsonTokenType.True:
|
||||
return "true";
|
||||
|
||||
//
|
||||
case JsonTokenType.False:
|
||||
return "false";
|
||||
|
||||
//
|
||||
case JsonTokenType.Number:
|
||||
{
|
||||
//
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
return doc.RootElement.GetRawText();
|
||||
}
|
||||
|
||||
//
|
||||
case JsonTokenType.StartObject:
|
||||
case JsonTokenType.StartArray:
|
||||
{
|
||||
//
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
return doc.RootElement.GetRawText();
|
||||
}
|
||||
|
||||
//
|
||||
default:
|
||||
{
|
||||
//
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
return doc.RootElement.GetRawText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteString(
|
||||
Utf8JsonWriter writer,
|
||||
string name,
|
||||
string? value
|
||||
)
|
||||
{
|
||||
//
|
||||
if (value is null)
|
||||
{
|
||||
writer.WriteNull(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteString(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteDateTimeOffset(
|
||||
Utf8JsonWriter writer,
|
||||
string name,
|
||||
DateTimeOffset? value
|
||||
)
|
||||
{
|
||||
//
|
||||
if (value.HasValue)
|
||||
{
|
||||
writer.WriteString(name, value.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteNull(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteAssignee(
|
||||
Utf8JsonWriter writer,
|
||||
string name,
|
||||
AzureAssigneeDto? value,
|
||||
JsonSerializerOptions options
|
||||
)
|
||||
{
|
||||
//
|
||||
writer.WritePropertyName(name);
|
||||
if (value is null)
|
||||
{
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,45 @@ namespace xApi.Interfaces
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
Task<string> GetWorkItemTypesAsync(
|
||||
/// <summary>
|
||||
/// Retrieve Specified Work Item ...
|
||||
/// </summary>
|
||||
/// <param name="workItemId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<AzureWorkItemDto> GetWorkItemAsync(
|
||||
long workItemId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified Project's WorkItem Types ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<AzureListDto<AzureWorkItemTypeDto>> GetProjectWorkItemTypesAsync(
|
||||
Guid id,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified WorkItem Revisions (History) ...
|
||||
/// </summary>
|
||||
/// <param name="workItemId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<AzureListDto<WorkItemRevisionDto>> GetWorkItemRevisionsAsync(
|
||||
long workItemId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Work Item Fields ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<AzureListDto<AzureWorkItemFieldDto>> GetWorkItemFieldsAsync(
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using xApi.Helpers;
|
||||
|
||||
namespace xApi.Models
|
||||
{
|
||||
@@ -134,6 +136,301 @@ namespace xApi.Models
|
||||
public AzureProjectDto? Project { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemDto
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("rev")]
|
||||
public int Rev { get; set; }
|
||||
|
||||
[JsonPropertyName("fields")]
|
||||
public AzureWorkItemFieldsDto? Fields { get; set; }
|
||||
|
||||
[JsonPropertyName("_links")]
|
||||
public AzureWorkItemLinksDto? Links { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(AzureWorkItemFieldsDtoConverter))]
|
||||
public class AzureWorkItemFieldsDto
|
||||
{
|
||||
[JsonPropertyName("System.AreaPath")]
|
||||
public string? AreaPath { get; set; }
|
||||
|
||||
[JsonPropertyName("System.TeamProject")]
|
||||
public string? TeamProject { get; set; }
|
||||
|
||||
[JsonPropertyName("System.IterationPath")]
|
||||
public string? IterationPath { get; set; }
|
||||
|
||||
[JsonPropertyName("System.WorkItemType")]
|
||||
public string? WorkItemType { get; set; }
|
||||
|
||||
[JsonPropertyName("System.State")]
|
||||
public string? State { get; set; }
|
||||
|
||||
[JsonPropertyName("System.Reason")]
|
||||
public string? Reason { get; set; }
|
||||
|
||||
[JsonPropertyName("System.AssignedTo")]
|
||||
public AzureAssigneeDto? AssignedTo { get; set; }
|
||||
|
||||
[JsonPropertyName("System.CreatedDate")]
|
||||
public DateTimeOffset? CreatedDate { get; set; }
|
||||
|
||||
[JsonPropertyName("System.CreatedBy")]
|
||||
public AzureAssigneeDto? CreatedBy { get; set; }
|
||||
|
||||
[JsonPropertyName("System.ChangedDate")]
|
||||
public DateTimeOffset? ChangedDate { get; set; }
|
||||
|
||||
[JsonPropertyName("System.ChangedBy")]
|
||||
public AzureAssigneeDto? ChangedBy { get; set; }
|
||||
|
||||
[JsonPropertyName("System.CommentCount")]
|
||||
public int CommentCount { get; set; }
|
||||
|
||||
[JsonPropertyName("System.Title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonPropertyName("System.BoardColumn")]
|
||||
public string? BoardColumn { get; set; }
|
||||
|
||||
[JsonPropertyName("System.BoardColumnDone")]
|
||||
public bool BoardColumnDone { get; set; }
|
||||
|
||||
[JsonPropertyName("System.Description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
public Dictionary<string, string> OtherFields { get; set; }
|
||||
= new(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public class WorkItemRevisionDto
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("rev")]
|
||||
public int Rev { get; set; }
|
||||
|
||||
[JsonPropertyName("fields")]
|
||||
public AzureWorkItemFieldsDto? Fields { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemTypeDto
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("referenceName")]
|
||||
public string? ReferenceName { get; set; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[JsonPropertyName("color")]
|
||||
public string? Color { get; set; }
|
||||
|
||||
[JsonPropertyName("icon")]
|
||||
public AzureWorkItemTypeIconDto? Icon { get; set; }
|
||||
|
||||
[JsonPropertyName("isDisabled")]
|
||||
public bool IsDisabled { get; set; }
|
||||
|
||||
[JsonPropertyName("xmlForm")]
|
||||
public string? XmlForm { get; set; }
|
||||
|
||||
[JsonPropertyName("fields")]
|
||||
public List<AzureWorkItemFieldDefinitionDto> Fields { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("fieldInstances")]
|
||||
public List<AzureWorkItemFieldDefinitionDto> FieldInstances { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("transitions")]
|
||||
public Dictionary<string, List<AzureWorkItemTransitionDto>> Transitions { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("states")]
|
||||
public List<AzureWorkItemStateDto> States { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemFieldDto
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("referenceName")]
|
||||
public string? ReferenceName { get; set; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[JsonPropertyName("type")]
|
||||
public string? Type { get; set; }
|
||||
|
||||
[JsonPropertyName("usage")]
|
||||
public string? Usage { get; set; }
|
||||
|
||||
[JsonPropertyName("readOnly")]
|
||||
public bool ReadOnly { get; set; }
|
||||
|
||||
[JsonPropertyName("canSortBy")]
|
||||
public bool CanSortBy { get; set; }
|
||||
|
||||
[JsonPropertyName("isQueryable")]
|
||||
public bool IsQueryable { get; set; }
|
||||
|
||||
[JsonPropertyName("supportedOperations")]
|
||||
public List<AzureFieldSupportedOperationDto> SupportedOperations { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("isIdentity")]
|
||||
public bool IsIdentity { get; set; }
|
||||
|
||||
[JsonPropertyName("isPicklist")]
|
||||
public bool IsPicklist { get; set; }
|
||||
|
||||
[JsonPropertyName("isPicklistSuggested")]
|
||||
public bool IsPicklistSuggested { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? AdditionalProperties { get; set; }
|
||||
}
|
||||
|
||||
public class AzureFieldSupportedOperationDto
|
||||
{
|
||||
[JsonPropertyName("referenceName")]
|
||||
public string? ReferenceName { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemFieldDefinitionDto
|
||||
{
|
||||
[JsonPropertyName("defaultValue")]
|
||||
public JsonElement? DefaultValue { get; set; }
|
||||
|
||||
[JsonPropertyName("helpText")]
|
||||
public string? HelpText { get; set; }
|
||||
|
||||
[JsonPropertyName("alwaysRequired")]
|
||||
public bool AlwaysRequired { get; set; }
|
||||
|
||||
[JsonPropertyName("referenceName")]
|
||||
public string? ReferenceName { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? AdditionalProperties { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemTransitionDto
|
||||
{
|
||||
[JsonPropertyName("to")]
|
||||
public string? To { get; set; }
|
||||
|
||||
[JsonPropertyName("actions")]
|
||||
public List<string>? Actions { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemStateDto
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("color")]
|
||||
public string? Color { get; set; }
|
||||
|
||||
[JsonPropertyName("category")]
|
||||
public string? Category { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemTypeIconDto
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
}
|
||||
|
||||
public class AzureAssigneeDto
|
||||
{
|
||||
[JsonPropertyName("displayName")]
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
[JsonPropertyName("_links")]
|
||||
public AzureAssigneeLinksDto? Links { get; set; }
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("uniqueName")]
|
||||
public string? UniqueName { get; set; }
|
||||
|
||||
[JsonPropertyName("imageUrl")]
|
||||
public string? ImageUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("descriptor")]
|
||||
public string? Descriptor { get; set; }
|
||||
}
|
||||
|
||||
public class AzureAssigneeLinksDto
|
||||
{
|
||||
[JsonPropertyName("avatar")]
|
||||
public AzureItemLinkDto? Avatar { get; set; }
|
||||
}
|
||||
|
||||
public class AzureWorkItemLinksDto
|
||||
{
|
||||
[JsonPropertyName("self")]
|
||||
public AzureItemLinkDto? Self { get; set; }
|
||||
|
||||
[JsonPropertyName("workItemUpdates")]
|
||||
public AzureItemLinkDto? WorkItemUpdates { get; set; }
|
||||
|
||||
[JsonPropertyName("workItemRevisions")]
|
||||
public AzureItemLinkDto? WorkItemRevisions { get; set; }
|
||||
|
||||
[JsonPropertyName("workItemComments")]
|
||||
public AzureItemLinkDto? WorkItemComments { get; set; }
|
||||
|
||||
[JsonPropertyName("html")]
|
||||
public AzureItemLinkDto? Html { get; set; }
|
||||
|
||||
[JsonPropertyName("workItemType")]
|
||||
public AzureItemLinkDto? WorkItemType { get; set; }
|
||||
|
||||
[JsonPropertyName("fields")]
|
||||
public AzureItemLinkDto? Fields { get; set; }
|
||||
}
|
||||
|
||||
public class AzureItemLinkDto
|
||||
{
|
||||
[JsonPropertyName("href")]
|
||||
public string? Href { get; set; }
|
||||
}
|
||||
|
||||
public class AzureListDto<T>
|
||||
where T : class
|
||||
{
|
||||
|
||||
@@ -4,5 +4,6 @@ namespace xApi.Models
|
||||
{
|
||||
public string? Pat { get; set; }
|
||||
public string? BaseUrl { get; set; }
|
||||
public string? ApiSuffix { get; set; }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,8 +2,8 @@ using xApi.Extensions;
|
||||
using xApi.Attributes;
|
||||
using System.Reflection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
//
|
||||
// Access Application Builder ...
|
||||
|
||||
+193
-16
@@ -122,7 +122,60 @@ namespace xApi.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<string> GetWorkItemTypesAsync(
|
||||
/// <summary>
|
||||
/// Retrieve Specified Work Item ...
|
||||
/// </summary>
|
||||
/// <param name="workItemId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AzureWorkItemDto> GetWorkItemAsync(
|
||||
long workItemId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (workItemId <= 0)
|
||||
{
|
||||
//
|
||||
var message = "Invalid Args ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new ArgumentException(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare WorkItem Path ...
|
||||
var path = $"{AzureEndpoints.WorkItemsBaseEndpoint}/{workItemId}";
|
||||
var json = await HandleAzureRequest(
|
||||
path: path,
|
||||
method: HttpMethod.Get,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
var result = json.ParseJSON<AzureWorkItemDto>();
|
||||
if (result is null)
|
||||
{
|
||||
//
|
||||
var message = "Failed to parse Azure data ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Work Item Fields ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AzureListDto<AzureWorkItemFieldDto>> GetWorkItemFieldsAsync(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -130,26 +183,111 @@ namespace xApi.Providers
|
||||
var json = await HandleAzureRequest(
|
||||
method: HttpMethod.Get,
|
||||
cancellationToken: cancellationToken,
|
||||
path: AzureEndpoints.WorkItemsODataEndpoint
|
||||
path: AzureEndpoints.WorkItemFieldsEndpoint
|
||||
);
|
||||
|
||||
//
|
||||
return json;
|
||||
var result = json.ParseJSON<AzureListDto<AzureWorkItemFieldDto>>();
|
||||
if (result is null)
|
||||
{
|
||||
//
|
||||
var message = "Failed to parse Azure data ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
//
|
||||
// var result = json.ParseJSON<AzureListDto<AzureRepositoryDto>>();
|
||||
// if (result is null)
|
||||
// {
|
||||
// //
|
||||
// var message = "Failed to parse Azure data ...";
|
||||
return result;
|
||||
}
|
||||
|
||||
// //
|
||||
// logger.LogError(message);
|
||||
// throw new InvalidOperationException(message);
|
||||
// }
|
||||
/// <summary>
|
||||
/// Get Specified Project's WorkItem Types ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AzureListDto<AzureWorkItemTypeDto>> GetProjectWorkItemTypesAsync(
|
||||
Guid id,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Custom Path for WorkItem ...
|
||||
var path = $"{PrepareProjectBaseUrl(id)}/{AzureEndpoints.WorkItemTypesEndpoint.NormalizeUrlSegent()}";
|
||||
|
||||
// //
|
||||
// return result;
|
||||
//
|
||||
var json = await HandleAzureRequest(
|
||||
path: path,
|
||||
forceApiSuffix: false,
|
||||
method: HttpMethod.Get,
|
||||
forceJsonValidation: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
var result = json.ParseJSON<AzureListDto<AzureWorkItemTypeDto>>();
|
||||
if (result is null)
|
||||
{
|
||||
//
|
||||
var message = "Failed to parse Azure data ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified WorkItem Revisions (History) ...
|
||||
/// </summary>
|
||||
/// <param name="workItemId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AzureListDto<WorkItemRevisionDto>> GetWorkItemRevisionsAsync(
|
||||
long workItemId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (workItemId <= 0)
|
||||
{
|
||||
//
|
||||
var message = "Invalid Args ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new ArgumentException(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare WorkItem Path ...
|
||||
var path = $"{AzureEndpoints.WorkItemsBaseEndpoint}/{workItemId}/revisions";
|
||||
var json = await HandleAzureRequest(
|
||||
path: path,
|
||||
method: HttpMethod.Get,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
var result = json.ParseJSON<AzureListDto<WorkItemRevisionDto>>();
|
||||
if (result is null)
|
||||
{
|
||||
//
|
||||
var message = "Failed to parse Azure data ...";
|
||||
|
||||
//
|
||||
logger.LogError(message);
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -159,6 +297,7 @@ namespace xApi.Providers
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="forceApiSuffix"></param>
|
||||
/// <param name="forceJsonValidation"></param>
|
||||
/// <param name="headers"></param>
|
||||
/// <param name="queryParams"></param>
|
||||
@@ -168,6 +307,7 @@ namespace xApi.Providers
|
||||
private async Task<string> HandleAzureRequest(
|
||||
string path,
|
||||
HttpMethod method,
|
||||
bool forceApiSuffix = true,
|
||||
bool forceJsonValidation = true,
|
||||
IDictionary<string, string>? headers = null,
|
||||
IDictionary<string, string>? queryParams = null,
|
||||
@@ -217,6 +357,26 @@ namespace xApi.Providers
|
||||
{
|
||||
url += "/";
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Suffix ...
|
||||
if (forceApiSuffix &&
|
||||
!string.IsNullOrWhiteSpace(configuration.ApiSuffix)
|
||||
)
|
||||
{
|
||||
//
|
||||
var suffix = configuration.ApiSuffix;
|
||||
if (suffix.StartsWith('/'))
|
||||
{
|
||||
suffix = suffix[1..];
|
||||
}
|
||||
|
||||
//
|
||||
url += $"{suffix}/";
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Path ...
|
||||
if (path.StartsWith('/'))
|
||||
{
|
||||
path = path[1..];
|
||||
@@ -225,7 +385,8 @@ namespace xApi.Providers
|
||||
//
|
||||
// Handle Route Params ...
|
||||
if (routeParams is not null &&
|
||||
routeParams.Any())
|
||||
routeParams.Any()
|
||||
)
|
||||
{
|
||||
//
|
||||
var exists =
|
||||
@@ -255,7 +416,8 @@ namespace xApi.Providers
|
||||
//
|
||||
// Applying Headers ...
|
||||
if (headers is not null &&
|
||||
headers.Any())
|
||||
headers.Any()
|
||||
)
|
||||
{
|
||||
//
|
||||
foreach (var header in headers)
|
||||
@@ -275,6 +437,7 @@ namespace xApi.Providers
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Request ...
|
||||
try
|
||||
{
|
||||
//
|
||||
@@ -340,6 +503,20 @@ namespace xApi.Providers
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
private string PrepareProjectBaseUrl(
|
||||
Guid id
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = $"{id}/{configuration.ApiSuffix?.NormalizeUrlSegent()}";
|
||||
if (result.EndsWith('/')) {
|
||||
result = result[..^1];
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,9 @@
|
||||
"Url": "https://rpkavosh.ir"
|
||||
},
|
||||
"AzureServiceConfiguration": {
|
||||
"Pat": "6zvwbdviuswlets7ovugq7nningtx4v6gqll7qkyqhnn75nrxh3q",
|
||||
"BaseUrl": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis"
|
||||
"ApiSuffix": "/_apis",
|
||||
"BaseUrl": "http://192.168.10.22:8080/tfs/RPKavoshDevOps",
|
||||
"Pat": "6zvwbdviuswlets7ovugq7nningtx4v6gqll7qkyqhnn75nrxh3q"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Reference in New Issue
Block a user