Skip to content

Commit f93b086

Browse files
authored
Update (#20)
* Update
1 parent b375201 commit f93b086

20 files changed

+119
-91
lines changed

src/Adapters/WorkItemAdapter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public List<WorkItemDto> ToWorkItemsDto(List<WorkItem> workItems)
5151
.ToList();
5252
}
5353

54-
public WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
54+
public static WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
5555
{
5656
if (workIteChange is null) return null;
5757

@@ -65,7 +65,7 @@ public WorkItemChangeDto ToWorkItemChangeDto(WorkItemChange workIteChange)
6565
};
6666
}
6767

68-
public List<WorkItemChangeDto> ToWorkItemsChangeDto(List<WorkItemChange> workItemsChanges)
68+
public static List<WorkItemChangeDto> ToWorkItemsChangeDto(List<WorkItemChange> workItemsChanges)
6969
{
7070
var workItemsChangeDto = new List<WorkItemChangeDto>();
7171

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

83-
public TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
83+
public static TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
8484
{
8585
if (workItemStatusTime is null) return null;
8686

@@ -93,7 +93,7 @@ public TimeByStateDto ToTimeByStateDto(TimeByState workItemStatusTime)
9393
};
9494
}
9595

96-
public List<TimeByStateDto> ToTimeByStatesDto(List<TimeByState> workItemStatusTimes)
96+
public static List<TimeByStateDto> ToTimeByStatesDto(List<TimeByState> workItemStatusTimes)
9797
{
9898
var workItemStatusTimeDto = new List<TimeByStateDto>();
9999

src/AzureDevopsTracker.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
5-
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
5+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
66
<PackageId>AzureDevOpsTracker</PackageId>
77
<Authors>Elvis Souza | Diego Galante</Authors>
88
<Company>TypingHard</Company>
@@ -18,25 +18,25 @@
1818
<PackageLicenseFile>LICENSE.md.txt</PackageLicenseFile>
1919
<Description>A NuGet that allows you to use a Azure DevOps Service Hook to track workitems changes in a simply and detailed way.</Description>
2020
<AssemblyVersion>5.0.0.0</AssemblyVersion>
21-
<FileVersion>5.0.5</FileVersion>
22-
<Version>5.0.5</Version>
21+
<FileVersion>5.0.6</FileVersion>
22+
<Version>5.0.6</Version>
2323
<PackageReleaseNotes>Add ChangeLog Feature</PackageReleaseNotes>
2424
</PropertyGroup>
2525

26+
<ItemGroup>
27+
<None Include="../LICENSE.md.txt">
28+
<Pack>True</Pack>
29+
<PackagePath></PackagePath>
30+
</None>
31+
</ItemGroup>
32+
2633
<ItemGroup>
2734
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
2835
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
2936
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
3037
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
3138
</ItemGroup>
3239

33-
<ItemGroup>
34-
<None Include="LICENSE.md.txt">
35-
<Pack>True</Pack>
36-
<PackagePath></PackagePath>
37-
</None>
38-
</ItemGroup>
39-
4040
<ItemGroup>
4141
<None Update="adt_icon.png">
4242
<Pack>True</Pack>

src/Configurations/Configuration.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,31 @@
1010
using Microsoft.EntityFrameworkCore;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using System;
13+
using System.Linq;
1314

1415
namespace AzureDevopsTracker.Configurations
1516
{
1617
public static class Configuration
1718
{
18-
public static IServiceCollection AddAzureDevopsTracker(this IServiceCollection services, DataBaseConfig configurations, MessageConfig messageConfig = null)
19+
public static IServiceCollection AddAzureDevopsTracker(this IServiceCollection services,
20+
DataBaseConfig configurations,
21+
MessageConfig messageConfig = null)
1922
{
2023
services.AddDbContext<AzureDevopsTrackerContext>(options =>
2124
options.UseSqlServer(DataBaseConfig.ConnectionsString));
2225

26+
try
27+
{
28+
using var serviceScope = services.BuildServiceProvider().CreateScope();
29+
var dbContext = serviceScope.ServiceProvider.GetRequiredService<AzureDevopsTrackerContext>();
30+
31+
var pendingMigrations = dbContext.Database.GetPendingMigrations();
32+
if (pendingMigrations.Any())
33+
dbContext.Database.Migrate();
34+
}
35+
catch
36+
{ }
37+
2338
services.AddMessageIntegrations();
2439

2540
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
using AzureDevopsTracker.Data.Context;
22
using AzureDevopsTracker.Entities;
33
using AzureDevopsTracker.Interfaces.Internals;
4+
using Microsoft.EntityFrameworkCore;
45
using System.Collections.Generic;
56
using System.Linq;
7+
using System.Threading.Tasks;
68

79
namespace AzureDevopsTracker.Data
810
{
911
internal class ChangeLogItemRepository : Repository<ChangeLogItem>, IChangeLogItemRepository
1012
{
1113
public ChangeLogItemRepository(AzureDevopsTrackerContext context) : base(context) { }
1214

13-
public int CountItemsForRelease()
15+
public async Task<int> CountItemsForRelease()
1416
{
15-
return DbSet.Count(x => string.IsNullOrEmpty(x.ChangeLogId));
17+
return await DbSet.CountAsync(x => string.IsNullOrEmpty(x.ChangeLogId));
1618
}
1719

18-
public IEnumerable<ChangeLogItem> ListWaitingForRelease()
20+
public async Task<IEnumerable<ChangeLogItem>> ListWaitingForRelease()
1921
{
20-
return DbSet.Where(x => string.IsNullOrEmpty(x.ChangeLogId));
22+
return await DbSet.Where(x => string.IsNullOrEmpty(x.ChangeLogId)).ToListAsync();
2123
}
2224
}
2325
}

src/Data/ChangeLogRepository.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using AzureDevopsTracker.Data.Context;
22
using AzureDevopsTracker.Entities;
33
using AzureDevopsTracker.Interfaces.Internals;
4+
using Microsoft.EntityFrameworkCore;
45
using System;
5-
using System.Linq;
6+
using System.Threading.Tasks;
67

78
namespace AzureDevopsTracker.Data
89
{
910
internal class ChangeLogRepository : Repository<ChangeLog>, IChangeLogRepository
1011
{
1112
public ChangeLogRepository(AzureDevopsTrackerContext context) : base(context) { }
1213

13-
public int CountChangeLogsCreatedToday()
14+
public async Task<int> CountChangeLogsCreatedToday()
1415
{
15-
return DbSet.Count(x => x.CreatedAt.Date == DateTime.Now.Date);
16+
return await DbSet.CountAsync(x => x.CreatedAt.Date == DateTime.Now.Date);
1617
}
1718
}
1819
}

src/Data/Repository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.EntityFrameworkCore;
55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78
using System.Threading.Tasks;
89

910
namespace AzureDevopsTracker.Data

src/Entities/ChangeLogItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ChangeLogItem : Entity
1010
public string Description { get; private set; }
1111
public string WorkItemType { get; private set; }
1212
public string ChangeLogId { get; private set; }
13-
public bool WasReleased => string.IsNullOrEmpty(ChangeLogId?.Trim());
13+
public bool WasReleased => string.IsNullOrWhiteSpace(ChangeLogId);
1414
public ChangeLog ChangeLog { get; private set; }
1515

1616
private ChangeLogItem() { }

src/Entities/WorkItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ public IEnumerable<TimeByState> CalculateTotalTimeByState()
142142
if (!_workItemsChanges.Any())
143143
return timesByStateList;
144144

145-
foreach (var workItemChange in _workItemsChanges.OrderBy(x => x.CreatedAt).GroupBy(x => x.OldState).Where(x => x.Key is not null))
145+
foreach (var workItemChange in _workItemsChanges.OrderBy(x => x.CreatedAt)
146+
.GroupBy(x => x.OldState)
147+
.Where(x => x.Key is not null))
146148
{
147149
var totalTime = TimeSpan.Zero;
148150
var totalWorkedTime = TimeSpan.Zero;

src/Entities/WorkItemChange.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public double CalculateTotalWorkedTime()
139139
}
140140

141141
#region Private Methods
142-
private TimeSpan SubtractDates(DateTime biger, DateTime minor)
142+
private static TimeSpan SubtractDates(DateTime biger, DateTime minor)
143143
{
144144
if (biger.Hour == minor.Hour)
145145
{

src/Integrations/DiscordIntegration.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using System.Threading.Tasks;
89

910
namespace AzureDevopsTracker.Integrations
1011
{
1112
internal class DiscordIntegration : MessageIntegration
1213
{
13-
internal override void Send(ChangeLog changeLog)
14+
internal override async Task Send(ChangeLog changeLog)
1415
{
1516
var embedsDTO = new EmbedsDTO
1617
{
@@ -26,7 +27,7 @@ internal override void Send(ChangeLog changeLog)
2627
},
2728
};
2829

29-
Notify(embedsDTO);
30+
await Notify(embedsDTO);
3031
}
3132

3233
public class EmbedsDTO
@@ -97,7 +98,7 @@ public class Field
9798
public bool IsInline { get; set; }
9899
}
99100

100-
private IEnumerable<Field> GetText(ChangeLog changeLog)
101+
private static IEnumerable<Field> GetText(ChangeLog changeLog)
101102
{
102103
var changeLogItemsAgrupado = changeLog.ChangeLogItems.GroupBy(d => d.WorkItemType);
103104

0 commit comments

Comments
 (0)