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
20 changes: 10 additions & 10 deletions src/AzureDevopsTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>AzureDevOpsTracker</PackageId>
<Authors>Elvis Souza | Diego Galante</Authors>
<Company>TypingHard</Company>
Expand All @@ -18,25 +18,25 @@
<PackageLicenseFile>LICENSE.md.txt</PackageLicenseFile>
<Description>A NuGet that allows you to use a Azure DevOps Service Hook to track workitems changes in a simply and detailed way.</Description>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.5</FileVersion>
<Version>5.0.5</Version>
<FileVersion>5.0.6</FileVersion>
<Version>5.0.6</Version>
<PackageReleaseNotes>Add ChangeLog Feature</PackageReleaseNotes>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>

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

<ItemGroup>
<None Update="adt_icon.png">
<Pack>True</Pack>
Expand Down
17 changes: 16 additions & 1 deletion src/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;

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));

try
{
using var serviceScope = services.BuildServiceProvider().CreateScope();
var dbContext = serviceScope.ServiceProvider.GetRequiredService<AzureDevopsTrackerContext>();

var pendingMigrations = dbContext.Database.GetPendingMigrations();
if (pendingMigrations.Any())
dbContext.Database.Migrate();
}
catch
{ }

services.AddMessageIntegrations();

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
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);
}
}
}
1 change: 1 addition & 0 deletions src/Data/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Data
Expand Down
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
7 changes: 4 additions & 3 deletions src/Integrations/DiscordIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Integrations
{
internal class DiscordIntegration : MessageIntegration
{
internal override void Send(ChangeLog changeLog)
internal override async Task Send(ChangeLog changeLog)
{
var embedsDTO = new EmbedsDTO
{
Expand All @@ -26,7 +27,7 @@ internal override void Send(ChangeLog changeLog)
},
};

Notify(embedsDTO);
await Notify(embedsDTO);
}

public class EmbedsDTO
Expand Down Expand Up @@ -97,7 +98,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
3 changes: 2 additions & 1 deletion src/Integrations/FakeIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using AzureDevopsTracker.Entities;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Integrations
{
internal class FakeIntegration : MessageIntegration
{
internal override void Send(ChangeLog changeLog) { }
internal override async Task Send(ChangeLog changeLog) { }
}
}
5 changes: 3 additions & 2 deletions src/Integrations/MessageFacade.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AzureDevopsTracker.Entities;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Integrations
{
Expand All @@ -14,14 +15,14 @@ public MessageFacade(
_serviceScopeFactory = serviceScopeFactory;
}

public void Send(ChangeLog changeLog)
public async Task Send(ChangeLog changeLog)
{
using var scope = _serviceScopeFactory.CreateScope();

var messageIntegration = scope.ServiceProvider.GetService<MessageIntegration>();
if (messageIntegration is null) throw new Exception("Configure the MessageConfig in Startup to send changelog messages");

messageIntegration.Send(changeLog);
await messageIntegration.Send(changeLog);
}
}
}
23 changes: 11 additions & 12 deletions src/Integrations/MessageIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,58 @@
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace AzureDevopsTracker.Integrations
{
public abstract class MessageIntegration
{
internal abstract void Send(ChangeLog changeLog);
internal abstract Task Send(ChangeLog changeLog);
private static readonly string MIMETYPE = "application/json";
private static readonly string CDN_URL = "https://cdn.typinghard.tech/";
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 async Task<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 await client.PostAsync(new Uri(MessageConfig.URL), content);
}
}
}
Loading