Skip to content

Commit

Permalink
github: add FullName field to GitURL
Browse files Browse the repository at this point in the history
  • Loading branch information
aliculPix4D committed Dec 13, 2023
1 parent 483a285 commit d937c0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
16 changes: 10 additions & 6 deletions github/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

type GitURL struct {
URL *url.URL
Owner string
Repo string
URL *url.URL
Owner string
Repo string
FullName string
}

// safeUrlParse wraps [url.Parse] and returns only the error and not the URL to avoid leaking
Expand Down Expand Up @@ -76,11 +77,14 @@ func ParseGitPseudoURL(rawURL string) (GitURL, error) {
want, have, tokens)
}

owner := tokens[1]
repo := strings.TrimSuffix(tokens[2], ".git")
// All OK. Fill our gitURL struct
gu := GitURL{
URL: anyUrl,
Owner: tokens[1],
Repo: strings.TrimSuffix(tokens[2], ".git"),
URL: anyUrl,
Owner: owner,
Repo: repo,
FullName: owner + "/" + repo,
}
return gu, nil
}
25 changes: 15 additions & 10 deletions github/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func TestParseGitPseudoURLSuccess(t *testing.T) {
Host: "github.com",
Path: "/Pix4D/cogito.git",
},
Owner: "Pix4D",
Repo: "cogito",
Owner: "Pix4D",
Repo: "cogito",
FullName: "Pix4D/cogito",
},
},
{
Expand All @@ -37,8 +38,9 @@ func TestParseGitPseudoURLSuccess(t *testing.T) {
Host: "github.com",
Path: "/Pix4D/cogito.git",
},
Owner: "Pix4D",
Repo: "cogito",
Owner: "Pix4D",
Repo: "cogito",
FullName: "Pix4D/cogito",
},
},
{
Expand All @@ -50,8 +52,9 @@ func TestParseGitPseudoURLSuccess(t *testing.T) {
Host: "github.com",
Path: "/Pix4D/cogito.git",
},
Owner: "Pix4D",
Repo: "cogito",
Owner: "Pix4D",
Repo: "cogito",
FullName: "Pix4D/cogito",
},
},
{
Expand All @@ -64,8 +67,9 @@ func TestParseGitPseudoURLSuccess(t *testing.T) {
Host: "github.com",
Path: "/Pix4D/cogito.git",
},
Owner: "Pix4D",
Repo: "cogito",
Owner: "Pix4D",
Repo: "cogito",
FullName: "Pix4D/cogito",
},
},
{
Expand All @@ -78,8 +82,9 @@ func TestParseGitPseudoURLSuccess(t *testing.T) {
Host: "github.com",
Path: "/Pix4D/cogito.git",
},
Owner: "Pix4D",
Repo: "cogito",
Owner: "Pix4D",
Repo: "cogito",
FullName: "Pix4D/cogito",
},
},
}
Expand Down

0 comments on commit d937c0b

Please sign in to comment.