Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #529 from kysect/feat/style-cop
Browse files Browse the repository at this point in the history
Wild StyleCop appeared!
  • Loading branch information
xrem authored Jan 4, 2023
2 parents d9d0f24 + f62e9e1 commit 0ceade2
Show file tree
Hide file tree
Showing 155 changed files with 604 additions and 359 deletions.
1 change: 1 addition & 0 deletions Source/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dotnet_diagnostic.IDE0001.severity = warning
dotnet_diagnostic.IDE0002.severity = warning

# IDE0003 and IDE0009
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.IDE0003.severity = warning
dotnet_diagnostic.IDE0009.severity = warning
dotnet_style_qualification_for_field = false:warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public interface ITableUpdateQueue
{
void EnqueueSubmissionsQueueUpdate(Guid subjectCourseId, Guid studentGroupId);

void EnqueueCoursePointsUpdate(Guid subjectCourseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public QueryParameter(T type, string pattern)
}

public T Type { get; set; }

public string Pattern { get; set; }

public void Deconstruct(out T type, out string pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public StudyGroupDto(Guid id, string name)
}

public Guid Id { get; set; }

public string Name { get; set; }

public void Deconstruct(out Guid id, out string name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
namespace Kysect.Shreks.Application.GithubWorkflow.Abstractions;

public interface ISubjectCourseGithubOrganizationManager
{
Task UpdateOrganizations(CancellationToken cancellationToken);
}

public interface ISubjectCourseGithubOrganizationInviteSender
{
Task Invite(string organizationName, IReadOnlyCollection<string> usernames);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Kysect.Shreks.Application.GithubWorkflow.Abstractions;

public interface ISubjectCourseGithubOrganizationManager
{
Task UpdateOrganizations(CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public interface ISubjectCourseGithubOrganizationRepositoryManager
{
Task<IReadOnlyCollection<string>> GetRepositories(string organization);

Task CreateRepositoryFromTemplate(string organization, string newRepositoryName, string templateName);

Task AddAdminPermission(string organization, string repositoryName, string username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Domain\Kysect.Shreks.Common\Kysect.Shreks.Common.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.Application.Dto\Kysect.Shreks.Application.Dto.csproj"/>
<ProjectReference Include="..\..\Domain\Kysect.Shreks.Common\Kysect.Shreks.Common.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.Dto\Kysect.Shreks.Application.Dto.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Octokit"/>
<PackageReference Include="Octokit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace Kysect.Shreks.Application.GithubWorkflow.Abstractions.Models;
public class TestEnvironmentConfiguration
{
public string Organization { get; init; } = string.Empty;

public string TemplateRepository { get; init; } = string.Empty;

public IReadOnlyList<string> Users { get; init; } = new List<string>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ public async Task<Submission> CreateAsync(Guid userId, Guid assignmentId, Cancel
.WithSpecification(studentAssignmentSubmissionsSpec)
.CountAsync(cancellationToken);

return new GithubSubmission
(
return new GithubSubmission(
count + 1,
student,
groupAssignment,
Calendar.CurrentDateTime,
_payload,
_organizationName,
_repositoryName,
_pullRequestNumber
);
_pullRequestNumber);
}

private async Task<Student> FindStudentByRepositoryName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public async Task UpdateOrganizations(CancellationToken cancellationToken)
await _context.SubjectCourses.GetAllGithubUsers(subjectAssociation.SubjectCourse.Id);
var usernames = githubUserAssociations.Select(a => a.GithubUsername).ToList();
await _inviteSender.Invite(subjectAssociation.GithubOrganizationName, usernames);
await GenerateRepositories(_repositoryManager, usernames, subjectAssociation.GithubOrganizationName,
await GenerateRepositories(
_repositoryManager,
usernames,
subjectAssociation.GithubOrganizationName,
subjectAssociation.TemplateRepositoryName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public Task<string> GetSubjectCourseTableId(Guid subjectCourseId, CancellationTo
if (spreadsheetAssociation is not null)
return spreadsheetAssociation.SpreadsheetId;

_logger.LogInformation("Spreadsheet of course {SubjectCourseId} was not found and will be created.",
_logger.LogInformation(
"Spreadsheet of course {SubjectCourseId} was not found and will be created",
subjectCourseId);

SubjectCourse subjectCourse = await _context.SubjectCourses.GetByIdAsync(id, cancellationToken);
Expand All @@ -52,7 +53,9 @@ public Task<string> GetSubjectCourseTableId(Guid subjectCourseId, CancellationTo
_context.SubjectCourseAssociations.Add(spreadsheetAssociation);

await _context.SaveChangesAsync(cancellationToken);
_logger.LogInformation("Successfully created spreadsheet of course {SubjectCourseId}.", subjectCourseId);
_logger.LogInformation(
"Successfully created spreadsheet of course {SubjectCourseId}",
subjectCourseId);

_tableIdCache.TryRemove(id, out _);
return spreadsheetId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public TableUpdateQueue()
PointsUpdateSubjectCourseIds = new ConcurrentHashSet<Guid>();
}

public ConcurrentHashSet<(Guid, Guid)> QueueUpdateSubjectCourseGroupIds { get; }
public ConcurrentHashSet<(Guid SubjectCourseId, Guid StudentGroupId)> QueueUpdateSubjectCourseGroupIds { get; }

public ConcurrentHashSet<Guid> PointsUpdateSubjectCourseIds { get; }

public void EnqueueSubmissionsQueueUpdate(Guid subjectCourseId, Guid studentGroupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public CreateGithubSubmissionHandler(IShreksDatabaseContext context)

public async Task<Response> Handle(Command request, CancellationToken cancellationToken)
{
var factory = new GithubSubmissionFactory
(
var factory = new GithubSubmissionFactory(
_context,
request.OrganizationName,
request.RepositoryName,
request.PullRequestNumber,
request.Payload
);
request.Payload);

Submission submission = await factory.CreateAsync(
request.IssuerId, request.AssignmentId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
ISubmissionWorkflow workflow = await _submissionWorkflowService.GetSubjectCourseWorkflowAsync(
subjectCourse.Id, cancellationToken);

var submissionFactory = new GithubSubmissionFactory
(
var submissionFactory = new GithubSubmissionFactory(
_context,
request.OrganizationName,
request.RepositoryName,
request.PullRequestNumber,
request.Payload
);
request.Payload);

SubmissionUpdateResult result = await workflow.SubmissionUpdatedAsync(
request.IssuerId, request.UserId, request.AssignmentId, submissionFactory, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public async Task Handle(
}
catch (Exception e)
{
_logger.LogError(e, "Error while updating queue for subject course {SubjectCourseId} group {GroupId}",
notification.SubjectCourseId, notification.GroupId);
_logger.LogError(
e,
"Error while updating queue for subject course {SubjectCourseId} group {GroupId}",
notification.SubjectCourseId,
notification.GroupId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public async Task Handle(SubjectCoursePointsUpdatedNotification notification, Ca
}
catch (Exception e)
{
_logger.LogError(e, "Error updating course points for subject course {SubjectCourseId}",
_logger.LogError(
e,
"Error updating course points for subject course {SubjectCourseId}",
notification.SubjectCourseId);
}
}
Expand All @@ -46,7 +48,8 @@ private async Task ExecuteAsync(
SubjectCoursePointsUpdatedNotification notification,
CancellationToken cancellationToken)
{
_logger.LogInformation("Start updating for points sheet of course {SubjectCourseId}.",
_logger.LogInformation(
"Start updating for points sheet of course {SubjectCourseId}.",
notification.SubjectCourseId);

_logger.LogInformation("Started to collecting all course {courseId} points", notification.SubjectCourseId);
Expand All @@ -69,8 +72,12 @@ private async Task ExecuteAsync(

foreach ((StudentPointsDto student, AssignmentPointsDto studentPoints, AssignmentDto assignment) in table)
{
_logger.LogTrace("\t{Student} - {Assignment}: {Points}, banned: {Banned}",
student.Student.GitHubUsername, assignment.Title, studentPoints.Points, studentPoints.IsBanned);
_logger.LogTrace(
"\t{Student} - {Assignment}: {Points}, banned: {Banned}",
student.Student.GitHubUsername,
assignment.Title,
studentPoints.Points,
studentPoints.IsBanned);
}
}

Expand All @@ -79,7 +86,8 @@ private async Task ExecuteAsync(

await _sheet.UpdateAsync(spreadsheetId, points, cancellationToken);

_logger.LogInformation("Successfully updated points sheet of course {SubjectCourseId}.",
_logger.LogInformation(
"Successfully updated points sheet of course {SubjectCourseId}",
notification.SubjectCourseId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,22 @@ public async Task<Response> Handle(Query request, CancellationToken cancellation
JwtSecurityToken token = GetToken(claims);
string? tokenString = new JwtSecurityTokenHandler().WriteToken(token);

return new Response
(
return new Response(
tokenString,
token.ValidTo,
new ReadOnlyCollection<string>(roles)
);
new ReadOnlyCollection<string>(roles));
}

private JwtSecurityToken GetToken(IEnumerable<Claim> authClaims)
{
var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration.Secret));

var token = new JwtSecurityToken
(
var token = new JwtSecurityToken(
_configuration.Issuer,
_configuration.Audience,
expires: DateTime.UtcNow.AddHours(_configuration.ExpiresHours),
claims: authClaims,
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
);
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256));

return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\Kysect.Shreks.Identity\Kysect.Shreks.Identity.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.Application.GithubWorkflow.Abstractions\Kysect.Shreks.Application.GithubWorkflow.Abstractions.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.Application.Contracts\Kysect.Shreks.Application.Contracts.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.Application.GithubWorkflow\Kysect.Shreks.Application.GithubWorkflow.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.Application\Kysect.Shreks.Application.csproj"/>
<ProjectReference Include="..\Kysect.Shreks.DataAccess.Abstractions\Kysect.Shreks.DataAccess.Abstractions.csproj"/>
<ProjectReference Include="..\..\Infrastructure\Kysect.Shreks.Identity\Kysect.Shreks.Identity.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.GithubWorkflow.Abstractions\Kysect.Shreks.Application.GithubWorkflow.Abstractions.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.Contracts\Kysect.Shreks.Application.Contracts.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application.GithubWorkflow\Kysect.Shreks.Application.GithubWorkflow.csproj" />
<ProjectReference Include="..\Kysect.Shreks.Application\Kysect.Shreks.Application.csproj" />
<ProjectReference Include="..\Kysect.Shreks.DataAccess.Abstractions\Kysect.Shreks.DataAccess.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper"/>
<PackageReference Include="Kysect.CommonLib"/>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection"/>
<PackageReference Include="AutoMapper" />
<PackageReference Include="Kysect.CommonLib" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Kysect.Shreks.Tests.Handlers"/>
<InternalsVisibleTo Include="Kysect.Shreks.Tests.Handlers" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
request.Order,
new Points(request.MinPoints),
new Points(request.MaxPoints),
subjectCourse
);
subjectCourse);

_context.Assignments.Add(assignment);
await _context.SaveChangesAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
await _context.UserAssociations.AddAsync(association, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);


UserDto? dto = _mapper.Map<UserDto>(user);

return new Response(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ namespace Kysect.Shreks.Application.Extensions;

public static class EnumerableExtensions
{
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable) where T : class
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable)
where T : class
{
return enumerable.Where(x => x is not null).Select(x => x!);
}

public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable) where T : struct
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable)
where T : struct
{
return enumerable.Where(x => x is not null).Select(x => x!.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public static SubjectCourseDto CreateFrom(SubjectCourse subjectCourse)
case GithubSubjectCourseAssociation githubSubjectCourseAssociation:
string githubValue =
$"Repo: {githubSubjectCourseAssociation.GithubOrganizationName}, Template: {githubSubjectCourseAssociation.TemplateRepositoryName}";
associations.Add(new SubjectCourseAssociationDto(nameof(GithubSubjectCourseAssociation),
associations.Add(new SubjectCourseAssociationDto(
nameof(GithubSubjectCourseAssociation),
githubValue));
break;

case GoogleTableSubjectCourseAssociation googleTableSubjectCourseAssociation:
string googleValue = $"SpreadsheetId: {googleTableSubjectCourseAssociation.SpreadsheetId}";
associations.Add(new SubjectCourseAssociationDto(nameof(GoogleTableSubjectCourseAssociation),
associations.Add(new SubjectCourseAssociationDto(
nameof(GoogleTableSubjectCourseAssociation),
googleValue));
break;

Expand All @@ -38,7 +40,11 @@ public static SubjectCourseDto CreateFrom(SubjectCourse subjectCourse)
? (SubmissionStateWorkflowTypeDto)subjectCourse.WorkflowType
: null;

return new SubjectCourseDto(subjectCourse.Id, subjectCourse.Subject.Id, subjectCourse.Title, workflowType,
return new SubjectCourseDto(
subjectCourse.Id,
subjectCourse.Subject.Id,
subjectCourse.Title,
workflowType,
associations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static SubmissionRateDto CreateFromSubmission(Submission submission)
if (submission.Rating is not null)
rating = submission.Rating * 100;

var dto = new SubmissionRateDto
(
var dto = new SubmissionRateDto(
submission.Code,
submission.State.Kind.ToString(),
submission.SubmissionDate.Value,
Expand All @@ -26,8 +25,7 @@ public static SubmissionRateDto CreateFromSubmission(Submission submission)
maxRowPoints.Value,
submission.ExtraPoints?.Value,
submission.PointPenalty?.Value,
submission.EffectivePoints?.Value
);
submission.EffectivePoints?.Value);

return dto;
}
Expand Down
Loading

0 comments on commit 0ceade2

Please sign in to comment.