This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
/
New-GitLabProjectMergeRequest.ps1
121 lines (102 loc) · 3.46 KB
/
New-GitLabProjectMergeRequest.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function New-GitLabProjectMergeRequest
{
<#
.SYNOPSIS
Creates a new merge request
.DESCRIPTION
The New-GitLabProjectMergeRequest function creates a new merge request.
By default the source branch, target branch and MR title must be passed.
By specifying -PassThru the created MR is returned.
.EXAMPLE
New-GitLabProjectMergeRequest -ProjectID 20 -SourceBranch FeatureBranch -TargetBranch master -Title 'Implement new feature'
---------------------------------------------------------------
Creates a merge request named 'Implement new feature' from FeatureBranch to master in project 20
.EXAMPLE
New-GitLabProjectMergeRequest -ProjectID 20 -SourceBranch FeatureBranch -TargetBranch master -Title 'Implement new feature' -Passthru
---------------------------------------------------------------
Creates a merge request named 'Implement new feature' from FeatureBranch to master in project 20.
Returns the created Merge Request
#>
[CmdletBinding()]
[Alias()]
[OutputType()]
Param
(
# The ID of the project
[Parameter(HelpMessage = 'ProjectID',
Mandatory = $true)]
[Alias('ID')]
[int]$ProjectID,
# The source branch for the MR
[Parameter(HelpMessage = 'Source Branch',mandatory = $true)]
[Alias('source_branch')]
[string]$SourceBranch,
# The target branch for the MR
[Parameter(HelpMessage = 'target Branch',mandatory = $true)]
[Alias('target_branch')]
[string]$TargetBranch,
# The Title for the MR
[Parameter(HelpMessage = 'Title of MR',mandatory = $true)]
[string]$Title,
# The description for the MR
[Parameter(HelpMessage = 'description of the MR',mandatory = $false)]
[string]$Description,
# The Target Project for the MR
# By default uses the source project.
[Parameter(HelpMessage = 'the target projects id',mandatory = $false)]
[Alias('target_project_id')]
[string]$TargetProjectID,
# Assigns this MR to the user specified
[Parameter(Helpmessage = 'Assignee user ID',mandatory = $false)]
[Alias('assignee_id')]
[int]$AssigneeID,
# Assigns this MR to a milestone
[Parameter(Helpmessage = 'The ID of a milestone to assign MR',mandatory = $false)]
[Alias('milestone_id')]
[int]$MilestoneID,
# Assigns the labels to the MR
[Parameter(HelpMessage = 'label names for an MR',mandatory = $false)]
[string[]]$Labels,
# Specify Existing GitlabConnector
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitlabConnect),
# Return the created Merge Request
[Parameter(HelpMessage = 'Passthru the created MR',
Mandatory = $false)]
[switch]$PassThru
)
$HTTPMethod = 'post'
$APIUrl = "projects/$ProjectID/merge_requests"
$Parameters = @{
title = $Title
'source_branch' = $SourceBranch
'target_branch' = $TargetBranch
}
if($AssigneeID)
{
$Parameters.'assignee_id' = $AssigneeID
}
if($Description)
{
$Parameters.description = $Description
}
if($TargetProjectID)
{
$Parameters.'target_project_id' = $TargetProjectID
}
if($Labels)
{
$Parameters.labels = @($Labels) -join ','
}
if($MilestoneID)
{
$Parameters.'milestone_id' = $MilestoneID
}
$NewMergeRequest = $GitlabConnect.callapi($APIUrl,$HTTPMethod,$Parameters)
if($PassThru)
{
return $NewMergeRequest
}
}