Skip to content

Commit 990ed65

Browse files
Copilotmazhelez
andcommitted
Fix final repository detection logic to use standard AL-Go repositories
Co-authored-by: mazhelez <[email protected]>
1 parent e7a40d0 commit 990ed65

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

Actions/CheckForUpdates/CheckForUpdates.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ foreach($checkfile in $checkfiles) {
257257
# Determine if current repository is a final repository (has templateUrl pointing to another repo)
258258
# Final repositories should not have custom jobs applied to prevent persistence of removed template jobs
259259
# unless allowCustomJobsInEndRepos is explicitly set to true
260-
$currentRepoReference = $env:GITHUB_REPOSITORY
261260
$isFinalRepository = $false
262261
$allowCustomJobsInEndRepos = $false
263262

@@ -269,7 +268,9 @@ foreach($checkfile in $checkfiles) {
269268
# Extract repository reference from templateUrl (e.g., "microsoft/AL-Go-PTE" from "https://github.com/microsoft/AL-Go-PTE@main")
270269
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
271270
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
272-
$isFinalRepository = $templateRepoReference -ne $currentRepoReference
271+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
272+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
273+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
273274
}
274275

275276
if ($isFinalRepository -and -not $allowCustomJobsInEndRepos) {

Tests/CustomJobRemoval.Test.ps1

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ Describe "Custom Job Removal Tests" {
104104
$type = 'workflow'
105105

106106
# Apply the final repository detection logic
107-
$currentRepoReference = $env:GITHUB_REPOSITORY
108107
$isFinalRepository = $false
109108

110109
if ($repoSettings.templateUrl) {
111110
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
112111
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
113-
$isFinalRepository = $templateRepoReference -ne $currentRepoReference
112+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
113+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
114+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
114115
}
115116

116117
# Test that final repository is correctly detected
@@ -209,13 +210,14 @@ Describe "Custom Job Removal Tests" {
209210
$type = 'workflow'
210211

211212
# Apply the final repository detection logic
212-
$currentRepoReference = $env:GITHUB_REPOSITORY
213213
$isFinalRepository = $false
214214

215215
if ($repoSettings.templateUrl) {
216216
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
217217
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
218-
$isFinalRepository = $templateRepoReference -ne $currentRepoReference
218+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
219+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
220+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
219221
}
220222

221223
# Test that template repository is correctly detected
@@ -316,7 +318,6 @@ Describe "Custom Job Removal Tests" {
316318
$srcContent = $templateYaml.content -join "`n"
317319

318320
# Simulate the repository type detection and custom job handling
319-
$currentRepoReference = $env:GITHUB_REPOSITORY
320321
$isFinalRepository = $false
321322
$allowCustomJobsInEndRepos = $false
322323

@@ -327,7 +328,9 @@ Describe "Custom Job Removal Tests" {
327328
if ($repoSettings.templateUrl) {
328329
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
329330
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
330-
$isFinalRepository = $templateRepoReference -ne $currentRepoReference
331+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
332+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
333+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
331334
}
332335

333336
# Verify that it's detected as a final repository
@@ -365,4 +368,56 @@ Describe "Custom Job Removal Tests" {
365368
# Should default to false
366369
$allowCustomJobsInEndRepos | Should -Be $false
367370
}
371+
372+
It 'Repositories using standard AL-Go templates should NOT be considered final repositories' {
373+
$standardTemplates = @(
374+
"https://github.com/microsoft/AL-Go-PTE@main",
375+
"https://github.com/microsoft/AL-Go-AppSource@main",
376+
"https://github.com/microsoft/AL-Go@main"
377+
)
378+
379+
foreach ($templateUrl in $standardTemplates) {
380+
$repoSettings = @{
381+
templateUrl = $templateUrl
382+
}
383+
384+
$isFinalRepository = $false
385+
if ($repoSettings.templateUrl) {
386+
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
387+
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
388+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
389+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
390+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
391+
}
392+
393+
# Standard AL-Go templates should NOT be considered final repositories
394+
$isFinalRepository | Should -Be $false -Because "Repository using $templateUrl should not be considered a final repository"
395+
}
396+
}
397+
398+
It 'Repositories using custom templates should be considered final repositories' {
399+
$customTemplates = @(
400+
"https://github.com/myorg/my-custom-template@main",
401+
"https://github.com/company/[email protected]",
402+
"https://github.com/team/modified-template@development"
403+
)
404+
405+
foreach ($templateUrl in $customTemplates) {
406+
$repoSettings = @{
407+
templateUrl = $templateUrl
408+
}
409+
410+
$isFinalRepository = $false
411+
if ($repoSettings.templateUrl) {
412+
$templateRepoUrl = $repoSettings.templateUrl.Split('@')[0]
413+
$templateRepoReference = $templateRepoUrl.Split('/')[-2..-1] -join '/'
414+
# Final repository is one where templateUrl doesn't point to standard AL-Go repositories
415+
$standardAlGoRepos = @('microsoft/AL-Go-PTE', 'microsoft/AL-Go-AppSource', 'microsoft/AL-Go')
416+
$isFinalRepository = $templateRepoReference -notin $standardAlGoRepos
417+
}
418+
419+
# Custom templates should be considered final repositories
420+
$isFinalRepository | Should -Be $true -Because "Repository using $templateUrl should be considered a final repository"
421+
}
422+
}
368423
}

0 commit comments

Comments
 (0)