Skip to content

Commit

Permalink
Upgrade package Octokit to version 13
Browse files Browse the repository at this point in the history
*Aligns C# API with current GitHub REST interface.
* Fixes bug in client.Repository.PullRequest.ReviewComment.GetAll.
  • Loading branch information
jheinzel committed Jul 15, 2024
1 parent 154dd71 commit 6a5298a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 79 deletions.
10 changes: 2 additions & 8 deletions src/TutorBot.Cli/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@

namespace TutorBot;

public class App
public class App(IServiceProvider serviceProvider)
{
private readonly IServiceProvider serviceProvider;

public App(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}

private readonly IServiceProvider serviceProvider = serviceProvider;

public async Task RunAsync(string[] args)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TutorBot.Cli/Commands/ListReviewStatisticsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private async Task HandleAsync(string assignmentName, string classroomName, stri
progress.Dispose();

var progressStatistics = new ProgressBar("Loading statistics ");
var reviewStats = await assignment.GetReviewStatistics(studentList, progressStatistics);
var reviewStats = await assignment.GetReviewStatistics(progressStatistics);
progressStatistics.Dispose();

var orderedReviewStats =
Expand Down
23 changes: 7 additions & 16 deletions src/TutorBot.Cli/Domain/Assignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@ namespace TutorBot.Domain;

public record AssigmentParameters(long ClassroomId, string AssignmentName, int? Group = null, bool LoadAssessments = false);

public class Assignment
public class Assignment(IGitHubClassroomClient client, string name, DateTimeOffset? deadline, IReadOnlyList<Submission> submissions, IReadOnlyList<UnlinkedSubmission> unlinkedSubmissions)
{
private IGitHubClassroomClient client;
private readonly IGitHubClassroomClient client = client ?? throw new ArgumentNullException(nameof(client));

public string Name { get; init; }
public DateTimeOffset? Deadline { get; init; }
public string Name { get; init; } = name ?? throw new ArgumentNullException(nameof(name));
public DateTimeOffset? Deadline { get; init; } = deadline;

public IReadOnlyList<Submission> Submissions { get; init; }
public IReadOnlyList<Submission> Submissions { get; init; } = submissions ?? throw new ArgumentNullException(nameof(submissions));

public IReadOnlyList<UnlinkedSubmission> UnlinkedSubmissions { get; init; }

public Assignment(IGitHubClassroomClient client, string name, DateTimeOffset? deadline, IReadOnlyList<Submission> submissions, IReadOnlyList<UnlinkedSubmission> unlinkedSubmissions)
{
this.client = client ?? throw new ArgumentNullException(nameof(client));
Name = name ?? throw new ArgumentNullException(nameof(name));
Deadline = deadline;
Submissions = submissions ?? throw new ArgumentNullException(nameof(submissions));
UnlinkedSubmissions = unlinkedSubmissions ?? throw new ArgumentNullException(nameof(unlinkedSubmissions));
}
public IReadOnlyList<UnlinkedSubmission> UnlinkedSubmissions { get; init; } = unlinkedSubmissions ?? throw new ArgumentNullException(nameof(unlinkedSubmissions));

public static async Task<Assignment> FromGitHub(IGitHubClassroomClient client, IStudentList students, AssigmentParameters parameters, IProgress? progress = null)
{
Expand Down Expand Up @@ -145,7 +136,7 @@ public async Task RemoveReviewers(IProgress? progress = null)
}
}

public async Task<ReviewStatistics> GetReviewStatistics(IStudentList students, IProgress? progress = null)
public async Task<ReviewStatistics> GetReviewStatistics(IProgress? progress = null)
{
var reviewStats = new Dictionary<(string Owner, string Reviewer), Domain.ReviewStatisticsItem>();
foreach (var submission in Submissions)
Expand Down
9 changes: 2 additions & 7 deletions src/TutorBot.Cli/Domain/Reviewer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
namespace TutorBot.Domain;

public class Reviewer : Student
public class Reviewer(Student student, long? invitationId = null) : Student(student.GitHubUsername, student.LastName, student.FirstName, student.MatNr, student.GroupNr)
{
public int? InvitationId { get; init; }

public Reviewer(Student student, int? invitationId = null) : base(student.GitHubUsername, student.LastName, student.FirstName, student.MatNr, student.GroupNr)
{
InvitationId = invitationId;
}
public long? InvitationId { get; init; } = invitationId;

public bool IsInvitationPending => InvitationId.HasValue;

Expand Down
24 changes: 6 additions & 18 deletions src/TutorBot.Cli/Domain/Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ namespace TutorBot.Domain;

using ReviewStatistics = IDictionary<(string Owner, string Reviewer), ReviewStatisticsItem>;

public class Submission
public class Submission(IGitHubClassroomClient client, Repository repository, Student owner, IEnumerable<Reviewer> reviewers)
{
private IGitHubClassroomClient client;
private Repository repository;
private readonly IGitHubClassroomClient client = client;
private readonly Repository repository = repository;

public long RepositoryId => repository.Id;
public string RepositoryName => repository.Name;
public string RepositoryFullName => repository.FullName;
public string RepositoryUrl => repository.HtmlUrl;
public Student Owner { get; init; }
public Student Owner { get; init; } = owner;

public IList<Reviewer> Reviewers { get; set; }
public IList<Reviewer> Reviewers { get; set; } = reviewers.ToList();

public Assessment Assessment { get; private set; } = new Assessment();

public Submission(IGitHubClassroomClient client, Repository repository, Student owner, IEnumerable<Reviewer> reviewers)
{
this.client = client;
this.repository = repository;
this.Owner = owner;
this.Reviewers = reviewers.ToList();
}

public async Task AddReviewStatistics(ReviewStatistics reviewStats)
{
var reviews = await client.Repository.PullRequest.Review.GetAll(RepositoryId, Constants.FEEDBACK_PULLREQUEST_ID);
Expand Down Expand Up @@ -67,15 +59,11 @@ public async Task AddReviewStatistics(ReviewStatistics reviewStats)
}
}

public class UnlinkedSubmission
public class UnlinkedSubmission(Repository repository)
{
private Repository repository;

public long RepositoryId => repository.Id;
public string RepositoryName => repository.Name;
public string RepositoryFullName => repository.FullName;
public string RepositoryUrl => repository.HtmlUrl;
public string GitHubUsername => repository.Owner.Login;

public UnlinkedSubmission(Repository repository) => this.repository = repository;
}
2 changes: 1 addition & 1 deletion src/TutorBot.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"gh-tutorbot": {
"commandName": "Project",
"commandLineArgs": "check-plagiarism ue01-debug --language cpp",
"commandLineArgs": "list-review-statistics ue07 --classroom swe4-vz-2024ss",
"workingDirectory": "C:\\Users\\p20058\\Documents\\FH\\Lehre\\Tools\\gh-tutorbot\\test\\swe4-vz-2024ss"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/TutorBot.Cli/TutorBot.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

Expand Down
28 changes: 14 additions & 14 deletions src/TutorBot.Tests/AssignReviewersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public AssignReviewersTests()
client.Repository.Content.Returns(repositoryContentsClient);
}

private void AddContent(IRepositoryContentsClient contentClient, string assessmentString)
private static void AddContent(IRepositoryContentsClient contentClient, string assessmentString)
{
var encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(assessmentString));
RepositoryContent reopContent = new RepositoryContent("", "", "", 0, ContentType.File, "", "", "", "", "", encodedContent, "", "");
contentClient.GetAllContents(Arg.Any<long>(), Arg.Any<string>()).Returns(Task.FromResult<IReadOnlyList<RepositoryContent>>(new List<RepositoryContent> { reopContent }));
RepositoryContent reopContent = new("", "", "", 0, ContentType.File, "", "", "", "", "", encodedContent, "", "");
contentClient.GetAllContents(Arg.Any<long>(), Arg.Any<string>()).Returns(Task.FromResult<IReadOnlyList<RepositoryContent>>([reopContent]));
}

private void AddCollaborator(IRepoCollaboratorsClient collaboratorsClient, Repository repository, string permission)
private static void AddCollaborator(IRepoCollaboratorsClient collaboratorsClient, Repository repository, string permission)
{
var readRequest = new CollaboratorRequest(permission);
var invitation = new RepositoryInvitation(1, "", repository, null, null, InvitationPermissionType.Read, DateTimeOffset.Now, false, "", "");
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task ReviewerAssignment_WithOneSubmission_ShouldHaveNoReviewers()

var submissions = new List<Submission>
{
new Submission(client, repository, students[0], emptyReviewerList)
new(client, repository, students[0], emptyReviewerList)
};
foreach (var s in submissions) await s.Assessment.Load(client, repository.Id);

Expand All @@ -98,8 +98,8 @@ public async Task ReviewerAssignment_WithTwoSubmission_ShouldBeCorrect()

var submissions = new List<Submission>
{
new Submission(client, repository, students[0], emptyReviewerList),
new Submission(client, repository, students[1], emptyReviewerList)
new(client, repository, students[0], emptyReviewerList),
new(client, repository, students[1], emptyReviewerList)
};
foreach (var s in submissions) await s.Assessment.Load(client, repository.Id);

Expand Down Expand Up @@ -152,9 +152,9 @@ public async Task ReviewerAssignment_WithThreeSubmissionsAndOnePreAssignedReview

var submissions = new List<Submission>
{
new Submission(client, repository, students[0], new List<Reviewer> { new Reviewer(students[1]) }),
new Submission(client, repository, students[1], emptyReviewerList),
new Submission(client, repository, students[2], emptyReviewerList)
new(client, repository, students[0], [new Reviewer(students[1])]),
new(client, repository, students[1], emptyReviewerList),
new(client, repository, students[2], emptyReviewerList)
};
foreach (var s in submissions) await s.Assessment.Load(client, repository.Id);

Expand Down Expand Up @@ -192,7 +192,7 @@ public async Task ReviewerAssignment_WithPreAssignedReviewers_ShouldBeCorrect(in
}
else
{
submissions.Add(new Submission(client, repository, students[i], new List<Reviewer> { new Reviewer(students[i - 1]) }));
submissions.Add(new Submission(client, repository, students[i], [new(students[i - 1])]));
}
}
foreach (var s in submissions) await s.Assessment.Load(client, repository.Id);
Expand Down Expand Up @@ -241,12 +241,12 @@ public async Task AssignmentOfProposedReviewers_IsCorrectlyIntegratedIntoSubmiss
ReviewerAssignmentShouldBeCorrect(assignment);
}

private Repository CreateRepository(int id, string repoName)
private static Repository CreateRepository(int id, string repoName)
{
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, [], null, null, null, new());
}

private IList<Student> CreateStudentList(int n)
private static List<Student> CreateStudentList(int n)
{
var students = new List<Student>();
for (int i = 1; i <= n; i++)
Expand Down
26 changes: 13 additions & 13 deletions src/TutorBot.Tests/AssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public AssignmentTests()
collaboratorClient = Substitute.For<IRepoCollaboratorsClient>();
client.Repository.Collaborator.Returns(collaboratorClient);

students = new StudentList(new List<Student>
{
students = new StudentList(
[
new Student("gh-mayr", "Mayr", "Franz", "S2110307001", 1),
new Student("gh-huber", "Huber", "Susi", "S2110307002", 1)
});
]);
}

[Fact]
Expand All @@ -48,8 +48,8 @@ public async Task Submission_WithNoRepository_ThrowsException()
assignmentClient.GetByName(1, "ue01").Returns(
Task.FromResult(new AssignmentDto { Id = 10, Title = "ue01", Accepted = 1, Deadline = DateTime.Now.AddDays(1) }));

var submissionDto1 = new SubmissionDto { Id = 100, Students = new List<StudentDto> { new StudentDto { Id = 1, Login = "gh-mayr" } } };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>(new List<SubmissionDto> { submissionDto1 }));
var submissionDto1 = new SubmissionDto { Id = 100, Students = [new() { Id = 1, Login = "gh-mayr" }] };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>([submissionDto1]));

