Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Update-VSTeamPullRequest and Add-VSTeamPullRequest #241

Merged
merged 15 commits into from
Feb 25, 2020
Merged
102 changes: 102 additions & 0 deletions .docs/Add-VSTeamPullRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!-- #include "./common/header.md" -->

# Add-VSTeamPullRequest

## SYNOPSIS

<!-- #include "./synopsis/Add-VSTeamPullRequest.md" -->

## SYNTAX

## DESCRIPTION

Create a new Pull Request

## EXAMPLES

### -------------------------- EXAMPLE 1 --------------------------

```PowerShell
PS C:\> Set-VSTeamAccount -Account mydemos -Token $(System.AccessToken) -UseBearerToken
PS C:\> $r = Get-VSTeamGitRepository -ProjectName project -Name demorepo
PS C:\> Add-VSTeamPullRequest -ProjectName project -RepositoryId $r.RepositoryId -SourceRefName "refs/heads/mybranch" -TargetRefName "refs/heads/master" -Title "My PR" -Description "My Description" -Draft
```

Create a new pull request as a draft

## PARAMETERS

<!-- #include "./params/projectName.md" -->

### -RepositoryId

Specifies the ID of the repository

```yaml
Type: Guid
Required: True
Aliases: Id
Accept pipeline input: true (ByPropertyName)
```

### -SourceRefName

A source reference, like a branch or commit
Needs to be in ref format like refs/heads/MyBranch

```yaml
Type: String
Required: True
```

### -TargetRefName

A target reference, like a branch or commit
Needs to be in ref format like refs/heads/MyBranch

```yaml
Type: String
Required: True
```

### -Title

The title of the pull request

```yaml
Type: String
Required: True
```

### -Description

The description of the pull request

```yaml
Type: String
Required: True
```

### -Draft

Mark the new pull request as a draft

```yaml
Type: Switch
```

<!-- #include "./params/confirm.md" -->

<!-- #include "./params/force.md" -->

<!-- #include "./params/whatIf.md" -->

## INPUTS

## OUTPUTS

### Team.PullRequest

## NOTES

## RELATED LINKS
125 changes: 125 additions & 0 deletions .docs/Update-VSTeamPullRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!-- #include "./common/header.md" -->

# Update-VSTeamPullRequest

## SYNOPSIS

<!-- #include "./synopsis/Update-VSTeamPullRequest.md" -->

## SYNTAX

## DESCRIPTION

Update a pull request

## EXAMPLES

### -------------------------- EXAMPLE 1 --------------------------

```PowerShell
PS C:\> Set-VSTeamAccount -Account mydemos -Token $(System.AccessToken) -UseBearerToken
PS C:\> $r = Get-VSTeamGitRepository -ProjectName project -Name demorepo
PS C:\> Update-VSTeamPullRequest -RepositoryId $r.RepositoryId -Draft
```

Set the pull request to be a draft

### -------------------------- EXAMPLE 2 --------------------------

```PowerShell
PS C:\> Set-VSTeamAccount -Account mydemos -Token $(System.AccessToken) -UseBearerToken
PS C:\> $r = Get-VSTeamGitRepository -ProjectName project -Name demorepo
PS C:\> Update-VSTeamPullRequest -RepositoryId $r.RepositoryId -Status abandoned
```

Abandon a pull request

## PARAMETERS

### -RepositoryId

The id of the repository

```yaml
Type: Guid
Required: True
Aliases: Id
Accept pipeline input: true (ByPropertyName)
Parameter Sets: Draft, Publish, Status, EnableAutoComplete, DisableAutoComplete
```

### -PullRequestId

The id of the pull request

```yaml
Type: Int32
Required: True
Parameter Sets: Draft, Publish, Status, EnableAutoComplete, DisableAutoComplete
```

### -Status

The status to set the pull request to. Valid values for this are:

- abandoned
- active
- completed
- notSet

```yaml
Type: String
Parameter Sets: Status
```

### -EnableAutoComplete

Set the pull requests auto complete status

```yaml
Type: Switch
Parameter Sets: EnableAutoComplete
```

### -AutoCompleteIdentity

The identity that enabled autocomplete. This is mandatory if -AutoComplete is set to $true

```yaml
Type: VSTeamUser
Parameter Sets: EnableAutoComplete
```

### -DisableAutoComplete

Unset the pull requests auto complete status

```yaml
Type: Switch
Parameter Sets: DisableAutoComplete
```

### -Draft

Set the pull request as a draft

```yaml
Type: Switch
Parameter Sets: Draft
```

<!-- #include "./params/confirm.md" -->

<!-- #include "./params/force.md" -->

