Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updating
  • Loading branch information
DiegoGalante committed Jul 15, 2021
commit 6683ed7abe19d290b29a0561a6a893825957e4fa
48 changes: 38 additions & 10 deletions AzureDevopsStateTracker/Adapters/WorkItemAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AzureDevopsStateTracker.DTOs;
using AzureDevopsStateTracker.Entities;
using AzureDevopsStateTracker.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -20,11 +21,18 @@ public WorkItemDTO ToWorkItemDTO(WorkItem workItem)
CreatedBy = workItem.CreatedBy,
CurrentStatus = workItem.CurrentStatus,
TeamProject = workItem.TeamProject,
AreaPath = workItem.AreaPath,
IterationPath = workItem.IterationPath,
Title = workItem.Title,
Type = workItem.Type,
Effort = workItem.Effort,
StoryPoints = workItem.StoryPoints,
OriginalEstimate = workItem.OriginalEstimate,
WorkItemParentId = workItem.WorkItemParentId,
Activity = workItem.Activity,
Tags = workItem.Tags == null ? new List<string>() : workItem.Tags.Split(';').ToList(),
WorkItemsChangesDTO = ToWorkItemsChangeDTO(workItem.WorkItemsChanges.OrderBy(x => x.CreatedAt).ToList()),
WorkItemsStatusTimeDTO = ToWorkItemsStatusTimeDTO(workItem.WorkItemsStatusTime.OrderBy(x => x.CreatedAt).ToList()),
TotalTimeByState = workItem.CalculateTotalTimeByState()
TimesByStateDTO = ToTimeByStatesDTO(workItem.CalculateTotalTimeByState().ToList()),
};
}

Expand All @@ -39,7 +47,6 @@ public List<WorkItemDTO> ToWorkItemsDTO(List<WorkItem> workItems)
workItemsDTO.Add(ToWorkItemDTO(workItem)));

return workItemsDTO
.Where(w => w != null)
.ToList();
}

Expand All @@ -52,7 +59,8 @@ public WorkItemChangeDTO ToWorkItemChangeDTO(WorkItemChange workIteChange)
NewDate = workIteChange.NewDate,
NewState = workIteChange.NewState,
OldState = workIteChange.OldState,
OldDate = workIteChange.OldDate
OldDate = workIteChange.OldDate,
ChangedBy = workIteChange.ChangedBy
};
}

Expand All @@ -71,30 +79,50 @@ public List<WorkItemChangeDTO> ToWorkItemsChangeDTO(List<WorkItemChange> workIte
.ToList();
}

public WorkItemStatusTimeDTO ToWorkItemStatusTimeDTO(WorkItemStatusTime workItemStatusTime)
public TimeByStateDTO ToTimeByStateDTO(TimeByState workItemStatusTime)
{
if (workItemStatusTime == null) return null;

return new WorkItemStatusTimeDTO()
return new TimeByStateDTO()
{
CreatedAt = workItemStatusTime.CreatedAt,
UpdatedAt = workItemStatusTime.UpdatedAt,
State = workItemStatusTime.State,
TotalTime = workItemStatusTime.TotalTime.ToString()
TotalTime = ToStringTime(new DateTime(workItemStatusTime.TotalTime).TimeOfDay),
TotalWorkedTime = ToStringTime(new DateTime(workItemStatusTime.TotalWorkedTime).TimeOfDay)
};
}

public List<WorkItemStatusTimeDTO> ToWorkItemsStatusTimeDTO(List<WorkItemStatusTime> workItemStatusTimes)
public List<TimeByStateDTO> ToTimeByStatesDTO(List<TimeByState> workItemStatusTimes)
{
var workItemStatusTimeDTO = new List<WorkItemStatusTimeDTO>();
var workItemStatusTimeDTO = new List<TimeByStateDTO>();

if (workItemStatusTimes == null) return workItemStatusTimeDTO;

workItemStatusTimes.ForEach(
workItemStatusTime =>
workItemStatusTimeDTO.Add(ToWorkItemStatusTimeDTO(workItemStatusTime)));
workItemStatusTimeDTO.Add(ToTimeByStateDTO(workItemStatusTime)));

