Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions github/classroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ import (
// GitHub API docs: https://docs.github.com/rest/classroom/classroom
type ClassroomService service

// ClassroomUser represents a GitHub user simplified for Classroom.
type ClassroomUser struct {
ID *int64 `json:"id,omitempty"`
Login *string `json:"login,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
}

func (u ClassroomUser) String() string {
return Stringify(u)
}

// Classroom represents a GitHub Classroom.
type Classroom struct {
ID *int64 `json:"id,omitempty"`
Expand Down Expand Up @@ -56,6 +68,41 @@ func (a ClassroomAssignment) String() string {
return Stringify(a)
}

// AcceptedAssignment represents a GitHub Classroom accepted assignment.
type AcceptedAssignment struct {
ID *int64 `json:"id,omitempty"`
Submitted *bool `json:"submitted,omitempty"`
Passing *bool `json:"passing,omitempty"`
CommitCount *int `json:"commit_count,omitempty"`
Grade *string `json:"grade,omitempty"`
Students []*ClassroomUser `json:"students,omitempty"`
Repository *Repository `json:"repository,omitempty"`
Assignment *ClassroomAssignment `json:"assignment,omitempty"`
}

func (a AcceptedAssignment) String() string {
return Stringify(a)
}

// AssignmentGrade represents a GitHub Classroom assignment grade.
type AssignmentGrade struct {
AssignmentName *string `json:"assignment_name,omitempty"`
AssignmentURL *string `json:"assignment_url,omitempty"`
StarterCodeURL *string `json:"starter_code_url,omitempty"`
GithubUsername *string `json:"github_username,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GithubUsername *string `json:"github_username,omitempty"`
GitHubUsername *string `json:"github_username,omitempty"`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we decided years ago that in this repo, we are going to strictly follow the capitalization of the JSON tag, so that GithubUsername in this case is correct.

If they had named the field git_hub_username, then you would be right, but they don't, so we don't.

I'll see if I can find the conversation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's one instance, but am still trying to find the original decision with the repo's original author.
#2851 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is what I'm thinking of, although I'm pretty sure there was a separate discussion specifically about Github vs GitHub.
#605

RosterIdentifier *string `json:"roster_identifier,omitempty"`
StudentRepositoryName *string `json:"student_repository_name,omitempty"`
StudentRepositoryURL *string `json:"student_repository_url,omitempty"`
SubmissionTimestamp *Timestamp `json:"submission_timestamp,omitempty"`
PointsAwarded *int `json:"points_awarded,omitempty"`
PointsAvailable *int `json:"points_available,omitempty"`
GroupName *string `json:"group_name,omitempty"`
}

func (g AssignmentGrade) String() string {
return Stringify(g)
}

// GetAssignment gets a GitHub Classroom assignment. Assignment will only be
// returned if the current user is an administrator of the GitHub Classroom
// for the assignment.
Expand Down Expand Up @@ -155,3 +202,55 @@ func (s *ClassroomService) ListClassroomAssignments(ctx context.Context, classro

return assignments, resp, nil
}

// ListAcceptedAssignments lists accepted assignments for a GitHub Classroom assignment.
// Accepted assignments will only be returned if the current user is an administrator
// of the GitHub Classroom for the assignment.
//
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#list-accepted-assignments-for-an-assignment
//
//meta:operation GET /assignments/{assignment_id}/accepted_assignments
func (s *ClassroomService) ListAcceptedAssignments(ctx context.Context, assignmentID int64, opts *ListOptions) ([]*AcceptedAssignment, *Response, error) {
u := fmt.Sprintf("assignments/%v/accepted_assignments", assignmentID)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

var acceptedAssignments []*AcceptedAssignment
resp, err := s.client.Do(ctx, req, &acceptedAssignments)
if err != nil {
return nil, resp, err
}

return acceptedAssignments, resp, nil
}

// GetAssignmentGrades gets assignment grades for a GitHub Classroom assignment.
// Grades will only be returned if the current user is an administrator
// of the GitHub Classroom for the assignment.
//
// GitHub API docs: https://docs.github.com/rest/classroom/classroom#get-assignment-grades
//
//meta:operation GET /assignments/{assignment_id}/grades
func (s *ClassroomService) GetAssignmentGrades(ctx context.Context, assignmentID int64) ([]*AssignmentGrade, *Response, error) {
u := fmt.Sprintf("assignments/%v/grades", assignmentID)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

var grades []*AssignmentGrade
resp, err := s.client.Do(ctx, req, &grades)
if err != nil {
return nil, resp, err
}

return grades, resp, nil
}
Loading
Loading