From d937c0b649cb8f7c977179888acdf47d632d46cb Mon Sep 17 00:00:00 2001 From: aliculPix4D Date: Wed, 13 Dec 2023 09:57:34 +0100 Subject: [PATCH] github: add FullName field to GitURL --- github/url.go | 16 ++++++++++------ github/url_test.go | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/github/url.go b/github/url.go index 3c68ef7..31cb497 100644 --- a/github/url.go +++ b/github/url.go @@ -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 @@ -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 } diff --git a/github/url_test.go b/github/url_test.go index e7641c2..802e45b 100644 --- a/github/url_test.go +++ b/github/url_test.go @@ -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", }, }, { @@ -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", }, }, { @@ -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", }, }, { @@ -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", }, }, { @@ -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", }, }, }