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

Commit def3c90

Browse files
authored
Merge pull request #1870 from PatrickRice-KSC/add-restrict-pipeline-cancellation-support
Add support for ci_restrict_pipeline_cancellation_role attribute to Projects
2 parents 0826177 + 0342a41 commit def3c90

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

projects.go

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type Project struct {
139139
CIJobTokenScopeEnabled bool `json:"ci_job_token_scope_enabled"`
140140
CIOptInJWT bool `json:"ci_opt_in_jwt"`
141141
CIAllowForkPipelinesToRunInParentProject bool `json:"ci_allow_fork_pipelines_to_run_in_parent_project"`
142+
CIRestrictPipelineCancellationRole AccessControlValue `json:"ci_restrict_pipeline_cancellation_role"`
142143
PublicJobs bool `json:"public_jobs"`
143144
BuildTimeout int `json:"build_timeout"`
144145
AutoCancelPendingPipelines string `json:"auto_cancel_pending_pipelines"`
@@ -842,6 +843,7 @@ type EditProjectOptions struct {
842843
CIDefaultGitDepth *int `url:"ci_default_git_depth,omitempty" json:"ci_default_git_depth,omitempty"`
843844
CIForwardDeploymentEnabled *bool `url:"ci_forward_deployment_enabled,omitempty" json:"ci_forward_deployment_enabled,omitempty"`
844845
CISeperateCache *bool `url:"ci_separated_caches,omitempty" json:"ci_separated_caches,omitempty"`
846+
CIRestrictPipelineCancellationRole *AccessControlValue `url:"ci_restrict_pipeline_cancellation_role,omitempty" json:"ci_restrict_pipeline_cancellation_role,omitempty"`
845847
ContainerExpirationPolicyAttributes *ContainerExpirationPolicyAttributes `url:"container_expiration_policy_attributes,omitempty" json:"container_expiration_policy_attributes,omitempty"`
846848
ContainerRegistryAccessLevel *AccessControlValue `url:"container_registry_access_level,omitempty" json:"container_registry_access_level,omitempty"`
847849
DefaultBranch *string `url:"default_branch,omitempty" json:"default_branch,omitempty"`

projects_test.go

+52-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"fmt"
23+
"io"
2324
"net/http"
2425
"os"
2526
"reflect"
@@ -276,6 +277,53 @@ func TestListOwnedProjects(t *testing.T) {
276277
}
277278
}
278279

280+
func TestEditProject(t *testing.T) {
281+
mux, client := setup(t)
282+
283+
var developerAccessLevel AccessControlValue = "developer"
284+
opt := &EditProjectOptions{
285+
CIRestrictPipelineCancellationRole: Ptr(developerAccessLevel),
286+
}
287+
288+
// Store whether we've set the restrict value in our edit properly
289+
restrictValueSet := false
290+
291+
mux.HandleFunc("/api/v4/projects/1", func(w http.ResponseWriter, r *http.Request) {
292+
testMethod(t, r, http.MethodPut)
293+
294+
// Check that our request properly included ci_restrict_pipeline_cancellation_role
295+
body, err := io.ReadAll(r.Body)
296+
if err != nil {
297+
t.Fatalf("Unable to read body properly. Error: %v", err)
298+
}
299+
300+
// Set the value to check if our value is included
301+
restrictValueSet = strings.Contains(string(body), "ci_restrict_pipeline_cancellation_role")
302+
303+
// Print the start of the mock example from https://docs.gitlab.com/ee/api/projects.html#edit-project
304+
// including the attribute we edited
305+
fmt.Fprint(w, `
306+
{
307+
"id": 1,
308+
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
309+
"description_html": "<p data-sourcepos=\"1:1-1:56\" dir=\"auto\">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
310+
"default_branch": "main",
311+
"visibility": "private",
312+
"ssh_url_to_repo": "[email protected]:diaspora/diaspora-project-site.git",
313+
"http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git",
314+
"web_url": "http://example.com/diaspora/diaspora-project-site",
315+
"readme_url": "http://example.com/diaspora/diaspora-project-site/blob/main/README.md",
316+
"ci_restrict_pipeline_cancellation_role": "developer"
317+
}`)
318+
})
319+
320+
project, resp, err := client.Projects.EditProject(1, opt)
321+
assert.NoError(t, err)
322+
assert.Equal(t, http.StatusOK, resp.StatusCode)
323+
assert.Equal(t, true, restrictValueSet)
324+
assert.Equal(t, developerAccessLevel, project.CIRestrictPipelineCancellationRole)
325+
}
326+
279327
func TestListStarredProjects(t *testing.T) {
280328
mux, client := setup(t)
281329

@@ -323,6 +371,7 @@ func TestGetProjectByID(t *testing.T) {
323371
"name_regex_keep": null,
324372
"next_run_at": "2020-01-07T21:42:58.658Z"
325373
},
374+
"ci_restrict_pipeline_cancellation_role": "developer",
326375
"packages_enabled": false,
327376
"build_coverage_regex": "Total.*([0-9]{1,3})%"
328377
}`)
@@ -336,8 +385,9 @@ func TestGetProjectByID(t *testing.T) {
336385
Cadence: "7d",
337386
NextRunAt: &wantTimestamp,
338387
},
339-
PackagesEnabled: false,
340-
BuildCoverageRegex: `Total.*([0-9]{1,3})%`,
388+
PackagesEnabled: false,
389+
BuildCoverageRegex: `Total.*([0-9]{1,3})%`,
390+
CIRestrictPipelineCancellationRole: "developer",
341391
}
342392

343393
project, _, err := client.Projects.GetProject(1, nil)

0 commit comments

Comments
 (0)