Skip to content

Commit

Permalink
fix: broken Log Streaming URL when working directory is set to "./" (r…
Browse files Browse the repository at this point in the history
…unatlantis#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
  • Loading branch information
Aayyush authored and krrrr38 committed Dec 16, 2022
1 parent 3d2b00d commit 95b5d82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions server/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 95b5d82

Please sign in to comment.