return workItemStatusTimeDTO
.Where(w => w != null)
.ToList();
}

public string ToStringTime(TimeSpan timeSpan)
{
if (timeSpan.Days > 0)
return $@"{timeSpan:%d} Dia(s) {timeSpan:%h}h e {timeSpan:%m}min e {timeSpan:%s}s";

if (timeSpan.Hours > 0)
return $@"{timeSpan:%h}h e {timeSpan:%m}min e {timeSpan:%s}s";

if (timeSpan.Minutes > 0)
return $@"{timeSpan:%m}min e {timeSpan:%s}s";

if (timeSpan.Seconds > 0)
return $@"{timeSpan:%s}s";

return $@"{timeSpan:%hh}:{timeSpan:%mm}:{timeSpan:%ss}";
}
}
}
35 changes: 3 additions & 32 deletions AzureDevopsStateTracker/DTOs/Create/CreateWorkItemDTO.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
using Newtonsoft.Json;
using System;

namespace AzureDevopsStateTracker.DTOs.Create
{
public class CreateWorkItemDTO
{
[JsonProperty("resource")]
public ResourceDTO Resource { get; set; }
public Resource Resource { get; set; }
}

public class ResourceDTO
public class Resource
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("fields")]
public FieldsDTO Fields { get; set; }
public Fields Fields { get; set; }
}

public class RevisionDTO
{
[JsonProperty("fields")]
public FieldsDTO Fields { get; set; }
}

public class FieldsDTO
{
[JsonProperty("System.AssignedTo")]
public string AssignedTo { get; set; }

[JsonProperty("System.WorkItemType")]
public string Type { get; set; }

[JsonProperty("System.CreatedDate")]
public DateTime CreatedDate { get; set; }

[JsonProperty("System.CreatedBy")]
public string CreatedBy { get; set; }

[JsonProperty("System.State")]
public string State { get; set; }

[JsonProperty("System.Title")]
public string Title { get; set; }
}

}
59 changes: 59 additions & 0 deletions AzureDevopsStateTracker/DTOs/Fields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json;
using System;

namespace AzureDevopsStateTracker.DTOs
{
public class Fields
{
[JsonProperty("System.AreaPath")]
public string AreaPath { get; set; }

[JsonProperty("System.TeamProject")]
public string TeamProject { get; set; }

[JsonProperty("System.IterationPath")]
public string IterationPath { get; set; }

[JsonProperty("System.AssignedTo")]
public string AssignedTo { get; set; }

[JsonProperty("System.WorkItemType")]
public string Type { get; set; }

[JsonProperty("System.CreatedDate")]
public DateTime CreatedDate { get; set; }

[JsonProperty("System.CreatedBy")]
public string CreatedBy { get; set; }

[JsonProperty("System.ChangedBy")]
public string ChangedBy { get; set; }

[JsonProperty("System.State")]
public string State { get; set; }

[JsonProperty("System.Title")]
public string Title { get; set; }

[JsonProperty("System.Tags")]
public string Tags { get; set; }

[JsonProperty("System.Parent")]
public string Parent { get; set; }

[JsonProperty("Microsoft.VSTS.Scheduling.StoryPoints")]
public string StoryPoints { get; set; }

[JsonProperty("Microsoft.VSTS.Scheduling.OriginalEstimate")]
public string OriginalEstimate { get; set; }

[JsonProperty("Microsoft.VSTS.Scheduling.RemainingWork")]
public string RemainingWork { get; set; }

[JsonProperty("Microsoft.VSTS.Scheduling.Effort")]
public string Effort { get; set; }

[JsonProperty("Microsoft.VSTS.Common.Activity")]
public string Activity { get; set; }
}
}
28 changes: 16 additions & 12 deletions AzureDevopsStateTracker/DTOs/Update/UpdateWorkItemDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,37 @@ namespace AzureDevopsStateTracker.DTOs.Update
public class UpdatedWorkItemDTO
{
[JsonProperty("resource")]
public ResourceDTO Resource { get; set; }
public Resource Resource { get; set; }
}

