Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/Adapters/WorkItemAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<WorkItemDto> ToWorkItemsDto(List<WorkItem> workItems)
.ToList();
}

public WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
public static WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
{
if (workIteChange is null) return null;

Expand All @@ -65,7 +65,7 @@ public WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
};
}

public List<WorkItemChangeDto> ToWorkItemsChangeDto(List<WorkItemChange> workItemsChanges)
public static List<WorkItemChangeDto> ToWorkItemsChangeDto(List<WorkItemChange> workItemsChanges)
{
var workItemsChangeDto = new List<WorkItemChangeDto>();

Expand All @@ -80,7 +80,7 @@ public List<WorkItemChangeDto> ToWorkItemsChangeDto(List<WorkItemChange> workIte
.ToList();
}

public TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
public static TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
{
if (workItemStatusTime is null) return null;

Expand All @@ -93,7 +93,7 @@ public TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
};
}

public List<TimeByStateDto> ToTimeByStatesDto(List<TimeByState> workItemStatusTimes)
public static List<TimeByStateDto> ToTimeByStatesDto(List<TimeByState> workItemStatusTimes)
{
var workItemStatusTimeDto = new List<TimeByStateDto>();

Expand Down
7 changes: 4 additions & 3 deletions src/AzureDevopsTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.28" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="..\LICENSE.md.txt">
<Pack>True</Pack>
<PackagePath></PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace AzureDevopsTracker.Configurations
{
public static class Configuration
{
public static IServiceCollection AddAzureDevopsTracker(this IServiceCollection services, DataBaseConfig configurations, MessageConfig messageConfig = null)
public static IServiceCollection AddAzureDevopsTracker(this IServiceCollection services,
DataBaseConfig configurations,
MessageConfig messageConfig = null)
{
services.AddDbContext<AzureDevopsTrackerContext>(options =>
options.UseSqlServer(DataBaseConfig.ConnectionsString));
Expand Down
10 changes: 6 additions & 4 deletions src/Data/ChangeLogItemRepository.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using AzureDevopsTracker.Data.Context;
using AzureDevopsTracker.Entities;
using AzureDevopsTracker.Interfaces.Internals;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Data
{
internal class ChangeLogItemRepository : Repository<ChangeLogItem>, IChangeLogItemRepository
{
public ChangeLogItemRepository(AzureDevopsTrackerContext context) : base(context) { }

public int CountItemsForRelease()
public async Task<int> CountItemsForRelease()
{
return DbSet.Count(x => string.IsNullOrEmpty(x.ChangeLogId));
return await DbSet.CountAsync(x => string.IsNullOrEmpty(x.ChangeLogId));
}

public IEnumerable<ChangeLogItem> ListWaitingForRelease()
public async Task<IEnumerable<ChangeLogItem>> ListWaitingForRelease()
{
return DbSet.Where(x => string.IsNullOrEmpty(x.ChangeLogId));
return await DbSet.Where(x => string.IsNullOrEmpty(x.ChangeLogId)).ToListAsync();
}
}
}
7 changes: 4 additions & 3 deletions src/Data/ChangeLogRepository.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using AzureDevopsTracker.Data.Context;
using AzureDevopsTracker.Entities;
using AzureDevopsTracker.Interfaces.Internals;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Data
{
internal class ChangeLogRepository : Repository<ChangeLog>, IChangeLogRepository
{
public ChangeLogRepository(AzureDevopsTrackerContext context) : base(context) { }

public int CountChangeLogsCreatedToday()
public async Task<int> CountChangeLogsCreatedToday()
{
return DbSet.Count(x => x.CreatedAt.Date == DateTime.Now.Date);
return await DbSet.CountAsync(x => x.CreatedAt.Date == DateTime.Now.Date);
}
}
}
2 changes: 1 addition & 1 deletion src/Entities/ChangeLogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ChangeLogItem : Entity
public string Description { get; private set; }
public string WorkItemType { get; private set; }
public string ChangeLogId { get; private set; }
public bool WasReleased => string.IsNullOrEmpty(ChangeLogId?.Trim());
public bool WasReleased => string.IsNullOrWhiteSpace(ChangeLogId);
public ChangeLog ChangeLog { get; private set; }

private ChangeLogItem() { }
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/WorkItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public IEnumerable<TimeByState> CalculateTotalTimeByState()
if (!_workItemsChanges.Any())
return timesByStateList;

foreach (var workItemChange in _workItemsChanges.OrderBy(x => x.CreatedAt).GroupBy(x => x.OldState).Where(x => x.Key is not null))
foreach (var workItemChange in _workItemsChanges.OrderBy(x => x.CreatedAt)
.GroupBy(x => x.OldState)
.Where(x => x.Key is not null))
{
var totalTime = TimeSpan.Zero;
var totalWorkedTime = TimeSpan.Zero;
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/WorkItemChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public double CalculateTotalWorkedTime()
}

#region Private Methods
private TimeSpan SubtractDates(DateTime biger, DateTime minor)
private static TimeSpan SubtractDates(DateTime biger, DateTime minor)
{
if (biger.Hour == minor.Hour)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Integrations/DiscordIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Field
public bool IsInline { get; set; }
}

private IEnumerable<Field> GetText(ChangeLog changeLog)
private static IEnumerable<Field> GetText(ChangeLog changeLog)
{
var changeLogItemsAgrupado = changeLog.ChangeLogItems.GroupBy(d => d.WorkItemType);

Expand Down
20 changes: 9 additions & 11 deletions src/Integrations/MessageIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,46 @@ public abstract class MessageIntegration
private static readonly string MEGAFONE_GIF = "megafone.gif";
private static readonly string LOGO_TYPINGHARD_16X16 = "logo-typinghard-16x16.png";

protected internal string GetTitle()
protected internal static string GetTitle()
{
return $"Nova atualização da plataforma";
}

protected internal string GetVersion(ChangeLog changeLog)
protected internal static string GetVersion(ChangeLog changeLog)
{
return $"Versão: {changeLog.Number}";
}

protected internal string GetAnnouncementImageUrl()
protected internal static string GetAnnouncementImageUrl()
{
return $"{CDN_URL}{MEGAFONE_GIF}";
}

protected internal string GetLogoTypingHard16x16Url()
protected internal static string GetLogoTypingHard16x16Url()
{
return $"{CDN_URL}{LOGO_TYPINGHARD_16X16}";
}

protected internal string GetFileVersion()
protected internal static string GetFileVersion()
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
return fileVersionInfo.FileVersion;
}

protected internal string GetNugetVersion()
protected internal static string GetNugetVersion()
{
return $"Powered by **Typing Hard** • nuget version {GetFileVersion()}";
}

protected internal HttpResponseMessage Notify(object body)
protected internal static HttpResponseMessage Notify(object body)
{
var json = Newtonsoft.Json.JsonConvert.SerializeObject(body);
var content = new StringContent(json,
Encoding.UTF8,
MIMETYPE);
HttpClient client = new HttpClient();
return client.PostAsync(new Uri(MessageConfig.URL),
content).Result;

using HttpClient client = new();
return client.PostAsync(new Uri(MessageConfig.URL), content).Result;
}
}
}
10 changes: 5 additions & 5 deletions src/Integrations/MicrosoftTeamsIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal override void Send(ChangeLog changeLog)
Notify(values);
}

private string GetText(ChangeLog changeLog)
private static string GetText(ChangeLog changeLog)
{
if (changeLog is null || !changeLog.ChangeLogItems.Any()) return string.Empty;

Expand All @@ -74,7 +74,7 @@ private string GetText(ChangeLog changeLog)
return text.ToString();
}

private string GetWorkItemsDescriptionSection(string sectionName, IEnumerable<ChangeLogItem> changeLogItems)
private static string GetWorkItemsDescriptionSection(string sectionName, IEnumerable<ChangeLogItem> changeLogItems)
{
StringBuilder text = new();
if (!changeLogItems.Any()) return string.Empty;
Expand All @@ -87,18 +87,18 @@ private string GetWorkItemsDescriptionSection(string sectionName, IEnumerable<Ch
return text.ToString();
}

private string GetWorkItemDescriptionLine(ChangeLogItem workItem)
private static string GetWorkItemDescriptionLine(ChangeLogItem workItem)
{
var description = GetDescription(workItem.Description);
return $"<em>**{workItem.WorkItemId}**</em> - {description} <br>";
}

private string GetDescription(string description)
private static string GetDescription(string description)
{
return description.Replace("<div>", "").Replace("</div>", "").Replace("<br>", "");
}

private string GetFooter()
private static string GetFooter()
{
return $"<br><sup> <img style='width: 16px; height: 16px;' src='{GetLogoTypingHard16x16Url()}' /> {GetNugetVersion()}</sup>";
}
Expand Down
5 changes: 3 additions & 2 deletions src/Interfaces/IChangeLogService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using AzureDevopsTracker.Entities;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Interfaces
{
public interface IChangeLogService
{
int CountItemsForRelease();
ChangeLog Release();
Task<int> CountItemsForRelease();
Task<ChangeLog> Release();
string SendToMessengers(ChangeLog changeLog);
}
}
5 changes: 3 additions & 2 deletions src/Interfaces/Internals/IChangeLogItemRepository.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using AzureDevopsTracker.Entities;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Interfaces.Internals
{
public interface IChangeLogItemRepository : IRepository<ChangeLogItem>
{
int CountItemsForRelease();
IEnumerable<ChangeLogItem> ListWaitingForRelease();
Task<int> CountItemsForRelease();
Task<IEnumerable<ChangeLogItem>> ListWaitingForRelease();
}
}
3 changes: 2 additions & 1 deletion src/Interfaces/Internals/IChangeLogRepository.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using AzureDevopsTracker.Entities;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Interfaces.Internals
{
public interface IChangeLogRepository : IRepository<ChangeLog>
{
int CountChangeLogsCreatedToday();
Task<int> CountChangeLogsCreatedToday();
}
}
20 changes: 10 additions & 10 deletions src/Services/AzureDevopsTrackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task Create(CreateWorkItemDto create, bool addWorkItemChange = true
if (addWorkItemChange)
AddWorkItemChange(workItem, create);

CheckWorkItemAvailableToChangeLog(workItem, create.Resource.Fields);
await CheckWorkItemAvailableToChangeLog(workItem, create.Resource.Fields);

AddCustomFields(workItem);

Expand Down Expand Up @@ -104,7 +104,7 @@ public async Task Update(UpdatedWorkItemDto update)

AddWorkItemChange(workItem, update);

CheckWorkItemAvailableToChangeLog(workItem, update.Resource.Revision.Fields);
await CheckWorkItemAvailableToChangeLog(workItem, update.Resource.Revision.Fields);

AddCustomFields(workItem);

Expand Down Expand Up @@ -218,15 +218,15 @@ public string GetRequestBody()
return corpo;
}

public WorkItemChange ToWorkItemChange(
public static WorkItemChange ToWorkItemChange(
string workItemId, string changedBy,
string iterationPath, DateTime newDate, string newState,
string oldState = null, DateTime? oldDate = null)
{
return new WorkItemChange(workItemId, changedBy.ExtractEmail(), iterationPath, newDate, newState, oldState, oldDate);
}

public void AddWorkItemChange(WorkItem workItem, CreateWorkItemDto create)
public static void AddWorkItemChange(WorkItem workItem, CreateWorkItemDto create)
{
var workItemChange = ToWorkItemChange(workItem.Id,
create.Resource.Fields.ChangedBy,
Expand Down Expand Up @@ -275,13 +275,13 @@ public void RemoveTimeByStateFromDataBase(WorkItem workItem)
_workItemRepository.RemoveAllTimeByState(workItem.TimeByStates.ToList());
}

public void CheckWorkItemAvailableToChangeLog(WorkItem workItem, Fields fields)
public async Task CheckWorkItemAvailableToChangeLog(WorkItem workItem, Fields fields)
{
if (workItem.CurrentStatus != "Closed" &&
workItem.LastStatus == "Closed" &&
workItem.ChangeLogItem is not null &&
!workItem.ChangeLogItem.WasReleased)
RemoveChangeLogItem(workItem);
await RemoveChangeLogItem(workItem);

if (workItem.CurrentStatus != "Closed" ||
fields.ChangeLogDescription.IsNullOrEmpty())
Expand All @@ -293,7 +293,7 @@ workItem.ChangeLogItem is not null &&
workItem.ChangeLogItem.Update(workItem.Title, workItem.Type, fields.ChangeLogDescription);
}

public bool CheckWorkItemChangeExists(WorkItem workItem, WorkItemChange newWorkItemChange)
public static bool CheckWorkItemChangeExists(WorkItem workItem, WorkItemChange newWorkItemChange)
{
return workItem.WorkItemsChanges.Any(x => x.NewDate == newWorkItemChange.NewDate &&
x.OldDate == newWorkItemChange.OldDate &&
Expand All @@ -304,18 +304,18 @@ public bool CheckWorkItemChangeExists(WorkItem workItem, WorkItemChange newWorkI
x.TotalWorkedTime == newWorkItemChange.TotalWorkedTime);
}

public ChangeLogItem ToChangeLogItem(WorkItem workItem, Fields fields)
public static ChangeLogItem ToChangeLogItem(WorkItem workItem, Fields fields)
{
return new ChangeLogItem(workItem.Id, workItem.Title, fields.ChangeLogDescription, workItem.Type);
}

public void RemoveChangeLogItem(WorkItem workItem)
public async Task RemoveChangeLogItem(WorkItem workItem)
{
var changeLogItem = _changeLogItemRepository.GetById(workItem.ChangeLogItem?.Id).Result;
if (changeLogItem is not null)
{
_changeLogItemRepository.Delete(changeLogItem);
_changeLogItemRepository.SaveChangesAsync().Wait();
await _changeLogItemRepository.SaveChangesAsync();

workItem.RemoveChangeLogItem();
}
Expand Down
Loading