Skip to content

Commit e5f31b2

Browse files
refactor!: Rename AutolinkOptions to CreateAutolinkRequest, AddAutolink to CreateAutolink, and pass the body by value (#4399)
BREAKING CHANGE: `AutolinkOptions` is now `CreateAutolinkRequest` with non-pointer `KeyPrefix` and `URLTemplate`; `RepositoriesService.AddAutolink` is now `CreateAutolink` and passes `body` by value.
1 parent 9549a7a commit e5f31b2

6 files changed

Lines changed: 78 additions & 86 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ linters:
206206
- ActionsVariable
207207
- AddProjectItemOptions
208208
- AuthorizationRequest
209-
- AutolinkOptions
210209
- CodeScanningAlertState
211210
- CodespaceCreateForUserOptions
212211
- ConfigApplyOptions
@@ -276,7 +275,6 @@ linters:
276275
# TODO: fix and remove these exceptions.
277276
body-allowed-wrong-names:
278277
- AddProjectItemOptions
279-
- AutolinkOptions
280278
- CheckSuitePreferenceOptions
281279
- CodespaceCreateForUserOptions
282280
- ConfigApplyOptions

github/github-accessors.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 27 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos_autolinks.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"fmt"
1111
)
1212

13-
// AutolinkOptions specifies parameters for RepositoriesService.AddAutolink method.
14-
type AutolinkOptions struct {
15-
KeyPrefix *string `json:"key_prefix,omitempty"`
16-
URLTemplate *string `json:"url_template,omitempty"`
17-
IsAlphanumeric *bool `json:"is_alphanumeric,omitempty"`
13+
// CreateAutolinkRequest specifies parameters for RepositoriesService.CreateAutolink method.
14+
type CreateAutolinkRequest struct {
15+
KeyPrefix string `json:"key_prefix"`
16+
URLTemplate string `json:"url_template"`
17+
IsAlphanumeric *bool `json:"is_alphanumeric,omitempty"`
1818
}
1919

2020
// Autolink represents autolinks to external resources like Jira issues and Zendesk tickets.
@@ -48,13 +48,13 @@ func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo str
4848
return autolinks, resp, nil
4949
}
5050

