@@ -55,14 +55,26 @@ func (r *RepoInfo) SetDefault() error {
5555}
5656
5757func (r * RepoInfo ) GetRepoOwner () string {
58+ // if org or owner is not empty, return org/owner
5859 if r .Org != "" {
5960 return r .Org
6061 }
61- return r .Owner
62+ if r .Owner != "" {
63+ return r .Owner
64+ }
65+ // else return owner extract from url
66+ if r .CloneURL != "" {
67+ owner , _ , err := r .CloneURL .extractRepoOwnerAndName ()
68+ if err != nil {
69+ log .Warnf ("git GetRepoName failed %s" , err )
70+ }
71+ return owner
72+ }
73+ return ""
6274}
6375
6476func (r * RepoInfo ) GetRepoPath () string {
65- return fmt .Sprintf ("%s/%s" , r .GetRepoOwner (), r .Repo )
77+ return fmt .Sprintf ("%s/%s" , r .GetRepoOwner (), r .GetRepoName () )
6678}
6779
6880func (r * RepoInfo ) GetRepoName () string {
@@ -82,7 +94,7 @@ func (r *RepoInfo) GetRepoName() string {
8294func (r * RepoInfo ) GetCloneURL () string {
8395 var cloneURL string
8496 if r .CloneURL != "" {
85- cloneURL = string (r .CloneURL )
97+ cloneURL = string (r .CloneURL . addGithubURLScheme () )
8698 } else {
8799 cloneURL = string (r .buildScmURL ())
88100 }
@@ -107,10 +119,9 @@ func (r *RepoInfo) getBranchWithDefault() string {
107119 if branch != "" {
108120 return branch
109121 }
110- switch r .RepoType {
111- case "github" :
122+ if r .IsGithubRepo () {
112123 branch = "main"
113- case "gitlab" :
124+ } else {
114125 branch = "master"
115126 }
116127 return branch
@@ -143,7 +154,6 @@ func (r *RepoInfo) updateFieldsFromURLField() error {
143154 // 1. config basic info for different repo type
144155 if r .IsGithubRepo () {
145156 r .RepoType = "github"
146- r .CloneURL = r .CloneURL .addGithubURLScheme ()
147157 } else {
148158 r .RepoType = "gitlab"
149159 // extract gitlab baseURL from url string
@@ -205,7 +215,7 @@ func (r *RepoInfo) checkValid() error {
205215// extractRepoOwnerAndName will get repoOwner and repoName from ScmURL
206216func (u ScmURL ) extractRepoOwnerAndName () (string , string , error ) {
207217 var paths string
208- ScmURLStr := string (u )
218+ ScmURLStr := string (u . addGithubURLScheme () )
209219 c , err := url .ParseRequestURI (ScmURLStr )
210220 if err != nil {
211221 if strings .Contains (ScmURLStr , "git@" ) {
@@ -232,7 +242,7 @@ func (u ScmURL) extractRepoOwnerAndName() (string, string, error) {
232242 return repoOwner , repoName , nil
233243}
234244
235- // formatGithubCloneURL will add "https://" in github url config if it doesn't contain schme
245+ // addGithubURLScheme will add "https://" in github url config if it doesn't contain schme
236246func (u ScmURL ) addGithubURLScheme () ScmURL {
237247 cloneURL := string (u )
238248 if ! strings .Contains (cloneURL , "git@" ) && ! strings .HasPrefix (cloneURL , "http" ) {
0 commit comments