From 2a542c99654677f3c82bdaa72449f6bbf511a959 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Thu, 5 Oct 2023 14:02:15 -0700 Subject: [PATCH] Ability to wip/unwip an MR --- src/GitlabCli/GitlabCli.psd1 | 4 ++-- src/GitlabCli/MergeRequests.psm1 | 40 ++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/GitlabCli/GitlabCli.psd1 b/src/GitlabCli/GitlabCli.psd1 index 66ef00d..a3b4ca6 100644 --- a/src/GitlabCli/GitlabCli.psd1 +++ b/src/GitlabCli/GitlabCli.psd1 @@ -1,11 +1,11 @@ @{ - ModuleVersion = '1.102.0' + ModuleVersion = '1.103.0' PrivateData = @{ PSData = @{ LicenseUri = 'https://github.com/chris-peterson/pwsh-gitlab/blob/main/LICENSE' ProjectUri = 'https://github.com/chris-peterson/pwsh-gitlab' - ReleaseNotes = 'Allow assigning MRs; make get user easier to use (no need to specify ID vs username vs email address)' + ReleaseNotes = 'Toggle MR draft status' } } diff --git a/src/GitlabCli/MergeRequests.psm1 b/src/GitlabCli/MergeRequests.psm1 index a0a9ff1..ad9e270 100644 --- a/src/GitlabCli/MergeRequests.psm1 +++ b/src/GitlabCli/MergeRequests.psm1 @@ -381,31 +381,42 @@ function Update-GitlabMergeRequest { [string] $Title, + [Parameter()] + [Alias('Wip')] + [switch] + $Draft, + + [Parameter()] + [Alias('RemoveDraft')] + [Alias('RemoveWip')] + [switch] + $MarkReady, + [Parameter()] [string] $Description, - [Parameter(ParameterSetName="Assign")] + [Parameter()] [string []] $AssignTo, - [Parameter(ParameterSetName="Unassign")] + [Parameter()] [switch] $Unassign, - [Parameter(ParameterSetName="Reviewers")] + [Parameter()] [string []] $Reviewers, - [Parameter(ParameterSetName="UnsetReviewers")] + [Parameter()] [switch] $UnsetReviewers, - [Parameter(ParameterSetName="Close")] + [Parameter()] [switch] $Close, - [Parameter(ParameterSetName="Reopen")] + [Parameter()] [switch] $Reopen, @@ -413,19 +424,24 @@ function Update-GitlabMergeRequest { [string] $SiteUrl ) - $Project = Get-GitlabProject -ProjectId $ProjectId $Request = @{} - if ($Close) { - $Request.state_event = 'close' - } - elseif ($Reopen) { + if ($Reopen) { $Request.state_event = 'reopen' } - + elseif ($Close) { + $Request.state_event = 'close' + } if ($Title) { $Request.title = $Title + } else { + $MergeRequest = Get-GitlabMergeRequest -ProjectId $ProjectId -MergeRequestId $MergeRequestId + if ($Draft -and -not $MergeRequest.Draft) { + $Request.title = "Draft: $($MergeRequest.Title)" + } elseif ($MarkReady -and $MergeRequest.Draft) { + $Request.title = $MergeRequest.Title -replace '^Draft:\s+', '' + } } if ($Description) { $Request.description = $Description