Skip to content

Commit 5a2db95

Browse files
author
Ender Tunc
committed
support for removing source branch on GitLab merge requests
1 parent 5357f28 commit 5a2db95

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

modules/core/src/main/scala/org/scalasteward/core/application/Cli.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,16 @@ object Cli {
280280
"When set, the number of required reviewers for a merge request will be set to this number (non-negative integer). Is only used in the context of gitlab-merge-when-pipeline-succeeds being enabled, and requires that the configured access token have the appropriate privileges. Also requires a Gitlab Premium subscription."
281281
).validate("Required reviewers must be non-negative")(_ >= 0).orNone
282282

283+
private val gitlabRemoveSourceBranch: Opts[Boolean] =
284+
flag(
285+
"gitlab-remove-source-branch",
286+
"Flag indicating if a merge request should remove the source branch when merging."
287+
).orFalse
288+
283289
private val gitLabCfg: Opts[GitLabCfg] =
284-
(gitlabMergeWhenPipelineSucceeds, gitlabRequiredReviewers).mapN(GitLabCfg.apply)
290+
(gitlabMergeWhenPipelineSucceeds, gitlabRequiredReviewers, gitlabRemoveSourceBranch).mapN(
291+
GitLabCfg.apply
292+
)
285293

286294
private val githubAppId: Opts[Long] =
287295
option[Long](

modules/core/src/main/scala/org/scalasteward/core/application/Config.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ object Config {
158158

159159
final case class GitLabCfg(
160160
mergeWhenPipelineSucceeds: Boolean,
161-
requiredReviewers: Option[Int]
161+
requiredReviewers: Option[Int],
162+
removeSourceBranch: Boolean
162163
) extends ForgeSpecificCfg
163164

164165
final case class GiteaCfg(

modules/core/src/main/scala/org/scalasteward/core/forge/gitlab/GitLabApiAlg.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final private[gitlab] case class MergeRequestPayload(
4040
assignee_ids: Option[List[Int]],
4141
reviewer_ids: Option[List[Int]],
4242
target_project_id: Long,
43+
remove_source_branch: Boolean,
4344
source_branch: String,
4445
target_branch: Branch
4546
)
@@ -49,7 +50,8 @@ private[gitlab] object MergeRequestPayload {
4950
id: String,
5051
projectId: Long,
5152
data: NewPullRequestData,
52-
usernamesToUserIdsMapping: Map[String, Int]
53+
usernamesToUserIdsMapping: Map[String, Int],
54+
removeSourceBranch: Boolean
5355
): MergeRequestPayload = {
5456
val assignees = data.assignees.flatMap(usernamesToUserIdsMapping.get)
5557
val reviewers = data.reviewers.flatMap(usernamesToUserIdsMapping.get)
@@ -61,6 +63,7 @@ private[gitlab] object MergeRequestPayload {
6163
reviewer_ids = Option.when(reviewers.nonEmpty)(reviewers),
6264
labels = Option.when(data.labels.nonEmpty)(data.labels),
6365
target_project_id = projectId,
66+
remove_source_branch = removeSourceBranch,
6467
source_branch = data.head,
6568
target_branch = data.base
6669
)
@@ -188,7 +191,8 @@ final class GitLabApiAlg[F[_]: Parallel](
188191
id = url.encodedProjectId(targetRepo),
189192
projectId = projectId.id,
190193
data = data,
191-
usernamesToUserIdsMapping = usernameMapping
194+
usernamesToUserIdsMapping = usernameMapping,
195+
removeSourceBranch = gitLabCfg.removeSourceBranch
192196
)
193197
res <- client.postWithBody[MergeRequestOut, MergeRequestPayload](
194198
uri = url.mergeRequest(targetRepo),

0 commit comments

Comments
 (0)