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
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions github/github-iterators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions github/github-iterators_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions github/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,26 @@ func (l License) String() string {
return Stringify(l)
}

// ListLicensesOptions specifies the optional parameters to the LicensesService.List method.
type ListLicensesOptions struct {
Featured *bool `url:"featured,omitempty"`

ListOptions
}

// List popular open source licenses.
//
// GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses
//
//meta:operation GET /licenses
func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
req, err := s.client.NewRequest("GET", "licenses", nil)
func (s *LicensesService) List(ctx context.Context, opts *ListLicensesOptions) ([]*License, *Response, error) {
u := "licenses"
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
}
Expand Down
6 changes: 4 additions & 2 deletions github/licenses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ func TestLicensesService_List(t *testing.T) {

mux.HandleFunc("/licenses", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"featured": "true", "page": "2", "per_page": "20"})
fmt.Fprint(w, `[{"key":"mit","name":"MIT","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}]`)
})

opts := &ListLicensesOptions{Featured: Ptr(true), ListOptions: ListOptions{Page: 2, PerPage: 20}}
ctx := t.Context()
licenses, _, err := client.Licenses.List(ctx)
licenses, _, err := client.Licenses.List(ctx, opts)
if err != nil {
t.Errorf("Licenses.List returned error: %v", err)
}
Expand All @@ -137,7 +139,7 @@ func TestLicensesService_List(t *testing.T) {

const methodName = "List"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Licenses.List(ctx)
got, resp, err := client.Licenses.List(ctx, opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
36 changes: 36 additions & 0 deletions test/integration/licences_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2026 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.

//go:build integration

package integration

import (
"testing"

"github.com/google/go-github/v82/github"
)

func TestLicenses_ListIter(t *testing.T) {
opts := &github.ListLicensesOptions{
Featured: github.Ptr(true),
ListOptions: github.ListOptions{
Page: 1,
PerPage: 1,
},
}

var featuredLicensesCount int
for _, err := range client.Licenses.ListIter(t.Context(), opts) {
if err != nil {
t.Fatalf("Licenses.ListIter returned error during iteration: %v", err)
}
featuredLicensesCount++
}

if featuredLicensesCount < 2 {
t.Errorf("Licenses.ListIter returned fewer than 2 featured licenses: %v", featuredLicensesCount)
}
}
Loading