@@ -681,6 +681,31 @@ 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
+ // Fetch the default branch using existing repo details from opts
700
+ defaultBranch , err := getDefaultBranch (gc , opts .GitHubOrg , opts .GitHubRepo )
701
+ if err != nil {
702
+ return fmt .Errorf ("failed to get default branch for %s/%s: %w" , opts .GitHubOrg , opts .GitHubRepo , err )
703
+ }
704
+
705
+ // Use the existing updatePR function to create/update the PR
706
+ return UpdatePR (gc , opts .GitHubOrg , opts .GitHubRepo , "" , opts .GitHubLogin , defaultBranch , opts .HeadBranchName , true , prTitle , prBody )
707
+ }
708
+
684
709
// getChangeId generates a change ID for the gerrit PR that is deterministic
685
710
// rather than being random as is normally preferable.
686
711
// In particular this chooses a change ID by hashing the last commit by the
0 commit comments