public class ResourceDTO
public class Resource
{
[JsonProperty("workItemId")]
public string WorkItemId { get; set; }

[JsonProperty("fields")]
public ResourceFieldsDTO Fields { get; set; }
public ResourceFields Fields { get; set; }

[JsonProperty("revision")]
public RevisionDTO Revision { get; set; }
public Revision Revision { get; set; }
}

public class RevisionDTO
public class Revision
{
[JsonProperty("fields")]
public RevisionFieldsDTO Fields { get; set; }
public Fields Fields { get; set; }
}

public class ResourceFieldsDTO
public class ResourceFields
{
[JsonProperty("System.State")]
public OldNewValues State { get; set; }

[JsonProperty("Microsoft.VSTS.Common.StateChangeDate")]
public DateTimeOldNewValues StateChangeDate { get; set; }
}

public class RevisionFieldsDTO
{
[JsonProperty("System.AssignedTo")]
public string AssignedTo { get; set; }
[JsonProperty("System.ChangedBy")]
public ChangedByOldNewValues ChangedBy { get; set; }
}

public class OldNewValues
Expand All @@ -60,5 +57,12 @@ public class DateTimeOldNewValues
public DateTime NewValue { get; set; }
}

public class ChangedByOldNewValues
{
[JsonProperty("oldValue")]
public string OldValue { get; set; }

[JsonProperty("newValue")]
public string NewValue { get; set; }
}
}
45 changes: 39 additions & 6 deletions AzureDevopsStateTracker/DTOs/WorkItemDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public class WorkItemDTO
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("effort")]
public string Effort { get; set; }

[JsonProperty("story_points")]
public string StoryPoints { get; set; }

[JsonProperty("original_estimate")]
public string OriginalEstimate { get; set; }

[JsonProperty("created_by")]
public string CreatedBy { get; set; }

Expand All @@ -27,17 +36,29 @@ public class WorkItemDTO
[JsonProperty("team_project")]
public string TeamProject { get; set; }

[JsonProperty("iteration_path")]
public string IterationPath { get; set; }

[JsonProperty("area_path")]
public string AreaPath { get; set; }

[JsonProperty("current_status")]
public string CurrentStatus { get; set; }

[JsonProperty("work_item_parent_id")]
public string WorkItemParentId { get; set; }

[JsonProperty("activity")]
public string Activity { get; set; }

[JsonProperty("tags")]
public IEnumerable<string> Tags { get; set; }

[JsonProperty("workItems_changes")]
public List<WorkItemChangeDTO> WorkItemsChangesDTO { get; set; }

[JsonProperty("workItems_status_time")]
public List<WorkItemStatusTimeDTO> WorkItemsStatusTimeDTO { get; set; }

[JsonProperty("total_time_by_state")]
public IEnumerable<Dictionary<string, string>> TotalTimeByState { get; set; }
[JsonProperty("times_by_state")]
public List<TimeByStateDTO> TimesByStateDTO { get; set; }
}

public class WorkItemChangeDTO
Expand All @@ -53,15 +74,27 @@ public class WorkItemChangeDTO

[JsonProperty("old_date")]
public DateTime? OldDate { get; set; }

[JsonProperty("changed_by")]
public string ChangedBy { get; set; }
}


public class WorkItemStatusTimeDTO
public class TimeByStateDTO
{
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }

[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }

[JsonProperty("state")]
public string State { get; set; }

[JsonProperty("total_time")]
public string TotalTime { get; set; }

[JsonProperty("total_worked_time")]
public string TotalWorkedTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using AzureDevopsStateTracker.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Linq;

Expand All @@ -14,7 +12,7 @@ public AzureDevopsStateTrackerContext(DbContextOptions options) : base(options)

public DbSet<WorkItem> WorkItems { get; set; }
public DbSet<WorkItemChange> WorkItemsChange { get; set; }
public DbSet<WorkItemStatusTime> WorkItemsStatusTime { get; set; }
public DbSet<TimeByState> TimeByStates { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Loading