var parameters = new AssigmentParameters(1, "ue01", LoadAssessments: false);
var fromGitHubAction = async () => await Assignment.FromGitHub(client, students, parameters);
Expand All @@ -67,10 +67,10 @@ public async Task SimpleAssignment_IsLoadedCorrectly()
Task.FromResult(new AssignmentDto { Id = 10, Title = assignmentName, Accepted = 1, Deadline = DateTime.Now.AddDays(1) }));

var studentDto1 = new StudentDto { Id = 1, Login = "gh-mayr" };
var submissionDto1 = new SubmissionDto { Id = 100, Students = new List<StudentDto> { studentDto1 }, Repository = new RepositoryDto { Id = 100 } };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>(new List<SubmissionDto> { submissionDto1 }));
var submissionDto1 = new SubmissionDto { Id = 100, Students = [studentDto1], Repository = new RepositoryDto { Id = 100 } };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>([submissionDto1]));

collaboratorClient.GetAll(100).Returns(Task.FromResult<IReadOnlyList<Collaborator>>(new List<Collaborator> { }));
collaboratorClient.GetAll(100).Returns(Task.FromResult<IReadOnlyList<Collaborator>>([]));

var parameters = new AssigmentParameters(1, "ue01", LoadAssessments: false);
var assignment = await Assignment.FromGitHub(client, students, parameters);
Expand All @@ -96,13 +96,13 @@ public async Task SimpleAssignment_With_Reviewers_IsLoadedCorrectly()
Task.FromResult(new AssignmentDto { Id = 10, Title = assignmentName, Accepted = 1, Deadline = DateTime.Now.AddDays(1) }));

var studentDto1 = new StudentDto { Id = 1, Login = "gh-mayr" };
var submissionDto1 = new SubmissionDto { Id = 100, Students = new List<StudentDto> { studentDto1 }, Repository = new RepositoryDto { Id = 100 } };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>(new List<SubmissionDto> { submissionDto1 }));
var submissionDto1 = new SubmissionDto { Id = 100, Students = [studentDto1], Repository = new RepositoryDto { Id = 100 } };
submissionsClient.GetAll(10).Returns(Task.FromResult<IReadOnlyList<SubmissionDto>>([submissionDto1]));

var reviewerName = "gh-huber";
var permissions1 = new CollaboratorPermissions(pull: false, triage: false, push: false, maintain: false, admin: false);
var collaborator1 = new Collaborator("gh-huber", id: 2, "[email protected]", "Huber", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", false, permissions: permissions1, "read");
collaboratorClient.GetAll(100).Returns(Task.FromResult<IReadOnlyList<Collaborator>>(new List<Collaborator> { collaborator1 }));
collaboratorClient.GetAll(100).Returns(Task.FromResult<IReadOnlyList<Collaborator>>([collaborator1]));

var parameters = new AssigmentParameters(1, "ue01", LoadAssessments: false);
var assignment = await Assignment.FromGitHub(client, students, parameters);
Expand All @@ -118,8 +118,8 @@ public async Task SimpleAssignment_With_Reviewers_IsLoadedCorrectly()
assignment.Submissions[0].Reviewers[0].FirstName.Should().Be(expectedReviewer.FirstName);
}

private Repository CreateRepository(int id, string repoName)
private static Repository CreateRepository(int id, string repoName)
{
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, [], null, null, null, new());
}
}

0 comments on commit 6a5298a

Please sign in to comment.