Skip to content

Commit

Permalink
Update GenerateProjectJobURL to account for nested repo names (#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayyush authored Jan 24, 2022
1 parent ca28b57 commit e20e132
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"fmt"
"net/url"
"strings"

"github.com/gorilla/mux"
"github.com/pkg/errors"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (r *Router) GenerateProjectJobURL(ctx models.ProjectCommandContext) (string
projectIdentifier := models.GetProjectIdentifier(ctx.RepoRelDir, ctx.ProjectName)
jobURL, err := r.Underlying.Get(r.ProjectJobsViewRouteName).URL(
"org", pull.BaseRepo.Owner,
"repo", pull.BaseRepo.Name,
"repo", strings.ReplaceAll(pull.BaseRepo.Name, "/", "-"), // Account for nested repo names repo/sub-repo
"pull", fmt.Sprintf("%d", pull.Num),
"project", projectIdentifier,
"workspace", ctx.Workspace,
Expand Down
20 changes: 20 additions & 0 deletions server/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,23 @@ func TestGenerateProjectJobURL_ShouldGenerateURLWithDirectoryAndWorkspaceWhenPro

Equals(t, expectedURL, gotURL)
}

func TestGenerateProjectJobURL_ShouldGenerateURLWhenNestedRepo(t *testing.T) {
router := setupJobsRouter(t)
ctx := models.ProjectCommandContext{
Pull: models.PullRequest{
BaseRepo: models.Repo{
Owner: "test-owner",
Name: "test-repo/sub-repo",
},
Num: 1,
},
RepoRelDir: "ops/terraform/test-root",
Workspace: "default",
}
expectedURL := "http://localhost:4141/jobs/test-owner/test-repo-sub-repo/1/ops-terraform-test-root/default"
gotURL, err := router.GenerateProjectJobURL(ctx)
Ok(t, err)

Equals(t, expectedURL, gotURL)
}

0 comments on commit e20e132

Please sign in to comment.