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

Delete GHCreator and its usages #5042

Merged
merged 4 commits into from
Jan 4, 2023
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
2 changes: 0 additions & 2 deletions tools/github-labels/.gitignore

This file was deleted.

6 changes: 6 additions & 0 deletions tools/github-labels/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This area is focused on the management of GitHub labels for the various Azure SDK repositories, containing tools and data used for that purpose.

## Changelog

As of this PR: https://github.com/Azure/azure-sdk-tools/pull/5042
The management of GitHub labels no longer uses GHCreator. It is to be migrated to use GH CLI, per:
https://github.com/Azure/azure-sdk-tools/issues/4888#issuecomment-1369900827

## Prerequisites

- **.NET SDK:** In order to run the GHCreator tool, a version of the .NET Core SDK capable of executing an application targeting `netcoreapp3.1` is needed. The latest version of the [.NET Core SDK](https://dotnet.microsoft.com/download) is recommended.
Expand Down
121 changes: 62 additions & 59 deletions tools/github-labels/deploy-labels.ps1
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
<#
.SYNOPSIS
Deploys the set of common labels to the managed set of Azure SDK repositories.

.PARAMETER GitHubAccessToken
The personal access token of the GitHub user who this command is being run on behalf of.

.PARAMETER LabelFilePath
[optional] TThe fully-qualified path (including filename) of the CSV file that contains
the set of common label data, in GHCreator format.

.PARAMETER RepositoryFilePath
[optional] The fully-qualified path (including filename) of the text file that contains
the set of repositories to update labels for, with each repository appearing on a new line.

.PARAMETER DelayMinutes
[optional] The number of minutes to delay between updating labels for each individual repository;
intended to help guard against throttling.
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, HelpMessage="Please provide your GitHub access token.", Position=0)]
[ValidateNotNullOrEmpty()]
[string]$GitHubAccessToken,

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of common labels.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$LabelFilePath = "./common-labels.csv",

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of repositories.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$RepositoryFilePath = "./repositories.txt",

[Parameter(Mandatory=$false, HelpMessage="Please provide the time to delay between repositories (in minutes), between 0 and 100.")]
[ValidateRange(0,100)]
[int]$DelayMinutes = 0
)

$repositories = Get-Content $RepositoryFilePath

foreach ($currentRepository in $repositories)
{
Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " Starting $($currentRepository)" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

dotnet ./ghcreator/GHCreator.dll CreateOrUpdate $LabelFilePath $currentRepository -token $GitHubAccessToken

Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " $($currentRepository) complete" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

if ($DelayMinutes -gt 0)
{
Write-Warning "Delaying for $($DelayMinutes) minutes..."
Start-Sleep -Seconds ($DelayMinutes * 60)
}
<#
.SYNOPSIS
Deploys the set of common labels to the managed set of Azure SDK repositories.

.PARAMETER GitHubAccessToken
The personal access token of the GitHub user who this command is being run on behalf of.

.PARAMETER LabelFilePath
[optional] TThe fully-qualified path (including filename) of the CSV file that contains
the set of common label data, in GHCreator format.

.PARAMETER RepositoryFilePath
[optional] The fully-qualified path (including filename) of the text file that contains
the set of repositories to update labels for, with each repository appearing on a new line.

.PARAMETER DelayMinutes
[optional] The number of minutes to delay between updating labels for each individual repository;
intended to help guard against throttling.
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, HelpMessage="Please provide your GitHub access token.", Position=0)]
[ValidateNotNullOrEmpty()]
[string]$GitHubAccessToken,

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of common labels.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$LabelFilePath = "./common-labels.csv",

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of repositories.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$RepositoryFilePath = "./repositories.txt",

[Parameter(Mandatory=$false, HelpMessage="Please provide the time to delay between repositories (in minutes), between 0 and 100.")]
[ValidateRange(0,100)]
[int]$DelayMinutes = 0
)

$repositories = Get-Content $RepositoryFilePath

foreach ($currentRepository in $repositories)
{
Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " Starting $($currentRepository)" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

# GHCreator has been deleted by this PR: https://github.com/Azure/azure-sdk-tools/pull/5042
# Hence, this script is currently broken and needs updating to use GH CLI, per:
# https://github.com/Azure/azure-sdk-tools/issues/4888#issuecomment-1369900827
# dotnet ./ghcreator/GHCreator.dll CreateOrUpdate $LabelFilePath $currentRepository -token $GitHubAccessToken

Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " $($currentRepository) complete" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

if ($DelayMinutes -gt 0)
{
Write-Warning "Delaying for $($DelayMinutes) minutes..."
Start-Sleep -Seconds ($DelayMinutes * 60)
}
}
166 changes: 85 additions & 81 deletions tools/github-labels/diff-repo-labels.ps1
Original file line number Diff line number Diff line change
@@ -1,82 +1,86 @@
<#
.SYNOPSIS
Compares the labels for an Azure SDK repository against the set of labels common
to all repositories, outputting labels that exist only for the repository.

