fix: broken Log Streaming URL when working directory is set to "./" (#2015)

* Replacing . with _ when generating project identifier if project name is not set

* Adding test for GenerateProjectJobURL when working dir set to .

* Replacing . with _ when generating project identifier if project name is not set

* Fixing merge conflicts
This commit is contained in:
Aayush Gupta
2022-01-24 12:18:50 -08:00
committed by GitHub
parent e20e1328f2
commit 7d3f3fb490
2 changed files with 24 additions and 1 deletions

View File

@@ -437,7 +437,10 @@ func GetProjectIdentifier(relRepoDir string, projectName string) string {
if projectName != "" {
return projectName
}
return strings.ReplaceAll(relRepoDir, "/", "-")
// Replace directory separator / with -
// Replace . with _ to ensure projects with no project name and root dir set to "." have a valid URL
replacer := strings.NewReplacer("/", "-", ".", "_")
return replacer.Replace(relRepoDir)
}
// SplitRepoFullName splits a repo full name up into its owner and repo

View File

@@ -116,6 +116,26 @@ func TestGenerateProjectJobURL_ShouldGenerateURLWithDirectoryAndWorkspaceWhenPro
Equals(t, expectedURL, gotURL)
}
func TestGenerateProjectJobURL_ShouldGenerateURLWhenWorkingDirSetToBase(t *testing.T) {
router := setupJobsRouter(t)
ctx := models.ProjectCommandContext{
Pull: models.PullRequest{
BaseRepo: models.Repo{
Owner: "test-owner",
Name: "test-repo",
},
Num: 1,
},
RepoRelDir: ".",
Workspace: "default",
}
expectedURL := "http://localhost:4141/jobs/test-owner/test-repo/1/_/default"
gotURL, err := router.GenerateProjectJobURL(ctx)
Ok(t, err)
Equals(t, expectedURL, gotURL)
}
func TestGenerateProjectJobURL_ShouldGenerateURLWhenNestedRepo(t *testing.T) {
router := setupJobsRouter(t)
ctx := models.ProjectCommandContext{