Skip to content

Commit ce0e3a1

Browse files
Copilotpelikhan
andauthored
Fix runtime-import path duplication when repo is named .github (#19518)
* Initial plan * fix: use LastIndex to find .github/ directory when repo is named .github Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 038c4c9 commit ce0e3a1

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

pkg/workflow/compiler_yaml.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,12 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, pre
391391
normalizedPath := filepath.ToSlash(c.markdownPath)
392392

393393
// Look for "/.github/" as a directory (not just substring in repo name like "username.github.io")
394-
// We need to match the directory component, not arbitrary substrings
394+
// We need to match the directory component, not arbitrary substrings.
395+
// Use LastIndex so that when the repo itself is named ".github" (path like
396+
// "/root/.github/.github/workflows/file.md"), we find the actual .github
397+
// workflows directory rather than the repo root directory.
395398
githubDirPattern := "/.github/"
396-
githubIndex := strings.Index(normalizedPath, githubDirPattern)
399+
githubIndex := strings.LastIndex(normalizedPath, githubDirPattern)
397400

398401
if githubIndex != -1 {
399402
// Extract everything from ".github/" onwards (inclusive)

pkg/workflow/compiler_yaml_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,12 @@ func TestRuntimeImportPathGitHubIO(t *testing.T) {
11421142
expected: "{{#runtime-import .github/workflows/workflow.md}}",
11431143
description: "Normal repo without .github.io should work as before",
11441144
},
1145+
{
1146+
name: "repo_named_dot_github",
1147+
repoName: ".github",
1148+
expected: "{{#runtime-import .github/workflows/test.md}}",
1149+
description: "Repo named '.github' should not duplicate .github in runtime-import path",
1150+
},
11451151
{
11461152
name: "repo_with_github_in_name",
11471153
repoName: "my-github-project",

0 commit comments

Comments
 (0)