.PARAMETER GitHubAccessToken
The personal access token of the GitHub user who this command is being run on behalf of.

.PARAMETER RepositoryName
The full name (inlcuding owner organization) of the repository that is the
source for the labels being compared to the common set. For example, "Azure\azure-sdk-for-net".

.PARAMETER CommonLabelFilePath
[optional] The fully-qualified path (including filename) of the .csv file that contains
the set of labels common to all repositories, in GHChreate format.
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, HelpMessage="Please provide your GitHub access token.", Position=0)]
[ValidateNotNullOrEmpty()]
[string]$GitHubAccessToken,

[Parameter(Mandatory=$true, HelpMessage="Please provide the full name of the repository (including organization) to read labels from.", Position=1)]
[ValidateNotNullOrEmpty()]
[string]$RepositoryName,

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of common labels, in GHCreate format.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$CommonLabelFilePath = "./common-labels.csv"
)

function BuildCommonLabelHash($commonLabelFilePath)
{
$labels = [System.Collections.Generic.HashSet[string]]::new()

foreach ($line in (Get-Content $commonLabelFilePath))
{
if (-not [String]::IsNullOrEmpty($line))
{
[string]$label = (($line -split ",")[1])
$labels.Add($label) | Out-Null
}
}

return $labels
}

# ====================
# == Script Actions ==
# ====================

Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " $($RepositoryName)" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

$commonLabels = (BuildCommonLabelHash $CommonLabelFilePath)
$repositoryLabels = ((dotnet ./ghcreator/GHCreator.dll List Label $RepositoryName -token $GitHubAccessToken) | Select-Object -Skip 1)
$any = $false

foreach ($line in $repositoryLabels)
{
if (-not [String]::IsNullOrEmpty($line))
{
[string]$label = (($line -split ",")[1])

if (-not $commonLabels.Contains($label))
{
Write-Host "`t$($label)"
$any = $true
}
}
}

if (-not $any)
{
Write-Host "`tThe repository contains no labels not in the common set."
}

Write-Host ""
<#
.SYNOPSIS
Compares the labels for an Azure SDK repository against the set of labels common
to all repositories, outputting labels that exist only for the repository.

.PARAMETER GitHubAccessToken
The personal access token of the GitHub user who this command is being run on behalf of.

.PARAMETER RepositoryName
The full name (inlcuding owner organization) of the repository that is the
source for the labels being compared to the common set. For example, "Azure\azure-sdk-for-net".

.PARAMETER CommonLabelFilePath
[optional] The fully-qualified path (including filename) of the .csv file that contains
the set of labels common to all repositories, in GHChreate format.
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, HelpMessage="Please provide your GitHub access token.", Position=0)]
[ValidateNotNullOrEmpty()]
[string]$GitHubAccessToken,

[Parameter(Mandatory=$true, HelpMessage="Please provide the full name of the repository (including organization) to read labels from.", Position=1)]
[ValidateNotNullOrEmpty()]
[string]$RepositoryName,

[Parameter(Mandatory=$false, HelpMessage="Please provide the path to the set of common labels, in GHCreate format.")]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$CommonLabelFilePath = "./common-labels.csv"
)

function BuildCommonLabelHash($commonLabelFilePath)
{
$labels = [System.Collections.Generic.HashSet[string]]::new()

foreach ($line in (Get-Content $commonLabelFilePath))
{
if (-not [String]::IsNullOrEmpty($line))
{
[string]$label = (($line -split ",")[1])
$labels.Add($label) | Out-Null
}
}

return $labels
}

# ====================
# == Script Actions ==
# ====================

Write-Host " ==================================================== " -ForegroundColor Green
Write-Host " $($RepositoryName)" -ForegroundColor Green
Write-Host " ==================================================== " -ForegroundColor Green

$commonLabels = (BuildCommonLabelHash $CommonLabelFilePath)
# GHCreator has been deleted by this PR: https://github.com/Azure/azure-sdk-tools/pull/5042
# Hence, this script is currently broken and needs updating to use GH CLI, per:
# https://github.com/Azure/azure-sdk-tools/issues/4888#issuecomment-1369900827
#$repositoryLabels = ((dotnet ./ghcreator/GHCreator.dll List Label $RepositoryName -token $GitHubAccessToken) | Select-Object -Skip 1)
$repositoryLabels = ""
$any = $false

foreach ($line in $repositoryLabels)
{
if (-not [String]::IsNullOrEmpty($line))
{
[string]$label = (($line -split ",")[1])

if (-not $commonLabels.Contains($label))
{
Write-Host "`t$($label)"
$any = $true
}
}
}

if (-not $any)
{
Write-Host "`tThe repository contains no labels not in the common set."
}

Write-Host ""
Write-Host ""
Binary file removed tools/github-labels/ghcreator/CommandLine.dll
Binary file not shown.
Binary file not shown.
Binary file removed tools/github-labels/ghcreator/CsvHelper.dll
Binary file not shown.
Loading