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

Merge a branch of a repository #89

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions GitHubRepositoryMerge.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

function Merge-GitHubRepositoryBranches
raghav710 marked this conversation as resolved.
Show resolved Hide resolved
{
<#
.SYNOPSIS
Branch a branch into another
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

.DESCRIPTION
Merge a branch into another
Calls the API: https://developer.github.com/v3/repos/merging/
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub

.PARAMETER OwnerName
Owner of the repository.
If not supplied here, the DefaultOwnerName configuration property value will be used.

.PARAMETER RepositoryName
Name of the repository.
If not supplied here, the DefaultRepositoryName configuration property value will be used.

.PARAMETER Uri
Uri for the repository.
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
them individually.

.PARAMETER State
The state of the pull requests that should be returned back.

.PARAMETER Base
The name of the base branch that the head will be merged into.

.PARAMETER Head
The head to merge. This can be a branch name or a commit SHA1.

.PARAMETER CommitMessage
Commit message to use for the merge commit. If omitted, a default message will be used.

.PARAMETER AccessToken
If provided, this will be used as the AccessToken for authentication with the
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.

.PARAMETER NoStatus
If this switch is specified, long-running commands will run on the main thread
with no commandline status update. When not specified, those commands run in
the background, enabling the command prompt to provide status information.
If not supplied here, the DefaultNoStatus configuration property value will be used.

.OUTPUTS
//TODO: FInd the output for POST commands and put it here
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

.EXAMPLE
//TODO: Give an example here
raghav710 marked this conversation as resolved.
Show resolved Hide resolved
#>

[CmdletBinding(
SupportsShouldProcess,
DefaultParametersetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,

[Parameter(ParameterSetName='Elements')]
[string] $RepositoryName,

[Parameter(
Mandatory,
ParameterSetName='Uri')]
[string] $Uri,

[string] $Base,
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

[string] $CommitMessage,
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

[string] $Head,
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

[string] $AccessToken,

[switch] $NoStatus
)
Write-InvocationLog
raghav710 marked this conversation as resolved.
Show resolved Hide resolved

$elements = Resolve-RepositoryElements -DisableValidation
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName

$telemetryProperties = @{
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
}

$hashBody = @{
'base'= $Base;
'head' = $Head;
'commit_message' = $CommitMessage;
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/merges"
'Body' = (ConvertTo-Json -InputObject $hashBody)
'Method' = 'Post'
'Description' = "Merging branch $Head to $Base in $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
raghav710 marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions PowerShellForGitHub.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'GitHubPullRequests.ps1',
'GitHubRepositories.ps1',
'GitHubRepositoryForks.ps1',
'GitHubRepositoryMerge.ps1',
'GitHubRepositoryTraffic.ps1',
'GitHubTeams.ps1',
'GitHubUsers.ps1',
Expand Down Expand Up @@ -85,6 +86,7 @@
'Invoke-GHRestMethod',
'Invoke-GHRestMethodMultipleResult',
'Lock-GitHubIssue',
'Merge-GitHubRepositoryBranches',
'Move-GitHubRepositoryOwnership',
'New-GithubAssignee',
'New-GitHubComment',
Expand Down