mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-04 03:52:31 +03:00
✨ fix: add github.com as default for owner/repo parameter (#872)
* fix: add github.com as default for owner/repo parameter #780 * fix: use const to fix build error * fix: nitpick fix and golangci-lint issue
This commit is contained in:
parent
c54d77b0d7
commit
c73b28f13c
@ -56,12 +56,28 @@ func (r *RepoURL) String() string {
|
||||
|
||||
// Set parses a URL string into RepoURL struct.
|
||||
func (r *RepoURL) Set(s string) error {
|
||||
// Allow skipping scheme for ease-of-use, default to https.
|
||||
if !strings.Contains(s, "://") {
|
||||
s = "https://" + s
|
||||
var t string
|
||||
|
||||
const two = 2
|
||||
const three = 3
|
||||
|
||||
c := strings.Split(s, "/")
|
||||
|
||||
switch l := len(c); {
|
||||
// This will takes care for repo/owner format.
|
||||
// By default it will use github.com
|
||||
case l == two:
|
||||
t = "github.com/" + c[0] + "/" + c[1]
|
||||
case l >= three:
|
||||
t = s
|
||||
}
|
||||
|
||||
u, e := url.Parse(s)
|
||||
// Allow skipping scheme for ease-of-use, default to https.
|
||||
if !strings.Contains(t, "://") {
|
||||
t = "https://" + t
|
||||
}
|
||||
|
||||
u, e := url.Parse(t)
|
||||
if e != nil {
|
||||
//nolint:wrapcheck
|
||||
return sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("url.Parse: %v", e))
|
||||
|
@ -64,6 +64,26 @@ func TestRepoURL_ValidGitHubUrl(t *testing.T) {
|
||||
args: args{s: "https://gitlab.com/foo/kubeflow"},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "github repository",
|
||||
fields: fields{
|
||||
Host: "github.com",
|
||||
Owner: "foo",
|
||||
Repo: "kubeflow",
|
||||
},
|
||||
args: args{s: "foo/kubeflow"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "github repository",
|
||||
fields: fields{
|
||||
Host: "github.com",
|
||||
Owner: "foo",
|
||||
Repo: "kubeflow",
|
||||
},
|
||||
args: args{s: "https://github.com/foo/kubeflow"},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt // Re-initializing variable so it is not changed while executing the closure below
|
||||
|
Loading…
Reference in New Issue
Block a user