From a2af37808b4839c0c4af5879496146bb462e9364 Mon Sep 17 00:00:00 2001 From: jorge-ferrero-ag Date: Sun, 17 Aug 2025 15:23:56 +0200 Subject: [PATCH 1/2] feat: add GitHub Classroom GetAssignment API endpoint # Add GitHub Classroom GetAssignment API endpoint Implements `GET /assignments/{assignment_id}` endpoint for retrieving GitHub Classroom assignment details. ## Changes - **New service**: `ClassroomService` with `GetAssignment()` method - **New structs**: `Assignment` (19 fields) and `Classroom` with organization details --- github/classroom.go | 82 ++++++++++ github/classroom_test.go | 211 ++++++++++++++++++++++++++ github/github-accessors.go | 192 ++++++++++++++++++++++++ github/github-accessors_test.go | 255 ++++++++++++++++++++++++++++++++ github/github-stringify_test.go | 44 ++++++ github/github.go | 2 + 6 files changed, 786 insertions(+) create mode 100644 github/classroom.go create mode 100644 github/classroom_test.go diff --git a/github/classroom.go b/github/classroom.go new file mode 100644 index 00000000000..4e6e5095ac8 --- /dev/null +++ b/github/classroom.go @@ -0,0 +1,82 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" +) + +// ClassroomService handles communication with the GitHub Classroom related +// methods of the GitHub API. +// +// GitHub API docs: https://docs.github.com/rest/classroom/classroom +type ClassroomService service + +// Classroom represents a GitHub Classroom. +type Classroom struct { + ID *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Archived *bool `json:"archived,omitempty"` + Organization *Organization `json:"organization,omitempty"` + URL *string `json:"url,omitempty"` +} + +func (c Classroom) String() string { + return Stringify(c) +} + +// Assignment represents a GitHub Classroom assignment. +type Assignment struct { + ID *int64 `json:"id,omitempty"` + PublicRepo *bool `json:"public_repo,omitempty"` + Title *string `json:"title,omitempty"` + Type *string `json:"type,omitempty"` + InviteLink *string `json:"invite_link,omitempty"` + InvitationsEnabled *bool `json:"invitations_enabled,omitempty"` + Slug *string `json:"slug,omitempty"` + StudentsAreRepoAdmins *bool `json:"students_are_repo_admins,omitempty"` + FeedbackPullRequestsEnabled *bool `json:"feedback_pull_requests_enabled,omitempty"` + MaxTeams *int `json:"max_teams,omitempty"` + MaxMembers *int `json:"max_members,omitempty"` + Editor *string `json:"editor,omitempty"` + Accepted *int `json:"accepted,omitempty"` + Submitted *int `json:"submitted,omitempty"` + Passing *int `json:"passing,omitempty"` + Language *string `json:"language,omitempty"` + Deadline *Timestamp `json:"deadline,omitempty"` + StarterCodeRepository *Repository `json:"starter_code_repository,omitempty"` + Classroom *Classroom `json:"classroom,omitempty"` +} + +func (a Assignment) String() string { + return Stringify(a) +} + +// 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. +// +// GitHub API docs: https://docs.github.com/rest/classroom/classroom#get-an-assignment +// +//meta:operation GET /assignments/{assignment_id} +func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64) (*Assignment, *Response, error) { + u := fmt.Sprintf("assignments/%v", assignmentID) + + req, err := s.client.NewRequest(http.MethodGet, u, nil) + if err != nil { + return nil, nil, err + } + + assignment := new(Assignment) + resp, err := s.client.Do(ctx, req, assignment) + if err != nil { + return nil, resp, err + } + + return assignment, resp, nil +} diff --git a/github/classroom_test.go b/github/classroom_test.go new file mode 100644 index 00000000000..ef9efbc77f5 --- /dev/null +++ b/github/classroom_test.go @@ -0,0 +1,211 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" + "testing" + "time" + + "github.com/google/go-cmp/cmp" +) + +func TestClassroom_Marshal(t *testing.T) { + t.Parallel() + testJSONMarshal(t, &Classroom{}, "{}") + + c := &Classroom{ + ID: Ptr(int64(1296269)), + Name: Ptr("Programming Elixir"), + Archived: Ptr(false), + Organization: &Organization{ + ID: Ptr(int64(1)), + Login: Ptr("programming-elixir"), + NodeID: Ptr("MDEyOk9yZ2FuaXphdGlvbjE="), + HTMLURL: Ptr("https://github.com/programming-elixir"), + Name: Ptr("Learn how to build fault tolerant applications"), + AvatarURL: Ptr("https://avatars.githubusercontent.com/u/9919?v=4"), + }, + URL: Ptr("https://classroom.github.com/classrooms/1-programming-elixir"), + } + + want := `{ + "id": 1296269, + "name": "Programming Elixir", + "archived": false, + "organization": { + "id": 1, + "login": "programming-elixir", + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "html_url": "https://github.com/programming-elixir", + "name": "Learn how to build fault tolerant applications", + "avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4" + }, + "url": "https://classroom.github.com/classrooms/1-programming-elixir" + }` + + testJSONMarshal(t, c, want) +} + +func TestAssignment_Marshal(t *testing.T) { + t.Parallel() + testJSONMarshal(t, &Assignment{}, "{}") + + a := &Assignment{ + ID: Ptr(int64(12)), + PublicRepo: Ptr(false), + Title: Ptr("Intro to Binaries"), + Type: Ptr("individual"), + InviteLink: Ptr("https://classroom.github.com/a/Lx7jiUgx"), + InvitationsEnabled: Ptr(true), + Slug: Ptr("intro-to-binaries"), + StudentsAreRepoAdmins: Ptr(false), + FeedbackPullRequestsEnabled: Ptr(true), + MaxTeams: Ptr(0), + MaxMembers: Ptr(0), + Editor: Ptr("codespaces"), + Accepted: Ptr(100), + Submitted: Ptr(40), + Passing: Ptr(10), + Language: Ptr("ruby"), + Deadline: &Timestamp{referenceTime}, + StarterCodeRepository: &Repository{ + ID: Ptr(int64(1296269)), + FullName: Ptr("octocat/Hello-World"), + }, + Classroom: &Classroom{ + ID: Ptr(int64(1296269)), + Name: Ptr("Programming Elixir"), + }, + } + + want := `{ + "id": 12, + "public_repo": false, + "title": "Intro to Binaries", + "type": "individual", + "invite_link": "https://classroom.github.com/a/Lx7jiUgx", + "invitations_enabled": true, + "slug": "intro-to-binaries", + "students_are_repo_admins": false, + "feedback_pull_requests_enabled": true, + "max_teams": 0, + "max_members": 0, + "editor": "codespaces", + "accepted": 100, + "submitted": 40, + "passing": 10, + "language": "ruby", + "deadline": ` + referenceTimeStr + `, + "starter_code_repository": { + "id": 1296269, + "full_name": "octocat/Hello-World" + }, + "classroom": { + "id": 1296269, + "name": "Programming Elixir" + } + }` + + testJSONMarshal(t, a, want) +} + +func TestClassroomService_GetAssignment(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/assignments/12", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "id": 12, + "public_repo": false, + "title": "Intro to Binaries", + "type": "individual", + "invite_link": "https://classroom.github.com/a/Lx7jiUgx", + "invitations_enabled": true, + "slug": "intro-to-binaries", + "students_are_repo_admins": false, + "feedback_pull_requests_enabled": true, + "max_teams": 0, + "max_members": 0, + "editor": "codespaces", + "accepted": 100, + "submitted": 40, + "passing": 10, + "language": "ruby", + "deadline": "2011-01-26T19:06:43Z", + "starter_code_repository": { + "id": 1296269, + "full_name": "octocat/Hello-World", + "html_url": "https://github.com/octocat/Hello-World", + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "private": false, + "default_branch": "main" + }, + "classroom": { + "id": 1296269, + "name": "Programming Elixir", + "archived": false, + "url": "https://classroom.github.com/classrooms/1-programming-elixir" + } + }`) + }) + + ctx := context.Background() + assignment, _, err := client.Classroom.GetAssignment(ctx, 12) + if err != nil { + t.Errorf("Classroom.GetAssignment returned error: %v", err) + } + + want := &Assignment{ + ID: Ptr(int64(12)), + PublicRepo: Ptr(false), + Title: Ptr("Intro to Binaries"), + Type: Ptr("individual"), + InviteLink: Ptr("https://classroom.github.com/a/Lx7jiUgx"), + InvitationsEnabled: Ptr(true), + Slug: Ptr("intro-to-binaries"), + StudentsAreRepoAdmins: Ptr(false), + FeedbackPullRequestsEnabled: Ptr(true), + MaxTeams: Ptr(0), + MaxMembers: Ptr(0), + Editor: Ptr("codespaces"), + Accepted: Ptr(100), + Submitted: Ptr(40), + Passing: Ptr(10), + Language: Ptr("ruby"), + Deadline: func() *Timestamp { t, _ := time.Parse(time.RFC3339, "2011-01-26T19:06:43Z"); return &Timestamp{t} }(), + StarterCodeRepository: &Repository{ + ID: Ptr(int64(1296269)), + FullName: Ptr("octocat/Hello-World"), + HTMLURL: Ptr("https://github.com/octocat/Hello-World"), + NodeID: Ptr("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"), + Private: Ptr(false), + DefaultBranch: Ptr("main"), + }, + Classroom: &Classroom{ + ID: Ptr(int64(1296269)), + Name: Ptr("Programming Elixir"), + Archived: Ptr(false), + URL: Ptr("https://classroom.github.com/classrooms/1-programming-elixir"), + }, + } + + if !cmp.Equal(assignment, want) { + t.Errorf("Classroom.GetAssignment returned %+v, want %+v", assignment, want) + } + + const methodName = "GetAssignment" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Classroom.GetAssignment(ctx, 12) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} diff --git a/github/github-accessors.go b/github/github-accessors.go index d0973b280b0..0fe9d9f3917 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1086,6 +1086,158 @@ func (a *ArtifactWorkflowRun) GetRepositoryID() int64 { return *a.RepositoryID } +// GetAccepted returns the Accepted field if it's non-nil, zero value otherwise. +func (a *Assignment) GetAccepted() int { + if a == nil || a.Accepted == nil { + return 0 + } + return *a.Accepted +} + +// GetClassroom returns the Classroom field. +func (a *Assignment) GetClassroom() *Classroom { + if a == nil { + return nil + } + return a.Classroom +} + +// GetDeadline returns the Deadline field if it's non-nil, zero value otherwise. +func (a *Assignment) GetDeadline() Timestamp { + if a == nil || a.Deadline == nil { + return Timestamp{} + } + return *a.Deadline +} + +// GetEditor returns the Editor field if it's non-nil, zero value otherwise. +func (a *Assignment) GetEditor() string { + if a == nil || a.Editor == nil { + return "" + } + return *a.Editor +} + +// GetFeedbackPullRequestsEnabled returns the FeedbackPullRequestsEnabled field if it's non-nil, zero value otherwise. +func (a *Assignment) GetFeedbackPullRequestsEnabled() bool { + if a == nil || a.FeedbackPullRequestsEnabled == nil { + return false + } + return *a.FeedbackPullRequestsEnabled +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (a *Assignment) GetID() int64 { + if a == nil || a.ID == nil { + return 0 + } + return *a.ID +} + +// GetInvitationsEnabled returns the InvitationsEnabled field if it's non-nil, zero value otherwise. +func (a *Assignment) GetInvitationsEnabled() bool { + if a == nil || a.InvitationsEnabled == nil { + return false + } + return *a.InvitationsEnabled +} + +// GetInviteLink returns the InviteLink field if it's non-nil, zero value otherwise. +func (a *Assignment) GetInviteLink() string { + if a == nil || a.InviteLink == nil { + return "" + } + return *a.InviteLink +} + +// GetLanguage returns the Language field if it's non-nil, zero value otherwise. +func (a *Assignment) GetLanguage() string { + if a == nil || a.Language == nil { + return "" + } + return *a.Language +} + +// GetMaxMembers returns the MaxMembers field if it's non-nil, zero value otherwise. +func (a *Assignment) GetMaxMembers() int { + if a == nil || a.MaxMembers == nil { + return 0 + } + return *a.MaxMembers +} + +// GetMaxTeams returns the MaxTeams field if it's non-nil, zero value otherwise. +func (a *Assignment) GetMaxTeams() int { + if a == nil || a.MaxTeams == nil { + return 0 + } + return *a.MaxTeams +} + +// GetPassing returns the Passing field if it's non-nil, zero value otherwise. +func (a *Assignment) GetPassing() int { + if a == nil || a.Passing == nil { + return 0 + } + return *a.Passing +} + +// GetPublicRepo returns the PublicRepo field if it's non-nil, zero value otherwise. +func (a *Assignment) GetPublicRepo() bool { + if a == nil || a.PublicRepo == nil { + return false + } + return *a.PublicRepo +} + +// GetSlug returns the Slug field if it's non-nil, zero value otherwise. +func (a *Assignment) GetSlug() string { + if a == nil || a.Slug == nil { + return "" + } + return *a.Slug +} + +// GetStarterCodeRepository returns the StarterCodeRepository field. +func (a *Assignment) GetStarterCodeRepository() *Repository { + if a == nil { + return nil + } + return a.StarterCodeRepository +} + +// GetStudentsAreRepoAdmins returns the StudentsAreRepoAdmins field if it's non-nil, zero value otherwise. +func (a *Assignment) GetStudentsAreRepoAdmins() bool { + if a == nil || a.StudentsAreRepoAdmins == nil { + return false + } + return *a.StudentsAreRepoAdmins +} + +// GetSubmitted returns the Submitted field if it's non-nil, zero value otherwise. +func (a *Assignment) GetSubmitted() int { + if a == nil || a.Submitted == nil { + return 0 + } + return *a.Submitted +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (a *Assignment) GetTitle() string { + if a == nil || a.Title == nil { + return "" + } + return *a.Title +} + +// GetType returns the Type field if it's non-nil, zero value otherwise. +func (a *Assignment) GetType() string { + if a == nil || a.Type == nil { + return "" + } + return *a.Type +} + // GetBody returns the Body field if it's non-nil, zero value otherwise. func (a *Attachment) GetBody() string { if a == nil || a.Body == nil { @@ -2526,6 +2678,46 @@ func (c *CheckSuitePreferenceResults) GetRepository() *Repository { return c.Repository } +// GetArchived returns the Archived field if it's non-nil, zero value otherwise. +func (c *Classroom) GetArchived() bool { + if c == nil || c.Archived == nil { + return false + } + return *c.Archived +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (c *Classroom) GetID() int64 { + if c == nil || c.ID == nil { + return 0 + } + return *c.ID +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (c *Classroom) GetName() string { + if c == nil || c.Name == nil { + return "" + } + return *c.Name +} + +// GetOrganization returns the Organization field. +func (c *Classroom) GetOrganization() *Organization { + if c == nil { + return nil + } + return c.Organization +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *Classroom) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + // GetFingerprint returns the Fingerprint field if it's non-nil, zero value otherwise. func (c *ClusterSSHKey) GetFingerprint() string { if c == nil || c.Fingerprint == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index dbc78f046ba..9c903e28522 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1411,6 +1411,209 @@ func TestArtifactWorkflowRun_GetRepositoryID(tt *testing.T) { a.GetRepositoryID() } +func TestAssignment_GetAccepted(tt *testing.T) { + tt.Parallel() + var zeroValue int + a := &Assignment{Accepted: &zeroValue} + a.GetAccepted() + a = &Assignment{} + a.GetAccepted() + a = nil + a.GetAccepted() +} + +func TestAssignment_GetClassroom(tt *testing.T) { + tt.Parallel() + a := &Assignment{} + a.GetClassroom() + a = nil + a.GetClassroom() +} + +func TestAssignment_GetDeadline(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + a := &Assignment{Deadline: &zeroValue} + a.GetDeadline() + a = &Assignment{} + a.GetDeadline() + a = nil + a.GetDeadline() +} + +func TestAssignment_GetEditor(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{Editor: &zeroValue} + a.GetEditor() + a = &Assignment{} + a.GetEditor() + a = nil + a.GetEditor() +} + +func TestAssignment_GetFeedbackPullRequestsEnabled(tt *testing.T) { + tt.Parallel() + var zeroValue bool + a := &Assignment{FeedbackPullRequestsEnabled: &zeroValue} + a.GetFeedbackPullRequestsEnabled() + a = &Assignment{} + a.GetFeedbackPullRequestsEnabled() + a = nil + a.GetFeedbackPullRequestsEnabled() +} + +func TestAssignment_GetID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + a := &Assignment{ID: &zeroValue} + a.GetID() + a = &Assignment{} + a.GetID() + a = nil + a.GetID() +} + +func TestAssignment_GetInvitationsEnabled(tt *testing.T) { + tt.Parallel() + var zeroValue bool + a := &Assignment{InvitationsEnabled: &zeroValue} + a.GetInvitationsEnabled() + a = &Assignment{} + a.GetInvitationsEnabled() + a = nil + a.GetInvitationsEnabled() +} + +func TestAssignment_GetInviteLink(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{InviteLink: &zeroValue} + a.GetInviteLink() + a = &Assignment{} + a.GetInviteLink() + a = nil + a.GetInviteLink() +} + +func TestAssignment_GetLanguage(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{Language: &zeroValue} + a.GetLanguage() + a = &Assignment{} + a.GetLanguage() + a = nil + a.GetLanguage() +} + +func TestAssignment_GetMaxMembers(tt *testing.T) { + tt.Parallel() + var zeroValue int + a := &Assignment{MaxMembers: &zeroValue} + a.GetMaxMembers() + a = &Assignment{} + a.GetMaxMembers() + a = nil + a.GetMaxMembers() +} + +func TestAssignment_GetMaxTeams(tt *testing.T) { + tt.Parallel() + var zeroValue int + a := &Assignment{MaxTeams: &zeroValue} + a.GetMaxTeams() + a = &Assignment{} + a.GetMaxTeams() + a = nil + a.GetMaxTeams() +} + +func TestAssignment_GetPassing(tt *testing.T) { + tt.Parallel() + var zeroValue int + a := &Assignment{Passing: &zeroValue} + a.GetPassing() + a = &Assignment{} + a.GetPassing() + a = nil + a.GetPassing() +} + +func TestAssignment_GetPublicRepo(tt *testing.T) { + tt.Parallel() + var zeroValue bool + a := &Assignment{PublicRepo: &zeroValue} + a.GetPublicRepo() + a = &Assignment{} + a.GetPublicRepo() + a = nil + a.GetPublicRepo() +} + +func TestAssignment_GetSlug(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{Slug: &zeroValue} + a.GetSlug() + a = &Assignment{} + a.GetSlug() + a = nil + a.GetSlug() +} + +func TestAssignment_GetStarterCodeRepository(tt *testing.T) { + tt.Parallel() + a := &Assignment{} + a.GetStarterCodeRepository() + a = nil + a.GetStarterCodeRepository() +} + +func TestAssignment_GetStudentsAreRepoAdmins(tt *testing.T) { + tt.Parallel() + var zeroValue bool + a := &Assignment{StudentsAreRepoAdmins: &zeroValue} + a.GetStudentsAreRepoAdmins() + a = &Assignment{} + a.GetStudentsAreRepoAdmins() + a = nil + a.GetStudentsAreRepoAdmins() +} + +func TestAssignment_GetSubmitted(tt *testing.T) { + tt.Parallel() + var zeroValue int + a := &Assignment{Submitted: &zeroValue} + a.GetSubmitted() + a = &Assignment{} + a.GetSubmitted() + a = nil + a.GetSubmitted() +} + +func TestAssignment_GetTitle(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{Title: &zeroValue} + a.GetTitle() + a = &Assignment{} + a.GetTitle() + a = nil + a.GetTitle() +} + +func TestAssignment_GetType(tt *testing.T) { + tt.Parallel() + var zeroValue string + a := &Assignment{Type: &zeroValue} + a.GetType() + a = &Assignment{} + a.GetType() + a = nil + a.GetType() +} + func TestAttachment_GetBody(tt *testing.T) { tt.Parallel() var zeroValue string @@ -3277,6 +3480,58 @@ func TestCheckSuitePreferenceResults_GetRepository(tt *testing.T) { c.GetRepository() } +func TestClassroom_GetArchived(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &Classroom{Archived: &zeroValue} + c.GetArchived() + c = &Classroom{} + c.GetArchived() + c = nil + c.GetArchived() +} + +func TestClassroom_GetID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + c := &Classroom{ID: &zeroValue} + c.GetID() + c = &Classroom{} + c.GetID() + c = nil + c.GetID() +} + +func TestClassroom_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &Classroom{Name: &zeroValue} + c.GetName() + c = &Classroom{} + c.GetName() + c = nil + c.GetName() +} + +func TestClassroom_GetOrganization(tt *testing.T) { + tt.Parallel() + c := &Classroom{} + c.GetOrganization() + c = nil + c.GetOrganization() +} + +func TestClassroom_GetURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &Classroom{URL: &zeroValue} + c.GetURL() + c = &Classroom{} + c.GetURL() + c = nil + c.GetURL() +} + func TestClusterSSHKey_GetFingerprint(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index abbe7f6b8c0..e2d8fcee015 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -108,6 +108,35 @@ func TestArtifactPeriod_String(t *testing.T) { } } +func TestAssignment_String(t *testing.T) { + t.Parallel() + v := Assignment{ + ID: Ptr(int64(0)), + PublicRepo: Ptr(false), + Title: Ptr(""), + Type: Ptr(""), + InviteLink: Ptr(""), + InvitationsEnabled: Ptr(false), + Slug: Ptr(""), + StudentsAreRepoAdmins: Ptr(false), + FeedbackPullRequestsEnabled: Ptr(false), + MaxTeams: Ptr(0), + MaxMembers: Ptr(0), + Editor: Ptr(""), + Accepted: Ptr(0), + Submitted: Ptr(0), + Passing: Ptr(0), + Language: Ptr(""), + Deadline: &Timestamp{}, + StarterCodeRepository: &Repository{}, + Classroom: &Classroom{}, + } + want := `github.Assignment{ID:0, PublicRepo:false, Title:"", Type:"", InviteLink:"", InvitationsEnabled:false, Slug:"", StudentsAreRepoAdmins:false, FeedbackPullRequestsEnabled:false, MaxTeams:0, MaxMembers:0, Editor:"", Accepted:0, Submitted:0, Passing:0, Language:"", Deadline:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, StarterCodeRepository:github.Repository{}, Classroom:github.Classroom{}}` + if got := v.String(); got != want { + t.Errorf("Assignment.String = %v, want %v", got, want) + } +} + func TestAuthorization_String(t *testing.T) { t.Parallel() v := Authorization{ @@ -228,6 +257,21 @@ func TestCheckSuite_String(t *testing.T) { } } +func TestClassroom_String(t *testing.T) { + t.Parallel() + v := Classroom{ + ID: Ptr(int64(0)), + Name: Ptr(""), + Archived: Ptr(false), + Organization: &Organization{}, + URL: Ptr(""), + } + want := `github.Classroom{ID:0, Name:"", Archived:false, Organization:github.Organization{}, URL:""}` + if got := v.String(); got != want { + t.Errorf("Classroom.String = %v, want %v", got, want) + } +} + func TestCodeOfConduct_String(t *testing.T) { t.Parallel() v := CodeOfConduct{ diff --git a/github/github.go b/github/github.go index bb81b00c104..97b0d143be5 100644 --- a/github/github.go +++ b/github/github.go @@ -197,6 +197,7 @@ type Client struct { Authorizations *AuthorizationsService Billing *BillingService Checks *ChecksService + Classroom *ClassroomService CodeScanning *CodeScanningService CodesOfConduct *CodesOfConductService Codespaces *CodespacesService @@ -434,6 +435,7 @@ func (c *Client) initialize() { c.Authorizations = (*AuthorizationsService)(&c.common) c.Billing = (*BillingService)(&c.common) c.Checks = (*ChecksService)(&c.common) + c.Classroom = (*ClassroomService)(&c.common) c.CodeScanning = (*CodeScanningService)(&c.common) c.Codespaces = (*CodespacesService)(&c.common) c.CodesOfConduct = (*CodesOfConductService)(&c.common) From bef279d6cb74882d330f5c1a3b6f9199b227b54a Mon Sep 17 00:00:00 2001 From: jorge-ferrero-ag Date: Mon, 18 Aug 2025 13:41:07 +0200 Subject: [PATCH 2/2] Rename Assignment to ClassroomAssignment Refactors the Assignment struct and related methods to ClassroomAssignment for improved clarity and consistency. Updates all accessors, service methods, and tests to use the new name. --- github/classroom.go | 10 +- github/classroom_test.go | 8 +- github/github-accessors.go | 304 ++++++++++++------------ github/github-accessors_test.go | 406 ++++++++++++++++---------------- github/github-stringify_test.go | 58 ++--- 5 files changed, 393 insertions(+), 393 deletions(-) diff --git a/github/classroom.go b/github/classroom.go index 4e6e5095ac8..8f6ce14511e 100644 --- a/github/classroom.go +++ b/github/classroom.go @@ -30,8 +30,8 @@ func (c Classroom) String() string { return Stringify(c) } -// Assignment represents a GitHub Classroom assignment. -type Assignment struct { +// ClassroomAssignment represents a GitHub Classroom assignment. +type ClassroomAssignment struct { ID *int64 `json:"id,omitempty"` PublicRepo *bool `json:"public_repo,omitempty"` Title *string `json:"title,omitempty"` @@ -53,7 +53,7 @@ type Assignment struct { Classroom *Classroom `json:"classroom,omitempty"` } -func (a Assignment) String() string { +func (a ClassroomAssignment) String() string { return Stringify(a) } @@ -64,7 +64,7 @@ func (a Assignment) String() string { // GitHub API docs: https://docs.github.com/rest/classroom/classroom#get-an-assignment // //meta:operation GET /assignments/{assignment_id} -func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64) (*Assignment, *Response, error) { +func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64) (*ClassroomAssignment, *Response, error) { u := fmt.Sprintf("assignments/%v", assignmentID) req, err := s.client.NewRequest(http.MethodGet, u, nil) @@ -72,7 +72,7 @@ func (s *ClassroomService) GetAssignment(ctx context.Context, assignmentID int64 return nil, nil, err } - assignment := new(Assignment) + assignment := new(ClassroomAssignment) resp, err := s.client.Do(ctx, req, assignment) if err != nil { return nil, resp, err diff --git a/github/classroom_test.go b/github/classroom_test.go index ef9efbc77f5..a6c67f15180 100644 --- a/github/classroom_test.go +++ b/github/classroom_test.go @@ -52,11 +52,11 @@ func TestClassroom_Marshal(t *testing.T) { testJSONMarshal(t, c, want) } -func TestAssignment_Marshal(t *testing.T) { +func TestClassroomAssignment_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Assignment{}, "{}") + testJSONMarshal(t, &ClassroomAssignment{}, "{}") - a := &Assignment{ + a := &ClassroomAssignment{ ID: Ptr(int64(12)), PublicRepo: Ptr(false), Title: Ptr("Intro to Binaries"), @@ -162,7 +162,7 @@ func TestClassroomService_GetAssignment(t *testing.T) { t.Errorf("Classroom.GetAssignment returned error: %v", err) } - want := &Assignment{ + want := &ClassroomAssignment{ ID: Ptr(int64(12)), PublicRepo: Ptr(false), Title: Ptr("Intro to Binaries"), diff --git a/github/github-accessors.go b/github/github-accessors.go index 0fe9d9f3917..b860363e81d 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1086,158 +1086,6 @@ func (a *ArtifactWorkflowRun) GetRepositoryID() int64 { return *a.RepositoryID } -// GetAccepted returns the Accepted field if it's non-nil, zero value otherwise. -func (a *Assignment) GetAccepted() int { - if a == nil || a.Accepted == nil { - return 0 - } - return *a.Accepted -} - -// GetClassroom returns the Classroom field. -func (a *Assignment) GetClassroom() *Classroom { - if a == nil { - return nil - } - return a.Classroom -} - -// GetDeadline returns the Deadline field if it's non-nil, zero value otherwise. -func (a *Assignment) GetDeadline() Timestamp { - if a == nil || a.Deadline == nil { - return Timestamp{} - } - return *a.Deadline -} - -// GetEditor returns the Editor field if it's non-nil, zero value otherwise. -func (a *Assignment) GetEditor() string { - if a == nil || a.Editor == nil { - return "" - } - return *a.Editor -} - -// GetFeedbackPullRequestsEnabled returns the FeedbackPullRequestsEnabled field if it's non-nil, zero value otherwise. -func (a *Assignment) GetFeedbackPullRequestsEnabled() bool { - if a == nil || a.FeedbackPullRequestsEnabled == nil { - return false - } - return *a.FeedbackPullRequestsEnabled -} - -// GetID returns the ID field if it's non-nil, zero value otherwise. -func (a *Assignment) GetID() int64 { - if a == nil || a.ID == nil { - return 0 - } - return *a.ID -} - -// GetInvitationsEnabled returns the InvitationsEnabled field if it's non-nil, zero value otherwise. -func (a *Assignment) GetInvitationsEnabled() bool { - if a == nil || a.InvitationsEnabled == nil { - return false - } - return *a.InvitationsEnabled -} - -// GetInviteLink returns the InviteLink field if it's non-nil, zero value otherwise. -func (a *Assignment) GetInviteLink() string { - if a == nil || a.InviteLink == nil { - return "" - } - return *a.InviteLink -} - -// GetLanguage returns the Language field if it's non-nil, zero value otherwise. -func (a *Assignment) GetLanguage() string { - if a == nil || a.Language == nil { - return "" - } - return *a.Language -} - -// GetMaxMembers returns the MaxMembers field if it's non-nil, zero value otherwise. -func (a *Assignment) GetMaxMembers() int { - if a == nil || a.MaxMembers == nil { - return 0 - } - return *a.MaxMembers -} - -// GetMaxTeams returns the MaxTeams field if it's non-nil, zero value otherwise. -func (a *Assignment) GetMaxTeams() int { - if a == nil || a.MaxTeams == nil { - return 0 - } - return *a.MaxTeams -} - -// GetPassing returns the Passing field if it's non-nil, zero value otherwise. -func (a *Assignment) GetPassing() int { - if a == nil || a.Passing == nil { - return 0 - } - return *a.Passing -} - -// GetPublicRepo returns the PublicRepo field if it's non-nil, zero value otherwise. -func (a *Assignment) GetPublicRepo() bool { - if a == nil || a.PublicRepo == nil { - return false - } - return *a.PublicRepo -} - -// GetSlug returns the Slug field if it's non-nil, zero value otherwise. -func (a *Assignment) GetSlug() string { - if a == nil || a.Slug == nil { - return "" - } - return *a.Slug -} - -// GetStarterCodeRepository returns the StarterCodeRepository field. -func (a *Assignment) GetStarterCodeRepository() *Repository { - if a == nil { - return nil - } - return a.StarterCodeRepository -} - -// GetStudentsAreRepoAdmins returns the StudentsAreRepoAdmins field if it's non-nil, zero value otherwise. -func (a *Assignment) GetStudentsAreRepoAdmins() bool { - if a == nil || a.StudentsAreRepoAdmins == nil { - return false - } - return *a.StudentsAreRepoAdmins -} - -// GetSubmitted returns the Submitted field if it's non-nil, zero value otherwise. -func (a *Assignment) GetSubmitted() int { - if a == nil || a.Submitted == nil { - return 0 - } - return *a.Submitted -} - -// GetTitle returns the Title field if it's non-nil, zero value otherwise. -func (a *Assignment) GetTitle() string { - if a == nil || a.Title == nil { - return "" - } - return *a.Title -} - -// GetType returns the Type field if it's non-nil, zero value otherwise. -func (a *Assignment) GetType() string { - if a == nil || a.Type == nil { - return "" - } - return *a.Type -} - // GetBody returns the Body field if it's non-nil, zero value otherwise. func (a *Attachment) GetBody() string { if a == nil || a.Body == nil { @@ -2718,6 +2566,158 @@ func (c *Classroom) GetURL() string { return *c.URL } +// GetAccepted returns the Accepted field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetAccepted() int { + if c == nil || c.Accepted == nil { + return 0 + } + return *c.Accepted +} + +// GetClassroom returns the Classroom field. +func (c *ClassroomAssignment) GetClassroom() *Classroom { + if c == nil { + return nil + } + return c.Classroom +} + +// GetDeadline returns the Deadline field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetDeadline() Timestamp { + if c == nil || c.Deadline == nil { + return Timestamp{} + } + return *c.Deadline +} + +// GetEditor returns the Editor field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetEditor() string { + if c == nil || c.Editor == nil { + return "" + } + return *c.Editor +} + +// GetFeedbackPullRequestsEnabled returns the FeedbackPullRequestsEnabled field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetFeedbackPullRequestsEnabled() bool { + if c == nil || c.FeedbackPullRequestsEnabled == nil { + return false + } + return *c.FeedbackPullRequestsEnabled +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetID() int64 { + if c == nil || c.ID == nil { + return 0 + } + return *c.ID +} + +// GetInvitationsEnabled returns the InvitationsEnabled field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetInvitationsEnabled() bool { + if c == nil || c.InvitationsEnabled == nil { + return false + } + return *c.InvitationsEnabled +} + +// GetInviteLink returns the InviteLink field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetInviteLink() string { + if c == nil || c.InviteLink == nil { + return "" + } + return *c.InviteLink +} + +// GetLanguage returns the Language field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetLanguage() string { + if c == nil || c.Language == nil { + return "" + } + return *c.Language +} + +// GetMaxMembers returns the MaxMembers field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetMaxMembers() int { + if c == nil || c.MaxMembers == nil { + return 0 + } + return *c.MaxMembers +} + +// GetMaxTeams returns the MaxTeams field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetMaxTeams() int { + if c == nil || c.MaxTeams == nil { + return 0 + } + return *c.MaxTeams +} + +// GetPassing returns the Passing field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetPassing() int { + if c == nil || c.Passing == nil { + return 0 + } + return *c.Passing +} + +// GetPublicRepo returns the PublicRepo field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetPublicRepo() bool { + if c == nil || c.PublicRepo == nil { + return false + } + return *c.PublicRepo +} + +// GetSlug returns the Slug field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetSlug() string { + if c == nil || c.Slug == nil { + return "" + } + return *c.Slug +} + +// GetStarterCodeRepository returns the StarterCodeRepository field. +func (c *ClassroomAssignment) GetStarterCodeRepository() *Repository { + if c == nil { + return nil + } + return c.StarterCodeRepository +} + +// GetStudentsAreRepoAdmins returns the StudentsAreRepoAdmins field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetStudentsAreRepoAdmins() bool { + if c == nil || c.StudentsAreRepoAdmins == nil { + return false + } + return *c.StudentsAreRepoAdmins +} + +// GetSubmitted returns the Submitted field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetSubmitted() int { + if c == nil || c.Submitted == nil { + return 0 + } + return *c.Submitted +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + +// GetType returns the Type field if it's non-nil, zero value otherwise. +func (c *ClassroomAssignment) GetType() string { + if c == nil || c.Type == nil { + return "" + } + return *c.Type +} + // GetFingerprint returns the Fingerprint field if it's non-nil, zero value otherwise. func (c *ClusterSSHKey) GetFingerprint() string { if c == nil || c.Fingerprint == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 9c903e28522..245b85bbfd2 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -1411,209 +1411,6 @@ func TestArtifactWorkflowRun_GetRepositoryID(tt *testing.T) { a.GetRepositoryID() } -func TestAssignment_GetAccepted(tt *testing.T) { - tt.Parallel() - var zeroValue int - a := &Assignment{Accepted: &zeroValue} - a.GetAccepted() - a = &Assignment{} - a.GetAccepted() - a = nil - a.GetAccepted() -} - -func TestAssignment_GetClassroom(tt *testing.T) { - tt.Parallel() - a := &Assignment{} - a.GetClassroom() - a = nil - a.GetClassroom() -} - -func TestAssignment_GetDeadline(tt *testing.T) { - tt.Parallel() - var zeroValue Timestamp - a := &Assignment{Deadline: &zeroValue} - a.GetDeadline() - a = &Assignment{} - a.GetDeadline() - a = nil - a.GetDeadline() -} - -func TestAssignment_GetEditor(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{Editor: &zeroValue} - a.GetEditor() - a = &Assignment{} - a.GetEditor() - a = nil - a.GetEditor() -} - -func TestAssignment_GetFeedbackPullRequestsEnabled(tt *testing.T) { - tt.Parallel() - var zeroValue bool - a := &Assignment{FeedbackPullRequestsEnabled: &zeroValue} - a.GetFeedbackPullRequestsEnabled() - a = &Assignment{} - a.GetFeedbackPullRequestsEnabled() - a = nil - a.GetFeedbackPullRequestsEnabled() -} - -func TestAssignment_GetID(tt *testing.T) { - tt.Parallel() - var zeroValue int64 - a := &Assignment{ID: &zeroValue} - a.GetID() - a = &Assignment{} - a.GetID() - a = nil - a.GetID() -} - -func TestAssignment_GetInvitationsEnabled(tt *testing.T) { - tt.Parallel() - var zeroValue bool - a := &Assignment{InvitationsEnabled: &zeroValue} - a.GetInvitationsEnabled() - a = &Assignment{} - a.GetInvitationsEnabled() - a = nil - a.GetInvitationsEnabled() -} - -func TestAssignment_GetInviteLink(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{InviteLink: &zeroValue} - a.GetInviteLink() - a = &Assignment{} - a.GetInviteLink() - a = nil - a.GetInviteLink() -} - -func TestAssignment_GetLanguage(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{Language: &zeroValue} - a.GetLanguage() - a = &Assignment{} - a.GetLanguage() - a = nil - a.GetLanguage() -} - -func TestAssignment_GetMaxMembers(tt *testing.T) { - tt.Parallel() - var zeroValue int - a := &Assignment{MaxMembers: &zeroValue} - a.GetMaxMembers() - a = &Assignment{} - a.GetMaxMembers() - a = nil - a.GetMaxMembers() -} - -func TestAssignment_GetMaxTeams(tt *testing.T) { - tt.Parallel() - var zeroValue int - a := &Assignment{MaxTeams: &zeroValue} - a.GetMaxTeams() - a = &Assignment{} - a.GetMaxTeams() - a = nil - a.GetMaxTeams() -} - -func TestAssignment_GetPassing(tt *testing.T) { - tt.Parallel() - var zeroValue int - a := &Assignment{Passing: &zeroValue} - a.GetPassing() - a = &Assignment{} - a.GetPassing() - a = nil - a.GetPassing() -} - -func TestAssignment_GetPublicRepo(tt *testing.T) { - tt.Parallel() - var zeroValue bool - a := &Assignment{PublicRepo: &zeroValue} - a.GetPublicRepo() - a = &Assignment{} - a.GetPublicRepo() - a = nil - a.GetPublicRepo() -} - -func TestAssignment_GetSlug(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{Slug: &zeroValue} - a.GetSlug() - a = &Assignment{} - a.GetSlug() - a = nil - a.GetSlug() -} - -func TestAssignment_GetStarterCodeRepository(tt *testing.T) { - tt.Parallel() - a := &Assignment{} - a.GetStarterCodeRepository() - a = nil - a.GetStarterCodeRepository() -} - -func TestAssignment_GetStudentsAreRepoAdmins(tt *testing.T) { - tt.Parallel() - var zeroValue bool - a := &Assignment{StudentsAreRepoAdmins: &zeroValue} - a.GetStudentsAreRepoAdmins() - a = &Assignment{} - a.GetStudentsAreRepoAdmins() - a = nil - a.GetStudentsAreRepoAdmins() -} - -func TestAssignment_GetSubmitted(tt *testing.T) { - tt.Parallel() - var zeroValue int - a := &Assignment{Submitted: &zeroValue} - a.GetSubmitted() - a = &Assignment{} - a.GetSubmitted() - a = nil - a.GetSubmitted() -} - -func TestAssignment_GetTitle(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{Title: &zeroValue} - a.GetTitle() - a = &Assignment{} - a.GetTitle() - a = nil - a.GetTitle() -} - -func TestAssignment_GetType(tt *testing.T) { - tt.Parallel() - var zeroValue string - a := &Assignment{Type: &zeroValue} - a.GetType() - a = &Assignment{} - a.GetType() - a = nil - a.GetType() -} - func TestAttachment_GetBody(tt *testing.T) { tt.Parallel() var zeroValue string @@ -3532,6 +3329,209 @@ func TestClassroom_GetURL(tt *testing.T) { c.GetURL() } +func TestClassroomAssignment_GetAccepted(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &ClassroomAssignment{Accepted: &zeroValue} + c.GetAccepted() + c = &ClassroomAssignment{} + c.GetAccepted() + c = nil + c.GetAccepted() +} + +func TestClassroomAssignment_GetClassroom(tt *testing.T) { + tt.Parallel() + c := &ClassroomAssignment{} + c.GetClassroom() + c = nil + c.GetClassroom() +} + +func TestClassroomAssignment_GetDeadline(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + c := &ClassroomAssignment{Deadline: &zeroValue} + c.GetDeadline() + c = &ClassroomAssignment{} + c.GetDeadline() + c = nil + c.GetDeadline() +} + +func TestClassroomAssignment_GetEditor(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{Editor: &zeroValue} + c.GetEditor() + c = &ClassroomAssignment{} + c.GetEditor() + c = nil + c.GetEditor() +} + +func TestClassroomAssignment_GetFeedbackPullRequestsEnabled(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &ClassroomAssignment{FeedbackPullRequestsEnabled: &zeroValue} + c.GetFeedbackPullRequestsEnabled() + c = &ClassroomAssignment{} + c.GetFeedbackPullRequestsEnabled() + c = nil + c.GetFeedbackPullRequestsEnabled() +} + +func TestClassroomAssignment_GetID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + c := &ClassroomAssignment{ID: &zeroValue} + c.GetID() + c = &ClassroomAssignment{} + c.GetID() + c = nil + c.GetID() +} + +func TestClassroomAssignment_GetInvitationsEnabled(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &ClassroomAssignment{InvitationsEnabled: &zeroValue} + c.GetInvitationsEnabled() + c = &ClassroomAssignment{} + c.GetInvitationsEnabled() + c = nil + c.GetInvitationsEnabled() +} + +func TestClassroomAssignment_GetInviteLink(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{InviteLink: &zeroValue} + c.GetInviteLink() + c = &ClassroomAssignment{} + c.GetInviteLink() + c = nil + c.GetInviteLink() +} + +func TestClassroomAssignment_GetLanguage(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{Language: &zeroValue} + c.GetLanguage() + c = &ClassroomAssignment{} + c.GetLanguage() + c = nil + c.GetLanguage() +} + +func TestClassroomAssignment_GetMaxMembers(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &ClassroomAssignment{MaxMembers: &zeroValue} + c.GetMaxMembers() + c = &ClassroomAssignment{} + c.GetMaxMembers() + c = nil + c.GetMaxMembers() +} + +func TestClassroomAssignment_GetMaxTeams(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &ClassroomAssignment{MaxTeams: &zeroValue} + c.GetMaxTeams() + c = &ClassroomAssignment{} + c.GetMaxTeams() + c = nil + c.GetMaxTeams() +} + +func TestClassroomAssignment_GetPassing(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &ClassroomAssignment{Passing: &zeroValue} + c.GetPassing() + c = &ClassroomAssignment{} + c.GetPassing() + c = nil + c.GetPassing() +} + +func TestClassroomAssignment_GetPublicRepo(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &ClassroomAssignment{PublicRepo: &zeroValue} + c.GetPublicRepo() + c = &ClassroomAssignment{} + c.GetPublicRepo() + c = nil + c.GetPublicRepo() +} + +func TestClassroomAssignment_GetSlug(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{Slug: &zeroValue} + c.GetSlug() + c = &ClassroomAssignment{} + c.GetSlug() + c = nil + c.GetSlug() +} + +func TestClassroomAssignment_GetStarterCodeRepository(tt *testing.T) { + tt.Parallel() + c := &ClassroomAssignment{} + c.GetStarterCodeRepository() + c = nil + c.GetStarterCodeRepository() +} + +func TestClassroomAssignment_GetStudentsAreRepoAdmins(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &ClassroomAssignment{StudentsAreRepoAdmins: &zeroValue} + c.GetStudentsAreRepoAdmins() + c = &ClassroomAssignment{} + c.GetStudentsAreRepoAdmins() + c = nil + c.GetStudentsAreRepoAdmins() +} + +func TestClassroomAssignment_GetSubmitted(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &ClassroomAssignment{Submitted: &zeroValue} + c.GetSubmitted() + c = &ClassroomAssignment{} + c.GetSubmitted() + c = nil + c.GetSubmitted() +} + +func TestClassroomAssignment_GetTitle(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{Title: &zeroValue} + c.GetTitle() + c = &ClassroomAssignment{} + c.GetTitle() + c = nil + c.GetTitle() +} + +func TestClassroomAssignment_GetType(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &ClassroomAssignment{Type: &zeroValue} + c.GetType() + c = &ClassroomAssignment{} + c.GetType() + c = nil + c.GetType() +} + func TestClusterSSHKey_GetFingerprint(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index e2d8fcee015..0b27ee1817c 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -108,35 +108,6 @@ func TestArtifactPeriod_String(t *testing.T) { } } -func TestAssignment_String(t *testing.T) { - t.Parallel() - v := Assignment{ - ID: Ptr(int64(0)), - PublicRepo: Ptr(false), - Title: Ptr(""), - Type: Ptr(""), - InviteLink: Ptr(""), - InvitationsEnabled: Ptr(false), - Slug: Ptr(""), - StudentsAreRepoAdmins: Ptr(false), - FeedbackPullRequestsEnabled: Ptr(false), - MaxTeams: Ptr(0), - MaxMembers: Ptr(0), - Editor: Ptr(""), - Accepted: Ptr(0), - Submitted: Ptr(0), - Passing: Ptr(0), - Language: Ptr(""), - Deadline: &Timestamp{}, - StarterCodeRepository: &Repository{}, - Classroom: &Classroom{}, - } - want := `github.Assignment{ID:0, PublicRepo:false, Title:"", Type:"", InviteLink:"", InvitationsEnabled:false, Slug:"", StudentsAreRepoAdmins:false, FeedbackPullRequestsEnabled:false, MaxTeams:0, MaxMembers:0, Editor:"", Accepted:0, Submitted:0, Passing:0, Language:"", Deadline:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, StarterCodeRepository:github.Repository{}, Classroom:github.Classroom{}}` - if got := v.String(); got != want { - t.Errorf("Assignment.String = %v, want %v", got, want) - } -} - func TestAuthorization_String(t *testing.T) { t.Parallel() v := Authorization{ @@ -272,6 +243,35 @@ func TestClassroom_String(t *testing.T) { } } +func TestClassroomAssignment_String(t *testing.T) { + t.Parallel() + v := ClassroomAssignment{ + ID: Ptr(int64(0)), + PublicRepo: Ptr(false), + Title: Ptr(""), + Type: Ptr(""), + InviteLink: Ptr(""), + InvitationsEnabled: Ptr(false), + Slug: Ptr(""), + StudentsAreRepoAdmins: Ptr(false), + FeedbackPullRequestsEnabled: Ptr(false), + MaxTeams: Ptr(0), + MaxMembers: Ptr(0), + Editor: Ptr(""), + Accepted: Ptr(0), + Submitted: Ptr(0), + Passing: Ptr(0), + Language: Ptr(""), + Deadline: &Timestamp{}, + StarterCodeRepository: &Repository{}, + Classroom: &Classroom{}, + } + want := `github.ClassroomAssignment{ID:0, PublicRepo:false, Title:"", Type:"", InviteLink:"", InvitationsEnabled:false, Slug:"", StudentsAreRepoAdmins:false, FeedbackPullRequestsEnabled:false, MaxTeams:0, MaxMembers:0, Editor:"", Accepted:0, Submitted:0, Passing:0, Language:"", Deadline:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, StarterCodeRepository:github.Repository{}, Classroom:github.Classroom{}}` + if got := v.String(); got != want { + t.Errorf("ClassroomAssignment.String = %v, want %v", got, want) + } +} + func TestCodeOfConduct_String(t *testing.T) { t.Parallel() v := CodeOfConduct{