51-
// AddAutolink creates an autolink reference for a repository.
51+
// CreateAutolink creates an autolink reference for a repository.
5252
// Users with admin access to the repository can create an autolink.
5353
//
5454
// GitHub API docs: https://docs.github.com/rest/repos/autolinks?apiVersion=2022-11-28#create-an-autolink-reference-for-a-repository
5555
//
5656
//meta:operation POST /repos/{owner}/{repo}/autolinks
57-
func (s *RepositoriesService) AddAutolink(ctx context.Context, owner, repo string, body *AutolinkOptions) (*Autolink, *Response, error) {
57+
func (s *RepositoriesService) CreateAutolink(ctx context.Context, owner, repo string, body CreateAutolinkRequest) (*Autolink, *Response, error) {
5858
u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
5959
req, err := s.client.NewRequest(ctx, "POST", u, body)
6060
if err != nil {

github/repos_autolinks_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ func TestRepositoriesService_ListAutolinks(t *testing.T) {
5252
})
5353
}
5454

55-
func TestRepositoriesService_AddAutolink(t *testing.T) {
55+
func TestRepositoriesService_CreateAutolink(t *testing.T) {
5656
t.Parallel()
5757
client, mux, _ := setup(t)
5858

59-
opt := &AutolinkOptions{
60-
KeyPrefix: Ptr("TICKET-"),
61-
URLTemplate: Ptr("https://example.com/TICKET?query=<num>"),
59+
body := CreateAutolinkRequest{
60+
KeyPrefix: "TICKET-",
61+
URLTemplate: "https://example.com/TICKET?query=<num>",
6262
IsAlphanumeric: Ptr(true),
6363
}
6464
mux.HandleFunc("/repos/o/r/autolinks", func(w http.ResponseWriter, r *http.Request) {
6565
testMethod(t, r, "POST")
66-
testJSONBody(t, r, opt)
66+
testJSONBody(t, r, body)
6767
w.WriteHeader(http.StatusOK)
6868
assertWrite(t, w, []byte(`
6969
{
@@ -74,9 +74,9 @@ func TestRepositoriesService_AddAutolink(t *testing.T) {
7474
`))
7575
})
7676
ctx := t.Context()
77-
autolink, _, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
77+
autolink, _, err := client.Repositories.CreateAutolink(ctx, "o", "r", body)
7878
if err != nil {
79-
t.Errorf("Repositories.AddAutolink returned error: %v", err)
79+
t.Errorf("Repositories.CreateAutolink returned error: %v", err)
8080
}
8181
want := &Autolink{
8282
KeyPrefix: Ptr("TICKET-"),
@@ -85,17 +85,17 @@ func TestRepositoriesService_AddAutolink(t *testing.T) {
8585
}
8686

8787
if !cmp.Equal(autolink, want) {
88-
t.Errorf("AddAutolink returned %+v, want %+v", autolink, want)
88+
t.Errorf("CreateAutolink returned %+v, want %+v", autolink, want)
8989
}
9090

91-
const methodName = "AddAutolink"
91+
const methodName = "CreateAutolink"
9292
testBadOptions(t, methodName, func() (err error) {
93-
_, _, err = client.Repositories.AddAutolink(ctx, "\n", "\n", opt)
93+
_, _, err = client.Repositories.CreateAutolink(ctx, "\n", "\n", body)
9494
return err
9595
})
9696

9797
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
98-
got, resp, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
98+
got, resp, err := client.Repositories.CreateAutolink(ctx, "o", "r", body)
9999
if got != nil {
100100
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
101101
}

test/integration/repos_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,21 @@ func TestRepositories_Autolinks(t *testing.T) {
189189

190190
repo := createRandomTestRepository(t, "", true)
191191

192-
opts := &github.AutolinkOptions{
193-
KeyPrefix: github.Ptr("TICKET-"),
194-
URLTemplate: github.Ptr("https://example.com/TICKET?query=<num>"),
192+
body := github.CreateAutolinkRequest{
193+
KeyPrefix: "TICKET-",
194+
URLTemplate: "https://example.com/TICKET?query=<num>",
195195
IsAlphanumeric: github.Ptr(false),
196196
}
197197

198-
actionlink, _, err := client.Repositories.AddAutolink(t.Context(), *repo.Owner.Login, *repo.Name, opts)
198+
actionlink, _, err := client.Repositories.CreateAutolink(t.Context(), *repo.Owner.Login, *repo.Name, body)
199199
if err != nil {
200-
t.Fatalf("Repositories.AddAutolink() returned error: %v", err)
200+
t.Fatalf("Repositories.CreateAutolink() returned error: %v", err)
201201
}
202202

203-
if !cmp.Equal(actionlink.KeyPrefix, opts.KeyPrefix) ||
204-
!cmp.Equal(actionlink.URLTemplate, opts.URLTemplate) ||
205-
!cmp.Equal(actionlink.IsAlphanumeric, opts.IsAlphanumeric) {
206-
t.Errorf("Repositories.AddAutolink() returned %+v, want %+v", actionlink, opts)
203+
if !cmp.Equal(actionlink.GetKeyPrefix(), body.KeyPrefix) ||
204+
!cmp.Equal(actionlink.GetURLTemplate(), body.URLTemplate) ||
205+
!cmp.Equal(actionlink.IsAlphanumeric, body.IsAlphanumeric) {
206+
t.Errorf("Repositories.CreateAutolink() returned %+v, want %+v", actionlink, body)
207207
}
208208

209209
_, err = client.Repositories.Delete(t.Context(), *repo.Owner.Login, *repo.Name)

0 commit comments

Comments
 (0)