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
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ linters:
- ActionsVariable
- AddProjectItemOptions
- AuthorizationRequest
- AutolinkOptions
- CodeScanningAlertState
- CodespaceCreateForUserOptions
- ConfigApplyOptions
Expand Down Expand Up @@ -276,7 +275,6 @@ linters:
# TODO: fix and remove these exceptions.
body-allowed-wrong-names:
- AddProjectItemOptions
- AutolinkOptions
- CheckSuitePreferenceOptions
- CodespaceCreateForUserOptions
- ConfigApplyOptions
Expand Down
48 changes: 24 additions & 24 deletions github/github-accessors.go

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

60 changes: 27 additions & 33 deletions github/github-accessors_test.go

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

14 changes: 7 additions & 7 deletions github/repos_autolinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"fmt"
)

// AutolinkOptions specifies parameters for RepositoriesService.AddAutolink method.
type AutolinkOptions struct {
KeyPrefix *string `json:"key_prefix,omitempty"`
URLTemplate *string `json:"url_template,omitempty"`
IsAlphanumeric *bool `json:"is_alphanumeric,omitempty"`
// CreateAutolinkRequest specifies parameters for RepositoriesService.CreateAutolink method.
type CreateAutolinkRequest struct {
KeyPrefix string `json:"key_prefix"`
URLTemplate string `json:"url_template"`
IsAlphanumeric *bool `json:"is_alphanumeric,omitempty"`
}

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

// AddAutolink creates an autolink reference for a repository.
// CreateAutolink creates an autolink reference for a repository.
// Users with admin access to the repository can create an autolink.
//
// GitHub API docs: https://docs.github.com/rest/repos/autolinks?apiVersion=2022-11-28#create-an-autolink-reference-for-a-repository
//
//meta:operation POST /repos/{owner}/{repo}/autolinks
func (s *RepositoriesService) AddAutolink(ctx context.Context, owner, repo string, body *AutolinkOptions) (*Autolink, *Response, error) {
func (s *RepositoriesService) CreateAutolink(ctx context.Context, owner, repo string, body CreateAutolinkRequest) (*Autolink, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions github/repos_autolinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ func TestRepositoriesService_ListAutolinks(t *testing.T) {
})
}

func TestRepositoriesService_AddAutolink(t *testing.T) {
func TestRepositoriesService_CreateAutolink(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

opt := &AutolinkOptions{
KeyPrefix: Ptr("TICKET-"),
URLTemplate: Ptr("https://example.com/TICKET?query=<num>"),
body := CreateAutolinkRequest{
KeyPrefix: "TICKET-",
URLTemplate: "https://example.com/TICKET?query=<num>",
IsAlphanumeric: Ptr(true),
}
mux.HandleFunc("/repos/o/r/autolinks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testJSONBody(t, r, opt)
testJSONBody(t, r, body)
w.WriteHeader(http.StatusOK)
assertWrite(t, w, []byte(`
{
Expand All @@ -74,9 +74,9 @@ func TestRepositoriesService_AddAutolink(t *testing.T) {
`))
})
ctx := t.Context()
autolink, _, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
autolink, _, err := client.Repositories.CreateAutolink(ctx, "o", "r", body)
if err != nil {
t.Errorf("Repositories.AddAutolink returned error: %v", err)
t.Errorf("Repositories.CreateAutolink returned error: %v", err)
}
want := &Autolink{
KeyPrefix: Ptr("TICKET-"),
Expand All @@ -85,17 +85,17 @@ func TestRepositoriesService_AddAutolink(t *testing.T) {
}

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

const methodName = "AddAutolink"
const methodName = "CreateAutolink"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Repositories.AddAutolink(ctx, "\n", "\n", opt)
_, _, err = client.Repositories.CreateAutolink(ctx, "\n", "\n", body)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Repositories.AddAutolink(ctx, "o", "r", opt)
got, resp, err := client.Repositories.CreateAutolink(ctx, "o", "r", body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
18 changes: 9 additions & 9 deletions test/integration/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,21 @@ func TestRepositories_Autolinks(t *testing.T) {

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

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

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

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

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