Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit f4834ae

Browse files
committed
Bring the PR inline with the rest of the package
1 parent 25e4cfa commit f4834ae

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

users.go

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,51 +1409,46 @@ func (s *UsersService) DisableTwoFactor(user int, options ...RequestOptionFunc)
14091409
}
14101410
}
14111411

1412-
// CreateUserRunnerOptions represents the options available when creating a GitLab Runner
1413-
// using the new user-based flow.
1412+
// UserRunner represents a GitLab runner linked to the current user.
14141413
//
14151414
// GitLab API docs:
14161415
// https://docs.gitlab.com/ee/api/users.html#create-a-runner
1417-
type CreateUserRunnerOptions struct {
1418-
RunnerType string `json:"runner_type"`
1419-
GroupID int `json:"group_id"`
1420-
ProjectID int `json:"project_id"`
1421-
Description string `json:"description"`
1422-
Paused bool `json:"paused"`
1423-
Locked bool `json:"locked"`
1424-
RunUntagged bool `json:"run_untagged"`
1425-
TagList []string `json:"tag_list"`
1426-
AccessLevel string `json:"access_level"`
1427-
MaximumTimeout int `json:"maximum_timeout"`
1428-
MaintenanceNote string `json:"maintenance_note"`
1416+
type UserRunner struct {
1417+
ID int `json:"id"`
1418+
Token string `json:"token"`
1419+
TokenExpiresAt *time.Time `json:"token_expires_at"`
14291420
}
14301421

1431-
// UserRunner represents the a GitLab runner instance created using the user-based flow
1422+
// CreateUserRunnerOptions represents the available CreateUserRunner() options.
14321423
//
14331424
// GitLab API docs:
14341425
// https://docs.gitlab.com/ee/api/users.html#create-a-runner
1435-
type UserRunner struct {
1436-
ID int `json:"id"`
1437-
Token string `json:"token"`
1438-
TokenExpiresAt string `json:"token_expires_at"`
1426+
type CreateUserRunnerOptions struct {
1427+
RunnerType *string `url:"runner_type,omitempty" json:"runner_type,omitempty"`
1428+
GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
1429+
ProjectID *int `url:"project_id,omitempty" json:"project_id,omitempty"`
1430+
Description *string `url:"description,omitempty" json:"description,omitempty"`
1431+
Paused *bool `url:"paused,omitempty" json:"paused,omitempty"`
1432+
Locked *bool `url:"locked,omitempty" json:"locked,omitempty"`
1433+
RunUntagged *bool `url:"run_untagged,omitempty" json:"run_untagged,omitempty"`
1434+
TagList *[]string `url:"tag_list,omitempty" json:"tag_list,omitempty"`
1435+
AccessLevel *string `url:"access_level,omitempty" json:"access_level,omitempty"`
1436+
MaximumTimeout *int `url:"maximum_timeout,omitempty" json:"maximum_timeout,omitempty"`
1437+
MaintenanceNote *string `url:"maintenance_note,omitempty" json:"maintenance_note,omitempty"`
14391438
}
14401439

1441-
// CreateUserRunner creates a new runner using the user-based flow and returns the authentication
1442-
// token.
1440+
// CreateUserRunner creates a runner linked to the current user.
14431441
//
14441442
// GitLab API docs:
14451443
// https://docs.gitlab.com/ee/api/users.html#create-a-runner
1446-
func (s *UsersService) CreateUserRunner(runnerOpts *CreateUserRunnerOptions, options ...RequestOptionFunc) (*UserRunner, *Response, error) {
1447-
// The user who owns the runner comes from the access token used to authorize the request.
1448-
u := "user/runners"
1449-
1450-
req, err := s.client.NewRequest(http.MethodPost, u, runnerOpts, options)
1444+
func (s *UsersService) CreateUserRunner(opts *CreateUserRunnerOptions, options ...RequestOptionFunc) (*UserRunner, *Response, error) {
1445+
req, err := s.client.NewRequest(http.MethodPost, "user/runners", opts, options)
14511446
if err != nil {
14521447
return nil, nil, err
14531448
}
14541449

1455-
var r *UserRunner
1456-
resp, err := s.client.Do(req, &r)
1450+
r := new(UserRunner)
1451+
resp, err := s.client.Do(req, r)
14571452
if err != nil {
14581453
return nil, resp, err
14591454
}

users_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ func TestGetSingleSSHKeyForUser(t *testing.T) {
616616
"title": "Public key",
617617
"key": "ssh-rsa AAAA...",
618618
"created_at": "2014-08-01T14:47:39.080Z"
619-
}
620-
`)
619+
}`)
621620
})
622621

623622
sshKey, _, err := client.Users.GetSSHKeyForUser(1, 1)
@@ -661,12 +660,17 @@ func TestCreateUserRunner(t *testing.T) {
661660
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
662661
testMethod(t, r, http.MethodPost)
663662
w.WriteHeader(http.StatusCreated)
664-
w.Write([]byte(`{"id": 1234, "token": "glrt-1234567890ABCD", "token_expires_at":null}`))
663+
w.Write([]byte(`
664+
{
665+
"id": 1234,
666+
"token": "glrt-1234567890ABCD",
667+
"token_expires_at":null
668+
}`))
665669
})
666670

667671
createRunnerOpts := &CreateUserRunnerOptions{
668-
RunnerType: "project_type",
669-
ProjectID: 1,
672+
ProjectID: Int(1),
673+
RunnerType: String("project_type"),
670674
}
671675

672676
response, _, err := client.Users.CreateUserRunner(createRunnerOpts)
@@ -676,5 +680,5 @@ func TestCreateUserRunner(t *testing.T) {
676680

677681
require.Equal(t, 1234, response.ID)
678682
require.Equal(t, "glrt-1234567890ABCD", response.Token)
679-
require.Equal(t, "", response.TokenExpiresAt)
683+
require.Equal(t, (*time.Time)(nil), response.TokenExpiresAt)
680684
}

0 commit comments

Comments
 (0)