Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the commit actions to proper options #955

Merged
merged 1 commit into from Oct 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 24 additions & 34 deletions commits.go
Expand Up @@ -104,30 +104,6 @@ func (s *CommitsService) ListCommits(pid interface{}, opt *ListCommitsOptions, o
return c, resp, err
}

// FileAction represents the available actions that can be performed on a file.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
type FileAction string

// The available file actions.
const (
FileCreate FileAction = "create"
FileDelete FileAction = "delete"
FileMove FileAction = "move"
FileUpdate FileAction = "update"
)

// CommitAction represents a single file action within a commit.
type CommitAction struct {
Action FileAction `url:"action" json:"action"`
FilePath string `url:"file_path" json:"file_path"`
PreviousPath string `url:"previous_path,omitempty" json:"previous_path,omitempty"`
Content string `url:"content,omitempty" json:"content,omitempty"`
Encoding string `url:"encoding,omitempty" json:"encoding,omitempty"`
LastCommitID string `url:"last_commit_id,omitempty" json:"last_commit_id,omitempty"`
ExecuteFilemode bool `url:"execute_filemode,omitempty" json:"execute_filemode,omitempty"`
}

// CommitRef represents the reference of branches/tags in a commit.
//
// GitLab API docs:
Expand Down Expand Up @@ -203,16 +179,30 @@ func (s *CommitsService) GetCommit(pid interface{}, sha string, options ...Reque
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
type CreateCommitOptions struct {
Branch *string `url:"branch" json:"branch"`
CommitMessage *string `url:"commit_message" json:"commit_message"`
StartBranch *string `url:"start_branch,omitempty" json:"start_branch,omitempty"`
StartSHA *string `url:"start_sha,omitempty" json:"start_sha,omitempty"`
StartProject *string `url:"start_project,omitempty" json:"start_project,omitempty"`
Actions []*CommitAction `url:"actions" json:"actions"`
AuthorEmail *string `url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName *string `url:"author_name,omitempty" json:"author_name,omitempty"`
Stats *bool `url:"stats,omitempty" json:"stats,omitempty"`
Force *bool `url:"force,omitempty" json:"force,omitempty"`
Branch *string `url:"branch,omitempty" json:"branch,omitempty"`
CommitMessage *string `url:"commit_message,omitempty" json:"commit_message,omitempty"`
StartBranch *string `url:"start_branch,omitempty" json:"start_branch,omitempty"`
StartSHA *string `url:"start_sha,omitempty" json:"start_sha,omitempty"`
StartProject *string `url:"start_project,omitempty" json:"start_project,omitempty"`
Actions []*CommitActionOptions `url:"actions,omitempty" json:"actions,omitempty"`
AuthorEmail *string `url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName *string `url:"author_name,omitempty" json:"author_name,omitempty"`
Stats *bool `url:"stats,omitempty" json:"stats,omitempty"`
Force *bool `url:"force,omitempty" json:"force,omitempty"`
}

// CommitActionOptions represents the available options for a new single
// file action.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
type CommitActionOptions struct {
Action *FileAction `url:"action,omitempty" json:"action,omitempty"`
FilePath *string `url:"file_path,omitempty" json:"file_path,omitempty"`
PreviousPath *string `url:"previous_path,omitempty" json:"previous_path,omitempty"`
Content *string `url:"content,omitempty" json:"content,omitempty"`
Encoding *string `url:"encoding,omitempty" json:"encoding,omitempty"`
LastCommitID *string `url:"last_commit_id,omitempty" json:"last_commit_id,omitempty"`
ExecuteFilemode *bool `url:"execute_filemode,omitempty" json:"execute_filemode,omitempty"`
}

// CreateCommit creates a commit with multiple files and actions.
Expand Down
13 changes: 13 additions & 0 deletions types.go
Expand Up @@ -105,6 +105,19 @@ func DeploymentStatus(v DeploymentStatusValue) *DeploymentStatusValue {
return p
}

// FileAction represents the available actions that can be performed on a file.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
type FileAction string

// The available file actions.
const (
FileCreate FileAction = "create"
FileDelete FileAction = "delete"
FileMove FileAction = "move"
FileUpdate FileAction = "update"
)

// ISOTime represents an ISO 8601 formatted date
type ISOTime time.Time

Expand Down