<!-- #include "./params/whatIf.md" -->

## INPUTS

## OUTPUTS

### Team.PullRequest

## NOTES

## RELATED LINKS
1 change: 1 addition & 0 deletions .docs/synopsis/Add-VSTeamPullRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create a new Pull Request
1 change: 1 addition & 0 deletions .docs/synopsis/Update-VSTeamPullRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update a pull request
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 6.4.5

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/241) from [Michel Zehnder](https://github.com/MichelZ) which included the following:

- Added Update-VSTeamPullRequest to manipulate some basics about Pull Requests
- Added Add-VSTeamPullRequest to create Pull Requests

## 6.4.4

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/231) from [Dave Neeley](https://github.com/daveneeley) which included the following:
Expand Down
61 changes: 61 additions & 0 deletions Source/Public/Add-VSTeamPullRequest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Add-VSTeamPullRequest {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Low")]
param(
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)]
[Alias('Id')]
[Guid] $RepositoryId,

[Parameter(Mandatory = $true, HelpMessage = "Should be a ref like refs/heads/MyBranch")]
[ValidatePattern('^refs/.*')]
[string] $SourceRefName,

[Parameter(Mandatory = $true, HelpMessage = "Should be a ref like refs/heads/MyBranch")]
[ValidatePattern('^refs/.*')]
[string] $TargetRefName,

[Parameter(Mandatory = $true)]
[string] $Title,

[Parameter(Mandatory = $true)]
[string] $Description,

[Parameter()]
[switch] $Draft,

# Forces the command without confirmation
[Parameter()]
[switch] $Force
)

DynamicParam {
_buildProjectNameDynamicParam
}

process {
Write-Verbose "Add-VSTeamPullRequest"

# Bind the parameter to a friendly variable
$ProjectName = $PSBoundParameters["ProjectName"]

$body = '{"sourceRefName": "' + $SourceRefName + '", "targetRefName": "' + $TargetRefName + '", "title": "' + $Title + '", "description": "' + $Description + '", "isDraft": ' + $Draft.ToString().ToLower() + '}'

Write-Verbose $body

# Call the REST API
if ($force -or $pscmdlet.ShouldProcess($Title, "Add Pull Request")) {

try {
Write-Debug 'Add-VSTeamPullRequest Call the REST API'
$resp = _callAPI -ProjectName $ProjectName -Area 'git' -Resource 'repositories' -Id "$RepositoryId/pullrequests" `
-Method Post -ContentType 'application/json;charset=utf-8' -Body $body -Version $([VSTeamVersions]::Release)

_applyTypesToPullRequests -item $resp

Write-Output $resp
}
catch {
_handleException $_
}
}
}
}
60 changes: 60 additions & 0 deletions Source/Public/Update-VSTeamPullRequest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function Update-VSTeamPullRequest {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'Draft')]
param(
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)]
[Alias('Id')]
[Guid] $RepositoryId,

[Parameter(Mandatory = $true)]
[int] $PullRequestId,

[Parameter(ParameterSetName = "Status", Mandatory = $true)]
[ValidateSet("abandoned", "active", "completed", "notSet")]
[string] $Status,

[Parameter(ParameterSetName = "EnableAutoComplete", Mandatory = $true)]
[Switch] $EnableAutoComplete,

[Parameter(ParameterSetName = "EnableAutoComplete", Mandatory = $true)]
[VSTeamUser] $AutoCompleteIdentity,

[Parameter(ParameterSetName = "DisableAutoComplete", Mandatory = $true)]
[Switch] $DisableAutoComplete,

[Parameter(ParameterSetName = "Draft", Mandatory = $false)]
[switch] $Draft,

[switch] $Force
)

process {
if ($Force -or $pscmdlet.ShouldProcess($PullRequestId, "Update Pull Request ID")) {
if ($Draft.IsPresent) {
$body = '{"isDraft": true }'
}
else {
$body = '{"isDraft": false }'
}

if ($EnableAutoComplete.IsPresent) {
$body = '{"autoCompleteSetBy": "' + $AutoCompleteIdentity.Descriptor + '"}'
}

if ($DisableAutoComplete.IsPresent) {
$body = '{"autoCompleteSetBy": null}'
}

if ($Status) {
$body = '{"status": "' + $Status + '"}'
}

# Call the REST API
$resp = _callAPI -Area git -Resource repositories -iD "$RepositoryId/pullrequests/$PullRequestId" `
-Method Patch -ContentType 'application/json' -body $body -Version $([VSTeamVersions]::Git)

_applyTypesToPullRequests -item $resp

Write-Output $resp
}
}
}
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '6.4.4'
ModuleVersion = '6.4.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Loading