Created
December 8, 2023 03:44
-
-
Save maboloshi/59ccad329b0fc2ad17b8cf462b9c82e6 to your computer and use it in GitHub Desktop.
通过 GitHub REST API 创建远程分支 (Powershell 原生实现)
This file contains 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
function create_ref { | |
param ( | |
[Parameter(Mandatory = $true)] | |
[String]$Token, | |
[Parameter(Mandatory = $true)] | |
[String]$RepoNwo, | |
[Parameter(Mandatory = $true)] | |
[String]$Ref, | |
[Parameter(Mandatory = $true)] | |
[String]$CommitSha | |
) | |
$github_api_url = "https://api.github.com/repos/$RepoNwo/git/refs" | |
$headers = @{ | |
"Authorization" = "token $Token" | |
} | |
$body = @{ | |
ref = $Ref | |
sha = $CommitSha | |
} | ConvertTo-Json | |
Write-Host "Invoke-RestMethod -Method Post -Uri $github_api_url -ContentType 'application/json' -Headers $headers -Body $body" | |
Invoke-RestMethod -Method Post -Uri $github_api_url -ContentType 'application/json' -Headers $headers -Body $body | |
} | |
# Create remote branch vis GitHub REST API | |
$ParentSHA = $((git ls-remote --refs --quiet origin $OriginBranch).Split()[0]) | |
$response = create_ref -t $Token -RepoNwo $REPOSITORY -Ref "refs/heads/$branch" -CommitSha $ParentSHA | |
Write-Host $response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment