From 606411ff6fd5011f9a706fae3a54d34e25c038f0 Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Mon, 24 Aug 2020 19:59:55 +0300 Subject: [PATCH] Update GetPullRequest function --- github/create-pull-request.ps1 | 3 +-- github/github-api.psm1 | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/github/create-pull-request.ps1 b/github/create-pull-request.ps1 index a30d4fb..d9d1994 100644 --- a/github/create-pull-request.ps1 +++ b/github/create-pull-request.ps1 @@ -85,8 +85,7 @@ Write-Host "Push branch: $BranchName" Git-PushBranch -Name $BranchName -Force $true $gitHubApi = Get-GitHubApi -RepositoryFullName $RepositoryFullName -AccessToken $AccessToken -$repositoryOwner = $RepositoryFullName.Split('/')[0] -$pullRequest = $gitHubApi.GetPullRequest($BranchName, $repositoryOwner) +$pullRequest = $gitHubApi.GetPullRequest($BranchName) if ($pullRequest.Count -gt 0) { Write-Host "Update pull request" diff --git a/github/github-api.psm1 b/github/github-api.psm1 index f32612e..8f88578 100644 --- a/github/github-api.psm1 +++ b/github/github-api.psm1 @@ -6,6 +6,7 @@ class GitHubApi { [string] $BaseUrl [object] $AuthHeader + [string] $RepositoryOwner GitHubApi( [string] $AccountName, @@ -14,6 +15,7 @@ class GitHubApi ) { $this.BaseUrl = $this.BuildBaseUrl($AccountName, $ProjectName) $this.AuthHeader = $this.BuildAuth($AccessToken) + $this.RepositoryOwner = $AccountName } [object] hidden BuildAuth([string]$AccessToken) { @@ -42,9 +44,9 @@ class GitHubApi return $this.InvokeRestMethod($url, 'Post', $null, $requestBody) } - [object] GetPullRequest([string]$BranchName, [string]$RepositoryOwner){ + [object] GetPullRequest([string]$BranchName){ $url = "pulls" - return $this.InvokeRestMethod($url, 'GET', "head=${RepositoryOwner}:$BranchName&base=main", $null) + return $this.InvokeRestMethod($url, 'GET', "head=$($this.RepositoryOwner):${BranchName}&base=main", $null) } [object] UpdatePullRequest([string]$Title, [string]$Body, [string]$BranchName, [string]$PullRequestNumber){