Skip to content

Commit 49c0748

Browse files
authored
feat: Add ListAcceptedAssignments and GetAssignmentGrades methods to Classroom API (#3732)
1 parent 8b733ae commit 49c0748

File tree

5 files changed

+1025
-0
lines changed

5 files changed

+1025
-0
lines changed

github/classroom.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ import (
1616
// GitHub API docs: https://docs.github.com/rest/classroom/classroom
1717
type ClassroomService service
1818

19+
// ClassroomUser represents a GitHub user simplified for Classroom.
20+
type ClassroomUser struct {
21+
ID *int64 `json:"id,omitempty"`
22+
Login *string `json:"login,omitempty"`
23+
AvatarURL *string `json:"avatar_url,omitempty"`
24+
HTMLURL *string `json:"html_url,omitempty"`
25+
}
26+
27+
func (u ClassroomUser) String() string {
28+
return Stringify(u)
29+
}
30+
1931
// Classroom represents a GitHub Classroom.
2032
type Classroom struct {
2133
ID *int64 `json:"id,omitempty"`
@@ -56,6 +68,41 @@ func (a ClassroomAssignment) String() string {
5668
return Stringify(a)
5769
}
5870

71+
// AcceptedAssignment represents a GitHub Classroom accepted assignment.
72+
type AcceptedAssignment struct {
73+
ID *int64 `json:"id,omitempty"`
74+
Submitted *bool `json:"submitted,omitempty"`
75+
Passing *bool `json:"passing,omitempty"`
76+
CommitCount *int `json:"commit_count,omitempty"`
77+
Grade *string `json:"grade,omitempty"`
78+
Students []*ClassroomUser `json:"students,omitempty"`
79+
Repository *Repository `json:"repository,omitempty"`
80+
Assignment *ClassroomAssignment `json:"assignment,omitempty"`
81+
}
82+
83+
func (a AcceptedAssignment) String() string {
84+
return Stringify(a)
85+
}
86+
87+
// AssignmentGrade represents a GitHub Classroom assignment grade.
88+
type AssignmentGrade struct {
89+
AssignmentName *string `json:"assignment_name,omitempty"`
90+
AssignmentURL *string `json:"assignment_url,omitempty"`
91+
StarterCodeURL *string `json:"starter_code_url,omitempty"`
92+
GithubUsername *string `json:"github_username,omitempty"`
93+
RosterIdentifier *string `json:"roster_identifier,omitempty"`
94+
StudentRepositoryName *string `json:"student_repository_name,omitempty"`
95+
StudentRepositoryURL *string `json:"student_repository_url,omitempty"`
96+
SubmissionTimestamp *Timestamp `json:"submission_timestamp,omitempty"`
97+
PointsAwarded *int `json:"points_awarded,omitempty"`
98+
PointsAvailable *int `json:"points_available,omitempty"`
99+
GroupName *string `json:"group_name,omitempty"`
100+
}
101+
102+
func (g AssignmentGrade) String() string {
103+
return Stringify(g)
104+
}
105+
59106
// GetAssignment gets a GitHub Classroom assignment. Assignment will only be
60107
// returned if the current user is an administrator of the GitHub Classroom
61108
// for the assignment.
@@ -155,3 +202,55 @@ func (s *ClassroomService) ListClassroomAssignments(ctx context.Context, classro
155202

156203
return assignments, resp, nil
157204
}
205+
206+
// ListAcceptedAssignments lists accepted assignments for a GitHub Classroom assignment.
207+
// Accepted assignments will only be returned if the current user is an administrator
208+
// of the GitHub Classroom for the assignment.
209+
//
210+
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#list-accepted-assignments-for-an-assignment
211+
//
212+
//meta:operation GET /assignments/{assignment_id}/accepted_assignments
213+
func (s *ClassroomService) ListAcceptedAssignments(ctx context.Context, assignmentID int64, opts *ListOptions) ([]*AcceptedAssignment, *Response, error) {
214+
u := fmt.Sprintf("assignments/%v/accepted_assignments", assignmentID)
215+
u, err := addOptions(u, opts)
216+
if err != nil {
217+
return nil, nil, err
218+
}
219+
220+
req, err := s.client.NewRequest("GET", u, nil)
221+
if err != nil {
222+
return nil, nil, err
223+
}
224+
225+
var acceptedAssignments []*AcceptedAssignment
226+
resp, err := s.client.Do(ctx, req, &acceptedAssignments)
227+
if err != nil {
228+
return nil, resp, err
229+
}
230+
231+
return acceptedAssignments, resp, nil
232+
}
233+
234+
// GetAssignmentGrades gets assignment grades for a GitHub Classroom assignment.
235+
// Grades will only be returned if the current user is an administrator
236+
// of the GitHub Classroom for the assignment.
237+
//
238+
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#get-assignment-grades
239+
//
240+
//meta:operation GET /assignments/{assignment_id}/grades
241+
func (s *ClassroomService) GetAssignmentGrades(ctx context.Context, assignmentID int64) ([]*AssignmentGrade, *Response, error) {
242+
u := fmt.Sprintf("assignments/%v/grades", assignmentID)
243+
244+
req, err := s.client.NewRequest("GET", u, nil)
245+
if err != nil {
246+
return nil, nil, err
247+
}
248+
249+
var grades []*AssignmentGrade
250+
resp, err := s.client.Do(ctx, req, &grades)
251+
if err != nil {
252+
return nil, resp, err
253+
}
254+
255+
return grades, resp, nil
256+
}

0 commit comments

Comments
 (0)