@@ -63,7 +63,7 @@ var ctx = context.Background()
63
63
// getRef returns the commit branch reference object if it exists or creates it
64
64
// from the base branch before returning it.
65
65
func getRef () (ref * github.Reference , err error ) {
66
- if ref , _ , err = client .Git .GetRef (ctx , * sourceOwner , * sourceRepo , "refs/heads/" + * commitBranch ); err == nil {
66
+ if ref , _ , err = client .Git .GetRef (ctx , * sourceOwner , * sourceRepo , branchRef ( * commitBranch ) ); err == nil {
67
67
return ref , nil
68
68
}
69
69
@@ -78,14 +78,19 @@ func getRef() (ref *github.Reference, err error) {
78
78
}
79
79
80
80
var baseRef * github.Reference
81
- if baseRef , _ , err = client .Git .GetRef (ctx , * sourceOwner , * sourceRepo , "refs/heads/" + * baseBranch ); err != nil {
81
+ if baseRef , _ , err = client .Git .GetRef (ctx , * sourceOwner , * sourceRepo , branchRef ( * baseBranch ) ); err != nil {
82
82
return nil , err
83
83
}
84
- newRef := & github.Reference {Ref : github .Ptr ("refs/heads/" + * commitBranch ), Object : & github.GitObject {SHA : baseRef .Object .SHA }}
84
+ newRef := & github.Reference {Ref : github .Ptr (branchRef ( * commitBranch ) ), Object : & github.GitObject {SHA : baseRef .Object .SHA }}
85
85
ref , _ , err = client .Git .CreateRef (ctx , * sourceOwner , * sourceRepo , newRef )
86
86
return ref , err
87
87
}
88
88
89
+ // branchRef generates the fully qualified git reference for the given branch name.
90
+ func branchRef (name string ) string {
91
+ return "refs/heads/" + name
92
+ }
93
+
89
94
// getTree generates the tree to commit based on the given files and the commit
90
95
// of the ref you got in getRef.
91
96
func getTree (ref * github.Reference ) (tree * github.Tree , err error ) {
0 commit comments