-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete-tag.ps1
63 lines (50 loc) · 1.85 KB
/
delete-tag.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
param (
[string]$token = $env:INPUT_TOKEN,
[string]$repo = $env:INPUT_REPO,
[string]$keyword = $env:INPUT_KEYWORD,
[string]$owner = $env:INPUT_OWNER,
[string]$deleteType = $env:INPUT_DELETETYPE
)
$headers = @{
"Authorization" = "token $token"
"User-Agent" = "PowerShell-GitHub-Action"
}
function DeleteTags {
$urlTags = "https://api.github.com/repos/$owner/$repo/git/refs/tags"
$response = Invoke-RestMethod -Uri $urlTags -Headers $headers -Method Get
foreach ($tag in $response) {
$tagName = $tag.url
if ($tagName -like "*$keyword*") {
$deleteUrl = "https://api.github.com/repos/$owner/$repo/git/$tagName"
Invoke-RestMethod -Uri $tagName -Headers $headers -Method Delete
Write-Host "Deleted tag: $tagName"
}
}
}
function DeleteReleases {
$urlReleases = "https://api.github.com/repos/$owner/$repo/releases"
$response = Invoke-RestMethod -Uri $urlReleases -Headers $headers -Method Get
foreach ($release in $response) {
$releaseVersion = $release.name
if ($releaseVersion -like "*$keyword*") {
$deleteUrl = $release.url
Invoke-RestMethod -Uri $deleteUrl -Headers $headers -Method Delete
Write-Host "Deleted release: $releaseVersion"
}
}
}
if ($deleteType -eq "tag") {
# $url = "https://api.github.com/repos/$owner/$repo/git/refs/tags"
DeleteTags
} elseif ($deleteType -eq "release") {
# $url = "https://api.github.com/repos/$owner/$repo/releases"
DeleteReleases
} elseif ($deleteType -eq "tr") {
# $urlTags = "https://api.github.com/repos/$owner/$repo/git/refs/tags"
DeleteTags
# $urlReleases = "https://api.github.com/repos/$owner/$repo/releases"
DeleteReleases
} else {
Write-Host "Invalid delete type. Please enter 'tag', 'release', or 'tr'."
Exit
}