Skip to content

Commit

Permalink
Update Meziantou.Analyzer (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored May 1, 2023
1 parent 37e07f3 commit 8724974
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<!-- Assembly Info -->
<Company>Ubisoft</Company>
Expand Down Expand Up @@ -42,7 +42,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Meziantou.Analyzer" Version="2.0.36">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.45">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock.Tests/NGitLab.Mock.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions NGitLab.Mock/Clients/MergeRequestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ public void Delete(int mergeRequestIid)

if (query.CreatedAfter != null)
{
mergeRequests = mergeRequests.Where(mr => mr.CreatedAt >= query.CreatedAfter.Value);
mergeRequests = mergeRequests.Where(mr => mr.CreatedAt >= query.CreatedAfter.Value.ToDateTimeOffsetAssumeUtc());
}

if (query.CreatedBefore != null)
{
mergeRequests = mergeRequests.Where(mr => mr.CreatedAt <= query.CreatedBefore.Value);
mergeRequests = mergeRequests.Where(mr => mr.CreatedAt <= query.CreatedBefore.Value.ToDateTimeOffsetAssumeUtc());
}

if (!string.IsNullOrEmpty(query.Labels))
Expand Down Expand Up @@ -473,12 +473,12 @@ public void Delete(int mergeRequestIid)

if (query.UpdatedAfter != null)
{
mergeRequests = mergeRequests.Where(mr => mr.UpdatedAt >= query.UpdatedAfter.Value);
mergeRequests = mergeRequests.Where(mr => mr.UpdatedAt >= query.UpdatedAfter.Value.ToDateTimeOffsetAssumeUtc());
}

if (query.UpdatedBefore != null)
{
mergeRequests = mergeRequests.Where(mr => mr.UpdatedAt <= query.UpdatedBefore);
mergeRequests = mergeRequests.Where(mr => mr.UpdatedAt <= query.UpdatedBefore.Value.ToDateTimeOffsetAssumeUtc());
}

if (query.State != null)
Expand Down
12 changes: 6 additions & 6 deletions NGitLab.Mock/Config/GitLabHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ private static void CreateIssue(GitLabServer server, Project project, GitLabIssu
Author = new UserRef(GetOrCreateUser(server, issueAuthor)),
Assignees = string.IsNullOrEmpty(issueAssignee) ? Array.Empty<UserRef>() : issueAssignee.Split(',').Select(a => new UserRef(GetOrCreateUser(server, a.Trim()))).ToArray(),
Milestone = string.IsNullOrEmpty(issue.Milestone) ? null : GetOrCreateMilestone(project, issue.Milestone),
UpdatedAt = updatedAt,
UpdatedAt = updatedAt.ToDateTimeOffsetAssumeUtc(),
ClosedAt = issue.ClosedAt,
};

Expand Down Expand Up @@ -1341,8 +1341,8 @@ private static void CreateMergeRequest(GitLabServer server, Project project, Git
Assignees = string.IsNullOrEmpty(mergeRequestAssignee) ? Array.Empty<UserRef>() : mergeRequestAssignee.Split(',').Select(a => new UserRef(GetOrCreateUser(server, a.Trim()))).ToArray(),
SourceBranch = mergeRequest.SourceBranch ?? Guid.NewGuid().ToString("D"),
TargetBranch = mergeRequest.TargetBranch ?? server.DefaultBranchName,
CreatedAt = createdAt,
UpdatedAt = updatedAt,
CreatedAt = createdAt.ToDateTimeOffsetAssumeUtc(),
UpdatedAt = updatedAt.ToDateTimeOffsetAssumeUtc(),
ClosedAt = mergeRequest.ClosedAt,
MergedAt = mergeRequest.MergedAt,
SourceProject = project,
Expand Down Expand Up @@ -1375,7 +1375,7 @@ private static void CreateMergeRequest(GitLabServer server, Project project, Git
.DefaultIfEmpty(updatedAt)
.Min();

CreateComment(server, request, comment, maxCommentCreatedAt);
CreateComment(server, request, comment, maxCommentCreatedAt.ToDateTimeOffsetAssumeUtc());
}

project.MergeRequests.Add(request);
Expand Down Expand Up @@ -1509,9 +1509,9 @@ private static Pipeline CreatePipeline(GitLabServer server, Mock.GitLabObject pa
else if (statuses.Contains(JobStatus.Failed))
ppl.Status = JobStatus.Failed;

ppl.CreatedAt = jobs.Select(x => x.CreatedAt).DefaultIfEmpty(DateTime.UtcNow).Min();
ppl.CreatedAt = jobs.Select(x => x.CreatedAt).DefaultIfEmpty(DateTime.UtcNow).Min().ToDateTimeOffsetAssumeUtc();
var dateTimes = jobs.Where(x => x.StartedAt != default).Select(x => x.StartedAt).ToArray();
ppl.StartedAt = dateTimes.Length == 0 ? null : dateTimes.Min();
ppl.StartedAt = dateTimes.Length == 0 ? null : dateTimes.Min().ToDateTimeOffsetAssumeUtc();
ppl.FinishedAt = jobs.Any(x => x.Status is JobStatus.Created or JobStatus.Pending or JobStatus.Preparing or JobStatus.WaitingForResource or JobStatus.Running)
? null
: jobs.Where(x => x.FinishedAt != default).Select(x => (DateTimeOffset)x.FinishedAt).DefaultIfEmpty(ppl.CreatedAt).Max();
Expand Down
15 changes: 15 additions & 0 deletions NGitLab.Mock/Internals/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace NGitLab.Mock
{
internal static class DateTimeExtensions
{
public static DateTimeOffset ToDateTimeOffsetAssumeUtc(this DateTime dateTime)
{
if (dateTime.Kind == DateTimeKind.Unspecified)
return new DateTimeOffset(dateTime, TimeSpan.Zero);

return new DateTimeOffset(dateTime);
}
}
}
1 change: 0 additions & 1 deletion NGitLab.Tests/FilesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text;
using System.Threading.Tasks;
using NGitLab.Models;
using NGitLab.Tests.Docker;
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Tests/ProjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public async Task GetProjectsByLastActivity()
var project = context.CreateProject();
var projectClient = context.Client.Projects;

var date = DateTime.UtcNow.AddMonths(-1);
var date = DateTimeOffset.UtcNow.AddMonths(-1);
var query = new ProjectQuery
{
LastActivityAfter = date,
Expand All @@ -386,7 +386,7 @@ public async Task GetProjectsByLastActivity()

var projects = projectClient.Get(query).Take(10).ToList();
CollectionAssert.IsNotEmpty(projects);
Assert.That(projects.Select(p => p.LastActivityAt), Is.All.GreaterThan(date));
Assert.That(projects.Select(p => p.LastActivityAt), Is.All.GreaterThan(date.UtcDateTime));
}

[Test]
Expand Down

0 comments on commit 8724974

Please sign in to comment.