Skip to content

Commit

Permalink
fix: on pr, trim trailing slash in git url (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
  • Loading branch information
bluebrown authored Oct 26, 2023
1 parent 1cc0fe8 commit f009b6d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/gitbot/provider/azure/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func NewPrClient(upstreamRepo string, auth *url.Userinfo, client httpClient) (*p
// https://<org>@dev.azure.com/<org>/<project>/_git/<repoId>
// git@ssh.dev.azure.com:v3/<org>/<project>/<repoId>
func getOrgProjRepo(u string) (org, proj, repo string, err error) {
u = strings.TrimSuffix(u, "/")
u = strings.TrimSuffix(u, ".git")
parts := strings.Split(u, "/")
if strings.HasPrefix(u, "git@ssh") {
Expand Down
16 changes: 16 additions & 0 deletions internal/gitbot/provider/azure/pull-request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ func TestUrlParse(t *testing.T) {
wantRepoId: "my-repo",
wantError: false,
},
{
name: "https-trailing-slash",
giveUrl: "https://my-org@dev.azure.com/my-org/my-project/_git/my-repo/",
wantOrg: "my-org",
wantProject: "my-project",
wantRepoId: "my-repo",
wantError: false,
},
{
name: "ssh-trailing-slash",
giveUrl: "git@ssh.dev.azure.com:v3/my-org/my-project/my-repo.git/",
wantOrg: "my-org",
wantProject: "my-project",
wantRepoId: "my-repo",
wantError: false,
},
}
for _, tt := range tests {
tt := tt
Expand Down
1 change: 1 addition & 0 deletions internal/gitbot/provider/github/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewPrClient(upstreamRepo string, auth *url.Userinfo, client httpClient) (*p
// git@github.com:bluebrown/kobold-test.git
func getOwnerRepo(u string) (owner, repo string, err error) {
u = strings.TrimPrefix(u, "git@github.com:")
u = strings.TrimSuffix(u, "/")
u = strings.TrimSuffix(u, ".git")
parts := strings.Split(u, "/")
if len(parts) < 2 {
Expand Down
14 changes: 14 additions & 0 deletions internal/gitbot/provider/github/pull-request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ func TestUrlParse(t *testing.T) {
wantRepo: "kobold-test",
wantError: false,
},
{
name: "https-trailing-slash",
giveUrl: "https://github.com/bluebrown/kobold-test/",
wantOwner: "bluebrown",
wantRepo: "kobold-test",
wantError: false,
},
{
name: "ssh-trailing-slash",
giveUrl: "git@github.com:bluebrown/kobold-test.git/",
wantOwner: "bluebrown",
wantRepo: "kobold-test",
wantError: false,
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit f009b6d

Please sign in to comment.