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

Sync eng/common directory with azure-sdk-tools for PR 1161 #15013

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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