-
Notifications
You must be signed in to change notification settings - Fork 189
Merge a branch of a repository #89
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
Open
raghav710
wants to merge
5
commits into
microsoft:master
Choose a base branch
from
raghav710:issue#84-merge-branches
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a1b564
Initial cut, tested manually. Not ready for review
ff62aa0
* Functionality for Get-GitHubReference and New-GitHubReference imple…
ec585c8
Merge branch 'issue#84-merge-branches' of https://github.com/raghav71…
13d16cc
Added test cases and address review comments
e239f25
Merge branch 'master' into issue#84-merge-branches
raghav710 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
<# | ||
.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
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.