Skip to content

Commit

Permalink
Update the response and options based on new API documentation and ex…
Browse files Browse the repository at this point in the history
…amples
  • Loading branch information
RicePatrick committed Aug 4, 2023
1 parent b5d9b2e commit 25e4cfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
37 changes: 14 additions & 23 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,36 +1415,27 @@ func (s *UsersService) DisableTwoFactor(user int, options ...RequestOptionFunc)
// GitLab API docs:
// https://docs.gitlab.com/ee/api/users.html#create-a-runner
type CreateUserRunnerOptions struct {
RunnerType string `json:"runner_type"`
GroupID int `json:"group_id"`
ProjectID int `json:"project_id"`
Description string `json:"description"`
Paused bool `json:"paused"`
Locked bool `json:"locked"`
RunUntagged bool `json:"run_untagged"`
TagList []string `json:"tag_list"`
AccessLevel string `json:"access_level"`
MaximumTimeout int `json:"maximum_timeout"`
RunnerType string `json:"runner_type"`
GroupID int `json:"group_id"`
ProjectID int `json:"project_id"`
Description string `json:"description"`
Paused bool `json:"paused"`
Locked bool `json:"locked"`
RunUntagged bool `json:"run_untagged"`
TagList []string `json:"tag_list"`
AccessLevel string `json:"access_level"`
MaximumTimeout int `json:"maximum_timeout"`
MaintenanceNote string `json:"maintenance_note"`
}

// UserRunner represents the a GitLab runner instance created using the user-based flow
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/users.html#create-a-runner
type UserRunner struct {
ID int `json:"id"`
Token string `json:"token"`
TokenExpiresAt string `json:"token_expires_at"`
RunnerType string `json:"runner_type"`
GroupID int `json:"group_id"`
ProjectID int `json:"project_id"`
Description string `json:"description"`
Paused bool `json:"paused"`
Locked bool `json:"locked"`
RunUntagged bool `json:"run_untagged"`
TagList []string `json:"tag_list"`
AccessLevel string `json:"access_level"`
MaximumTimeout int `json:"maximum_timeout"`
ID int `json:"id"`
Token string `json:"token"`
TokenExpiresAt string `json:"token_expires_at"`
}

// CreateUserRunner creates a new runner using the user-based flow and returns the authentication
Expand Down
6 changes: 4 additions & 2 deletions users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestCreateUserRunner(t *testing.T) {
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{"id": 1234, "runner_type": "project_type"}`))
w.Write([]byte(`{"id": 1234, "token": "glrt-1234567890ABCD", "token_expires_at":null}`))
})

createRunnerOpts := &CreateUserRunnerOptions{
Expand All @@ -674,5 +674,7 @@ func TestCreateUserRunner(t *testing.T) {
t.Errorf("Users.CreateUserRunner returned an error: %v", err)
}

require.Equal(t, "project_type", response.RunnerType)
require.Equal(t, 1234, response.ID)
require.Equal(t, "glrt-1234567890ABCD", response.Token)
require.Equal(t, "", response.TokenExpiresAt)
}

0 comments on commit 25e4cfa

Please sign in to comment.