Skip to content

Commit c016e21

Browse files
authored
Allow merge on skipped pipeline (#705)
1 parent 6152a19 commit c016e21

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

docs/data-sources/projects.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Provide details about a list of projects in the Gitlab provider. Listing all projects and group projects with [project filtering](https://docs.gitlab.com/ee/api/projects.html#list-user-projects) or [group project filtering](https://docs.gitlab.com/ee/api/groups.html#list-a-groups-projects) is supported.
44

5-
> **NOTE**: This data source supports all available filters exposed by the `xanzy/go-gitlab` package, which might not expose all available filters exposed by the Gitlab APIs.
5+
> **NOTE**: This data source supports all available filters exposed by the `xanzy/go-gitlab` package, which might not expose all available filters exposed by the Gitlab APIs.
66
77
## Example Usage
88

@@ -162,6 +162,8 @@ Projects items have the following fields:
162162

163163
* `only_allow_merge_if_all_discussions_are_resolved`
164164

165+
* `allow_merge_on_skipped_pipeline`
166+
165167
* `lfs_enabled`
166168

167169
* `request_access_enabled`

docs/resources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ consult the [gitlab documentation](https://docs.gitlab.com/ee/user/project/repos
8383

8484
* `only_allow_merge_if_all_discussions_are_resolved` - (Optional) Set to true if you want allow merges only if all discussions are resolved.
8585

86+
* `allow_merge_on_skipped_pipeline` - (Optional) Set to true if you want to treat skipped pipelines as if they finished with success.
87+
8688
* `shared_runners_enabled` - (Optional) Enable shared runners for this project.
8789

8890
* `archived` - (Optional) Whether the project is in read-only mode (archived). Repositories can be archived/unarchived by toggling this parameter.

gitlab/data_source_gitlab_projects.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,23 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
145145
"public_builds": project.PublicBuilds,
146146
"only_allow_merge_if_pipeline_succeeds": project.OnlyAllowMergeIfPipelineSucceeds,
147147
"only_allow_merge_if_all_discussions_are_resolved": project.OnlyAllowMergeIfAllDiscussionsAreResolved,
148-
"lfs_enabled": project.LFSEnabled,
149-
"request_access_enabled": project.RequestAccessEnabled,
150-
"merge_method": project.MergeMethod,
151-
"forked_from_project": flattenForkedFromProject(project.ForkedFromProject),
152-
"mirror": project.Mirror,
153-
"mirror_user_id": project.MirrorUserID,
154-
"mirror_trigger_builds": project.MirrorTriggerBuilds,
155-
"only_mirror_protected_branches": project.OnlyMirrorProtectedBranches,
156-
"mirror_overwrites_diverged_branches": project.MirrorOverwritesDivergedBranches,
157-
"shared_with_groups": flattenSharedWithGroupsOptions(project),
158-
"statistics": project.Statistics,
159-
"_links": flattenProjectLinks(project.Links),
160-
"ci_config_path": project.CIConfigPath,
161-
"custom_attributes": project.CustomAttributes,
162-
"packages_enabled": project.PackagesEnabled,
163-
"build_coverage_regex": project.BuildCoverageRegex,
148+
"allow_merge_on_skipped_pipeline": project.AllowMergeOnSkippedPipeline,
149+
"lfs_enabled": project.LFSEnabled,
150+
"request_access_enabled": project.RequestAccessEnabled,
151+
"merge_method": project.MergeMethod,
152+
"forked_from_project": flattenForkedFromProject(project.ForkedFromProject),
153+
"mirror": project.Mirror,
154+
"mirror_user_id": project.MirrorUserID,
155+
"mirror_trigger_builds": project.MirrorTriggerBuilds,
156+
"only_mirror_protected_branches": project.OnlyMirrorProtectedBranches,
157+
"mirror_overwrites_diverged_branches": project.MirrorOverwritesDivergedBranches,
158+
"shared_with_groups": flattenSharedWithGroupsOptions(project),
159+
"statistics": project.Statistics,
160+
"_links": flattenProjectLinks(project.Links),
161+
"ci_config_path": project.CIConfigPath,
162+
"custom_attributes": project.CustomAttributes,
163+
"packages_enabled": project.PackagesEnabled,
164+
"build_coverage_regex": project.BuildCoverageRegex,
164165
}
165166
values = append(values, v)
166167
}
@@ -541,6 +542,10 @@ func dataSourceGitlabProjects() *schema.Resource {
541542
Type: schema.TypeBool,
542543
Computed: true,
543544
},
545+
"allow_merge_on_skipped_pipeline": {
546+
Type: schema.TypeBool,
547+
Computed: true,
548+
},
544549
"lfs_enabled": {
545550
Type: schema.TypeBool,
546551
Computed: true,

gitlab/resource_gitlab_project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
118118
Optional: true,
119119
Default: false,
120120
},
121+
"allow_merge_on_skipped_pipeline": {
122+
Type: schema.TypeBool,
123+
Optional: true,
124+
Default: false,
125+
},
121126
"ssh_url_to_repo": {
122127
Type: schema.TypeString,
123128
Computed: true,
@@ -316,6 +321,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
316321
d.Set("merge_method", string(project.MergeMethod))
317322
d.Set("only_allow_merge_if_pipeline_succeeds", project.OnlyAllowMergeIfPipelineSucceeds)
318323
d.Set("only_allow_merge_if_all_discussions_are_resolved", project.OnlyAllowMergeIfAllDiscussionsAreResolved)
324+
d.Set("allow_merge_on_skipped_pipeline", project.AllowMergeOnSkippedPipeline)
319325
d.Set("namespace_id", project.Namespace.ID)
320326
d.Set("ssh_url_to_repo", project.SSHURLToRepo)
321327
d.Set("http_url_to_repo", project.HTTPURLToRepo)
@@ -356,6 +362,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
356362
MergeMethod: stringToMergeMethod(d.Get("merge_method").(string)),
357363
OnlyAllowMergeIfPipelineSucceeds: gitlab.Bool(d.Get("only_allow_merge_if_pipeline_succeeds").(bool)),
358364
OnlyAllowMergeIfAllDiscussionsAreResolved: gitlab.Bool(d.Get("only_allow_merge_if_all_discussions_are_resolved").(bool)),
365+
AllowMergeOnSkippedPipeline: gitlab.Bool(d.Get("allow_merge_on_skipped_pipeline").(bool)),
359366
SharedRunnersEnabled: gitlab.Bool(d.Get("shared_runners_enabled").(bool)),
360367
RemoveSourceBranchAfterMerge: gitlab.Bool(d.Get("remove_source_branch_after_merge").(bool)),
361368
PackagesEnabled: gitlab.Bool(d.Get("packages_enabled").(bool)),
@@ -616,6 +623,10 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
616623
options.OnlyAllowMergeIfAllDiscussionsAreResolved = gitlab.Bool(d.Get("only_allow_merge_if_all_discussions_are_resolved").(bool))
617624
}
618625

626+
if d.HasChange("allow_merge_on_skipped_pipeline") {
627+
options.AllowMergeOnSkippedPipeline = gitlab.Bool(d.Get("allow_merge_on_skipped_pipeline").(bool))
628+
}
629+
619630
if d.HasChange("request_access_enabled") {
620631
options.RequestAccessEnabled = gitlab.Bool(d.Get("request_access_enabled").(bool))
621632
}

gitlab/resource_gitlab_project_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ func TestAccGitlabProject_basic(t *testing.T) {
4444
MergeMethod: gitlab.FastForwardMerge,
4545
OnlyAllowMergeIfPipelineSucceeds: true,
4646
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
47-
Archived: false, // needless, but let's make this explicit
48-
PackagesEnabled: true,
49-
PagesAccessLevel: gitlab.PublicAccessControl,
50-
BuildCoverageRegex: "foo",
51-
CIConfigPath: ".gitlab-ci.yml@mynamespace/myproject",
47+
AllowMergeOnSkippedPipeline: false,
48+
Archived: false, // needless, but let's make this explicit
49+
PackagesEnabled: true,
50+
PagesAccessLevel: gitlab.PublicAccessControl,
51+
BuildCoverageRegex: "foo",
52+
CIConfigPath: ".gitlab-ci.yml@mynamespace/myproject",
5253
}
5354

5455
defaultsMainBranch = defaults
@@ -88,10 +89,11 @@ func TestAccGitlabProject_basic(t *testing.T) {
8889
MergeMethod: gitlab.FastForwardMerge,
8990
OnlyAllowMergeIfPipelineSucceeds: true,
9091
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
91-
Archived: true,
92-
PackagesEnabled: false,
93-
PagesAccessLevel: gitlab.DisabledAccessControl,
94-
BuildCoverageRegex: "bar",
92+
AllowMergeOnSkippedPipeline: true,
93+
Archived: true,
94+
PackagesEnabled: false,
95+
PagesAccessLevel: gitlab.DisabledAccessControl,
96+
BuildCoverageRegex: "bar",
9597
}, &received),
9698
),
9799
},
@@ -999,6 +1001,7 @@ resource "gitlab_project" "foo" {
9991001
only_allow_merge_if_all_discussions_are_resolved = true
10001002
pages_access_level = "public"
10011003
build_coverage_regex = "foo"
1004+
allow_merge_on_skipped_pipeline = false
10021005
ci_config_path = ".gitlab-ci.yml@mynamespace/myproject"
10031006
}
10041007
`, rInt, rInt, defaultBranchStatement)
@@ -1053,6 +1056,7 @@ resource "gitlab_project" "foo" {
10531056
merge_method = "ff"
10541057
only_allow_merge_if_pipeline_succeeds = true
10551058
only_allow_merge_if_all_discussions_are_resolved = true
1059+
allow_merge_on_skipped_pipeline = true
10561060
10571061
request_access_enabled = false
10581062
issues_enabled = false

0 commit comments

Comments
 (0)