Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository for Tools P…
Browse files Browse the repository at this point in the history
…R 1161
  • Loading branch information
chidozieononiwu authored and azure-sdk committed Nov 5, 2020
1 parent abd5410 commit f2042b1
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 155 deletions.
8 changes: 6 additions & 2 deletions eng/common/scripts/Get-PullRequestCreator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ param (
[string]$RepoName,

[Parameter(Mandatory = $true)]
$PullRequestNumber
$PullRequestNumber,

[Parameter(Mandatory = $true)]
[string]$AuthToken
)

. "${PSScriptRoot}\common.ps1"

try
{
$pullRequest = Get-GithubPullRequest -RepoOwner $RepoOwner -RepoName $RepoName -PullRequestNumber $PullRequestNumber
$pullRequest = Get-GithubPullRequest -RepoOwner $RepoOwner -RepoName $RepoName `
-PullRequestNumber $PullRequestNumber -AuthToken $AuthToken
Write-Host "##vso[task.setvariable variable=System.PullRequest.Creator;]$($pullRequest.user.login)"
}
catch
Expand Down
92 changes: 92 additions & 0 deletions eng/common/scripts/Invoke-DevOpsAPI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
. "${PSScriptRoot}\logging.ps1"

$DevOpsAPIBaseURI = "https://dev.azure.com/{0}/{1}/_apis/{2}/{3}?{4}api-version=6.0"

function Get-DevOpsApiHeaders ($Base64EncodedToken) {
$headers = @{
Authorization = "Basic $Base64EncodedToken"
}
return $headers
}

function Start-DevOpsBuild {
param (
$Organization="azure-sdk",
$Project="internal",
[Parameter(Mandatory = $true)]
$SourceBranch,
[Parameter(Mandatory = $true)]
$DefinitionId,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$Base64EncodedAuthToken
)

$uri = "$DevOpsAPIBaseURI" -F $Organization, $Project , "build" , "builds", ""

$parameters = @{
sourceBranch = $SourceBranch
definition = @{ id = $DefinitionId }
}

return Invoke-RestMethod `
-Method POST `
-Body ($parameters | ConvertTo-Json) `
-Uri $uri `
-Headers (Get-DevOpsApiHeaders -Base64EncodedToken $Base64EncodedAuthToken) `
-MaximumRetryCount 3 `
-ContentType "application/json"
}

function Update-DevOpsBuild {
param (
$Organization="azure-sdk",
$Project="internal",
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$BuildId,
$Status, # pass canceling to cancel build
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$Base64EncodedAuthToken
)

$uri = "$DevOpsAPIBaseURI" -F $Organization, $Project, "build", "builds/$BuildId", ""
$parameters = @{}

if ($Status) { $parameters["status"] = $Status}

return Invoke-RestMethod `
-Method PATCH `
-Body ($parameters | ConvertTo-Json) `
-Uri $uri `
-Headers (Get-DevOpsApiHeaders -Base64EncodedToken $Base64EncodedAuthToken) `
-MaximumRetryCount 3 `
-ContentType "application/json"
}

function Get-DevOpsBuilds {
param (
$Organization="azure-sdk",
$Project="internal",
$BranchName, #Should start with 'refs/heads/'
$Definitions, # Comma seperated string of definition IDs
$StatusFilter, # Comma seperated string 'cancelling, completed, inProgress, notStarted'
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory = $true)]
$Base64EncodedAuthToken
)

$query = ""

if ($BranchName) { $query += "branchName=$BranchName&" }
if ($Definitions) { $query += "definitions=$Definitions&" }
if ($StatusFilter) { $query += "statusFilter=$StatusFilter&" }
$uri = "$DevOpsAPIBaseURI" -F $Organization, $Project , "build" , "builds", $query

return Invoke-RestMethod `
-Method GET `
-Uri $uri `
-Headers (Get-DevOpsApiHeaders -Base64EncodedToken $Base64EncodedAuthToken) `
-MaximumRetryCount 3
}
Loading

0 comments on commit f2042b1

Please sign in to comment.