Commit 3de359c6 authored by Patrick Rice's avatar Patrick Rice ❄️
Browse files

Merge branch 'refac1' into 'main'

refactor: moved comments to interface 1

Closes #2210

See merge request !2706
parents ec5b01ed 7c9493ab
Loading
Loading
Loading
Loading
Loading
+80 −80
Original line number Diff line number Diff line
@@ -24,22 +24,102 @@ import (

type (
	JobsServiceInterface interface {
		// ListProjectJobs gets a list of jobs in a project.
		//
		// The scope of jobs to show, one or array of: created, pending, running,
		// failed, success, canceled, skipped; showing all jobs if none provided
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#list-project-jobs
		ListProjectJobs(pid any, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error)
		// ListPipelineJobs gets a list of jobs for specific pipeline in a
		// project. If the pipeline ID is not found, it will respond with 404.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#list-pipeline-jobs
		ListPipelineJobs(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error)
		// ListPipelineBridges gets a list of bridges for specific pipeline in a
		// project.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#list-pipeline-trigger-jobs
		ListPipelineBridges(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Bridge, *Response, error)
		// GetJobTokensJob retrieves the job that generated a job token.
		//
		// GitLab API docs: https://docs.gitlab.com/api/jobs/#get-job-tokens-job
		GetJobTokensJob(opts *GetJobTokensJobOptions, options ...RequestOptionFunc) (*Job, *Response, error)
		// GetJob gets a single job of a project.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#get-a-single-job
		GetJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error)
		// GetJobArtifacts gets jobs artifacts of a project
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#get-job-artifacts
		GetJobArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error)
		// DownloadArtifactsFile downloads the artifacts file from the given
		// reference name and job provided the job finished successfully.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#download-the-artifacts-archive
		DownloadArtifactsFile(pid any, refName string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error)
		// DownloadSingleArtifactsFile downloads a file from the artifacts from the
		// given reference name and job provided the job finished successfully.
		// Only a single file is going to be extracted from the archive and streamed
		// to a client.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-job-id
		DownloadSingleArtifactsFile(pid any, jobID int64, artifactPath string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error)
		// DownloadSingleArtifactsFileByTagOrBranch downloads a single file from
		// a job's artifacts in the latest successful pipeline using the reference name.
		// The file is extracted from the archive and streamed to the client.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-from-specific-tag-or-branch
		DownloadSingleArtifactsFileByTagOrBranch(pid any, refName string, artifactPath string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error)
		// GetTraceFile gets a trace of a specific job of a project
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#get-a-log-file
		GetTraceFile(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error)
		// CancelJob cancels a single job of a project.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#cancel-a-job
		CancelJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error)
		// RetryJob retries a single job of a project
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#retry-a-job
		RetryJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error)
		// EraseJob erases a single job of a project, removes a job
		// artifacts and a job trace.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#erase-a-job
		EraseJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error)
		// KeepArtifacts prevents artifacts from being deleted when
		// expiration is set.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#keep-artifacts
		KeepArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error)
		// PlayJob triggers a manual action to start a job.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/jobs/#run-a-job
		PlayJob(pid any, jobID int64, opt *PlayJobOptions, options ...RequestOptionFunc) (*Job, *Response, error)
		// DeleteArtifacts deletes artifacts of a job
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts
		DeleteArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Response, error)
		// DeleteProjectArtifacts deletes artifacts eligible for deletion in a project
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts
		DeleteProjectArtifacts(pid any, options ...RequestOptionFunc) (*Response, error)
	}

@@ -161,13 +241,6 @@ type ListJobsOptions struct {
	IncludeRetried *bool              `url:"include_retried,omitempty" json:"include_retried,omitempty"`
}

// ListProjectJobs gets a list of jobs in a project.
//
// The scope of jobs to show, one or array of: created, pending, running,
// failed, success, canceled, skipped; showing all jobs if none provided
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#list-project-jobs
func (s *JobsService) ListProjectJobs(pid any, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) {
	return do[[]*Job](s.client,
		withMethod(http.MethodGet),
@@ -177,11 +250,6 @@ func (s *JobsService) ListProjectJobs(pid any, opts *ListJobsOptions, options ..
	)
}

// ListPipelineJobs gets a list of jobs for specific pipeline in a
// project. If the pipeline ID is not found, it will respond with 404.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#list-pipeline-jobs
func (s *JobsService) ListPipelineJobs(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) {
	return do[[]*Job](s.client,
		withMethod(http.MethodGet),
@@ -191,11 +259,6 @@ func (s *JobsService) ListPipelineJobs(pid any, pipelineID int64, opts *ListJobs
	)
}

// ListPipelineBridges gets a list of bridges for specific pipeline in a
// project.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#list-pipeline-trigger-jobs
func (s *JobsService) ListPipelineBridges(pid any, pipelineID int64, opts *ListJobsOptions, options ...RequestOptionFunc) ([]*Bridge, *Response, error) {
	return do[[]*Bridge](s.client,
		withMethod(http.MethodGet),
@@ -212,9 +275,6 @@ type GetJobTokensJobOptions struct {
	JobToken *string `url:"job_token,omitempty" json:"job_token,omitempty"`
}

// GetJobTokensJob retrieves the job that generated a job token.
//
// GitLab API docs: https://docs.gitlab.com/api/jobs/#get-job-tokens-job
func (s *JobsService) GetJobTokensJob(opts *GetJobTokensJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodGet),
@@ -224,10 +284,6 @@ func (s *JobsService) GetJobTokensJob(opts *GetJobTokensJobOptions, options ...R
	)
}

// GetJob gets a single job of a project.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#get-a-single-job
func (s *JobsService) GetJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodGet),
@@ -237,10 +293,6 @@ func (s *JobsService) GetJob(pid any, jobID int64, options ...RequestOptionFunc)
	)
}

