From 1d939b6a96158d4f1d5460f7243d0e92dca1cc8e Mon Sep 17 00:00:00 2001 From: freddydk Date: Thu, 23 Jan 2025 14:06:16 +0100 Subject: [PATCH] use readtoken --- Actions/CheckForUpdates/CheckForUpdates.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Actions/CheckForUpdates/CheckForUpdates.ps1 b/Actions/CheckForUpdates/CheckForUpdates.ps1 index ed7215caf..0ba9e0f29 100644 --- a/Actions/CheckForUpdates/CheckForUpdates.ps1 +++ b/Actions/CheckForUpdates/CheckForUpdates.ps1 @@ -33,7 +33,12 @@ $templateUrl = $templateUrl -replace "^(https:\/\/)(www\.)(.*)$", '$1$3' # TemplateUrl is now always a full url + @ and a branch name -if ($token) { +if ($update -eq 'Y') { + if (-not $token) { + throw "A personal access token with permissions to modify Workflows is needed. You must add a secret called GhTokenWorkflow containing a personal access token. You can Generate a new token from https://github.com/settings/tokens. Make sure that the workflow scope is checked." + } + + # token comes from a secret, base 64 encoded $token = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($token)) # Get token with read permissions for this and the template repository - if private and in the same organization @@ -44,10 +49,8 @@ if ($token) { $readToken = GetAccessToken -token $token -permissions @{"actions"="read";"contents"="read";"metadata"="read"} -repositories $repositories } else { - if ($update -eq 'Y') { - throw "A personal access token with permissions to modify Workflows is needed. You must add a secret called GhTokenWorkflow containing a personal access token. You can Generate a new token from https://github.com/settings/tokens. Make sure that the workflow scope is checked." - } - $readToken = $null + # use token directly + $readToken = $token } # Use Authenticated API request if possible to avoid the 60 API calls per hour limit