@@ -30,10 +30,16 @@ const (
3030// CloneRepos clones the repo
3131func (r * Releaser ) cloneRepos (dir string , request * source.ReleaseRequest ) (* ugit.Repository , error ) {
3232 logrus .Infof ("Cloning %s" , r .UpstreamKrewIndexRepoCloneURL )
33+ client := getGitHubClient (r .Token )
34+ remoteRepo , err := r .getRepo (client , r .UpstreamKrewIndexRepoOwner , r .UpstreamKrewIndexRepo )
35+ if err != nil {
36+ return nil , err
37+ }
38+
3339 repo , err := ugit .PlainClone (dir , false , & ugit.CloneOptions {
3440 URL : r .UpstreamKrewIndexRepoCloneURL ,
3541 Progress : os .Stdout ,
36- ReferenceName : plumbing .Master ,
42+ ReferenceName : plumbing .ReferenceName ( * remoteRepo . DefaultBranch ) ,
3743 SingleBranch : true ,
3844 Auth : r .getAuth (),
3945 RemoteName : OriginNameUpstream ,
@@ -123,23 +129,39 @@ func getPushRefSpec(branchName string) string {
123129 return fmt .Sprintf ("refs/heads/%s:refs/heads/%s" , branchName , branchName )
124130}
125131
132+ func getGitHubClient (token string ) * github.Client {
133+ ts := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : token })
134+ tc := oauth2 .NewClient (context .TODO (), ts )
135+ return github .NewClient (tc )
136+ }
137+
138+ func (r * Releaser ) getRepo (client * github.Client , owner string , repoName string ) (* github.Repository , error ) {
139+ repo , _ , err := client .Repositories .Get (context .TODO (), owner , repoName )
140+ if err != nil {
141+ return nil , err
142+ }
143+ return repo , nil
144+ }
145+
126146// SubmitPR submits the PR
127147func (r * Releaser ) submitPR (request * source.ReleaseRequest ) (string , error ) {
128- ts := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : r .Token })
129- tc := oauth2 .NewClient (context .TODO (), ts )
130- client := github .NewClient (tc )
148+ client := getGitHubClient (r .Token )
149+ repo , err := r .getRepo (client , r .UpstreamKrewIndexRepoOwner , r .UpstreamKrewIndexRepo )
150+ if err != nil {
151+ return "" , err
152+ }
131153
132154 prr := & github.NewPullRequest {
133155 Title : r .getTitle (request ),
134156 Head : r .getHead (request ),
135- Base : github .String ("master" ),
157+ Base : github .String (* repo . DefaultBranch ),
136158 Body : r .getPRBody (request ),
137159 }
138160
139161 logrus .Infof ("creating pr with title %q, \n head %q, \n base %q, \n body %q" ,
140162 github .Stringify (r .getTitle (request )),
141163 github .Stringify (r .getHead (request )),
142- "master" ,
164+ github . Stringify ( * repo . DefaultBranch ) ,
143165 github .Stringify (r .getPRBody (request )),
144166 )
145167
0 commit comments