// GetJobArtifacts get jobs artifacts of a project
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#get-job-artifacts
func (s *JobsService) GetJobArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
	b, resp, err := do[bytes.Buffer](s.client,
		withPath("projects/%s/jobs/%d/artifacts", ProjectID{pid}, jobID),
@@ -259,11 +311,6 @@ type DownloadArtifactsFileOptions struct {
	Job *string `url:"job" json:"job"`
}

// DownloadArtifactsFile download the artifacts file from the given
// reference name and job provided the job finished successfully.
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#download-the-artifacts-archive
func (s *JobsService) DownloadArtifactsFile(pid any, refName string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
	b, resp, err := do[bytes.Buffer](s.client,
		withPath("projects/%s/jobs/artifacts/%s/download", ProjectID{pid}, NoEscape{refName}),
@@ -274,13 +321,6 @@ func (s *JobsService) DownloadArtifactsFile(pid any, refName string, opt *Downlo
	return bytes.NewReader(b.Bytes()), resp, err
}

// DownloadSingleArtifactsFile download a file from the artifacts from the
// given reference name and job provided the job finished successfully.
// Only a single file is going to be extracted from the archive and streamed
// to a client.
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-by-job-id
func (s *JobsService) DownloadSingleArtifactsFile(pid any, jobID int64, artifactPath string, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
	b, resp, err := do[bytes.Buffer](s.client,
		withPath("projects/%s/jobs/%d/artifacts/%s", ProjectID{pid}, jobID, NoEscape{artifactPath}),
@@ -290,12 +330,6 @@ func (s *JobsService) DownloadSingleArtifactsFile(pid any, jobID int64, artifact
	return bytes.NewReader(b.Bytes()), resp, err
}

// DownloadSingleArtifactsFileByTagOrBranch downloads a single file from
// a job’s artifacts in the latest successful pipeline using the reference name.
// The file is extracted from the archive and streamed to the client.
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#download-a-single-artifact-file-from-specific-tag-or-branch
func (s *JobsService) DownloadSingleArtifactsFileByTagOrBranch(pid any, refName string, artifactPath string, opt *DownloadArtifactsFileOptions, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
	b, resp, err := do[bytes.Buffer](s.client,
		withPath("projects/%s/jobs/artifacts/%s/raw/%s", ProjectID{pid}, refName, NoEscape{artifactPath}),
@@ -306,10 +340,6 @@ func (s *JobsService) DownloadSingleArtifactsFileByTagOrBranch(pid any, refName
	return bytes.NewReader(b.Bytes()), resp, err
}

// GetTraceFile gets a trace of a specific job of a project
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#get-a-log-file
func (s *JobsService) GetTraceFile(pid any, jobID int64, options ...RequestOptionFunc) (*bytes.Reader, *Response, error) {
	b, resp, err := do[bytes.Buffer](s.client,
		withPath("projects/%s/jobs/%d/trace", ProjectID{pid}, jobID),
@@ -319,10 +349,6 @@ func (s *JobsService) GetTraceFile(pid any, jobID int64, options ...RequestOptio
	return bytes.NewReader(b.Bytes()), resp, err
}

// CancelJob cancels a single job of a project.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#cancel-a-job
func (s *JobsService) CancelJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodPost),
@@ -332,10 +358,6 @@ func (s *JobsService) CancelJob(pid any, jobID int64, options ...RequestOptionFu
	)
}

// RetryJob retries a single job of a project
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#retry-a-job
func (s *JobsService) RetryJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodPost),
@@ -345,11 +367,6 @@ func (s *JobsService) RetryJob(pid any, jobID int64, options ...RequestOptionFun
	)
}

// EraseJob erases a single job of a project, removes a job
// artifacts and a job trace.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#erase-a-job
func (s *JobsService) EraseJob(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodPost),
@@ -359,11 +376,6 @@ func (s *JobsService) EraseJob(pid any, jobID int64, options ...RequestOptionFun
	)
}

// KeepArtifacts prevents artifacts from being deleted when
// expiration is set.
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#keep-artifacts
func (s *JobsService) KeepArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodPost),
@@ -391,10 +403,6 @@ type JobVariableOptions struct {
	VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
}

// PlayJob triggers a manual action to start a job.
//
// GitLab API docs:
// https://docs.gitlab.com/api/jobs/#run-a-job
func (s *JobsService) PlayJob(pid any, jobID int64, opt *PlayJobOptions, options ...RequestOptionFunc) (*Job, *Response, error) {
	return do[*Job](s.client,
		withMethod(http.MethodPost),
@@ -404,10 +412,6 @@ func (s *JobsService) PlayJob(pid any, jobID int64, opt *PlayJobOptions, options
	)
}

// DeleteArtifacts delete artifacts of a job
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts
func (s *JobsService) DeleteArtifacts(pid any, jobID int64, options ...RequestOptionFunc) (*Response, error) {
	_, resp, err := do[none](s.client,
		withMethod(http.MethodDelete),
@@ -418,10 +422,6 @@ func (s *JobsService) DeleteArtifacts(pid any, jobID int64, options ...RequestOp
	return resp, err
}

// DeleteProjectArtifacts delete artifacts eligible for deletion in a project
//
// GitLab API docs:
// https://docs.gitlab.com/api/job_artifacts/#delete-job-artifacts
func (s *JobsService) DeleteProjectArtifacts(pid any, options ...RequestOptionFunc) (*Response, error) {
	_, resp, err := do[none](s.client,
		withMethod(http.MethodDelete),
+20 −20
Original line number Diff line number Diff line
@@ -23,10 +23,30 @@ import (

type (
	ProjectVariablesServiceInterface interface {
		// ListVariables gets a list of all variables in a project.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/project_level_variables/#list-project-variables
		ListVariables(pid any, opt *ListProjectVariablesOptions, options ...RequestOptionFunc) ([]*ProjectVariable, *Response, error)
		// GetVariable gets a variable.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/project_level_variables/#get-a-single-variable
		GetVariable(pid any, key string, opt *GetProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error)
		// CreateVariable creates a new project variable.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/project_level_variables/#create-a-variable
		CreateVariable(pid any, opt *CreateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error)
		// UpdateVariable updates a project's variable.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/project_level_variables/#update-a-variable
		UpdateVariable(pid any, key string, opt *UpdateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error)
		// RemoveVariable removes a project's variable.
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/project_level_variables/#delete-a-variable
		RemoveVariable(pid any, key string, opt *RemoveProjectVariableOptions, options ...RequestOptionFunc) (*Response, error)
	}

@@ -76,10 +96,6 @@ type ListProjectVariablesOptions struct {
	ListOptions
}

// ListVariables gets a list of all variables in a project.
//
// GitLab API docs:
// https://docs.gitlab.com/api/project_level_variables/#list-project-variables
func (s *ProjectVariablesService) ListVariables(pid any, opt *ListProjectVariablesOptions, options ...RequestOptionFunc) ([]*ProjectVariable, *Response, error) {
	return do[[]*ProjectVariable](s.client,
		withPath("projects/%s/variables", ProjectID{pid}),
@@ -97,10 +113,6 @@ type GetProjectVariableOptions struct {
	Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
}

// GetVariable gets a variable.
//
// GitLab API docs:
// https://docs.gitlab.com/api/project_level_variables/#get-a-single-variable
func (s *ProjectVariablesService) GetVariable(pid any, key string, opt *GetProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
	return do[*ProjectVariable](s.client,
		withPath("projects/%s/variables/%s", ProjectID{pid}, url.PathEscape(key)),
@@ -126,10 +138,6 @@ type CreateProjectVariableOptions struct {
	VariableType     *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
}

// CreateVariable creates a new project variable.
//
// GitLab API docs:
// https://docs.gitlab.com/api/project_level_variables/#create-a-variable
func (s *ProjectVariablesService) CreateVariable(pid any, opt *CreateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
	return do[*ProjectVariable](s.client,
		withMethod(http.MethodPost),
@@ -155,10 +163,6 @@ type UpdateProjectVariableOptions struct {
	VariableType     *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
}

// UpdateVariable updates a project's variable.
//
// GitLab API docs:
// https://docs.gitlab.com/api/project_level_variables/#update-a-variable
func (s *ProjectVariablesService) UpdateVariable(pid any, key string, opt *UpdateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
	return do[*ProjectVariable](s.client,
		withMethod(http.MethodPut),
@@ -177,10 +181,6 @@ type RemoveProjectVariableOptions struct {
	Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
}

// RemoveVariable removes a project's variable.
//
// GitLab API docs:
// https://docs.gitlab.com/api/project_level_variables/#delete-a-variable
func (s *ProjectVariablesService) RemoveVariable(pid any, key string, opt *RemoveProjectVariableOptions, options ...RequestOptionFunc) (*Response, error) {
	_, resp, err := do[none](s.client,
		withMethod(http.MethodDelete),
+63 −63

File changed.

Preview size limit exceeded, changes collapsed.