@@ -681,6 +681,28 @@ func getLastBumpCommit(gerritAuthor, commitTag string) (string, error) {
681
681
return outBuf .String (), nil
682
682
}
683
683
684
+ // getDefaultBranch retrieves the default branch name of a given repository
685
+ // using the provided GitHub client. It fetches the repository details and
686
+ // extracts the default branch. It returns a string representing the default
687
+ // branch name and error if the repository details cannot be retrieved.
688
+ func getDefaultBranch (gc github.Client , org , repo string ) (string , error ) {
689
+ repository , err := gc .GetRepo (org , repo )
690
+ if err != nil {
691
+ return "" , fmt .Errorf ("failed to get repository details for %s/%s: %w" , org , repo , err )
692
+ }
693
+ return repository .DefaultBranch , nil
694
+ }
695
+
696
+ // createOrUpdatePROnDefaultBranch retrieves the default branch for the repository
697
+ // and creates/updates a PR on that branch without requiring the caller to specify the branch.
698
+ func createOrUpdatePROnDefaultBranch (gc github.Client , opts * Options , prTitle , prBody string ) error {
699
+ defaultBranch , err := getDefaultBranch (gc , opts .GitHubOrg , opts .GitHubRepo )
700
+ if err != nil {
701
+ return fmt .Errorf ("failed to get default branch for %s/%s: %w" , opts .GitHubOrg , opts .GitHubRepo , err )
702
+ }
703
+ return UpdatePR (gc , opts .GitHubOrg , opts .GitHubRepo , "" , opts .GitHubLogin , defaultBranch , opts .HeadBranchName , true , prTitle , prBody )
704
+ }
705
+
684
706
// getChangeId generates a change ID for the gerrit PR that is deterministic
685
707
// rather than being random as is normally preferable.
686
708
// In particular this chooses a change ID by hashing the last commit by the
0 commit comments