MCPcopy Index your code
hub / github.com/google/go-github / getRef

Function getRef

example/commitpr/main.go:67–89  ·  view source on GitHub ↗

getRef returns the commit branch reference object if it exists or creates it from the base branch before returning it.

()

Source from the content-addressed store, hash-verified

65// getRef returns the commit branch reference object if it exists or creates it
66// from the base branch before returning it.
67func getRef() (ref *github.Reference, err error) {
68 if ref, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, branchRef(*commitBranch)); err == nil {
69 return ref, nil
70 }
71
72 // We consider that an error means the branch has not been found and needs to
73 // be created.
74 if *commitBranch == *baseBranch {
75 return nil, errors.New("the commit branch does not exist but `-base-branch` is the same as `-commit-branch`")
76 }
77
78 if *baseBranch == "" {
79 return nil, errors.New("the `-base-branch` should not be set to an empty string when the branch specified by `-commit-branch` does not exists")
80 }
81
82 var baseRef *github.Reference
83 if baseRef, _, err = client.Git.GetRef(ctx, *sourceOwner, *sourceRepo, branchRef(*baseBranch)); err != nil {
84 return nil, err
85 }
86 newRef := github.CreateRef{Ref: branchRef(*commitBranch), SHA: *baseRef.Object.SHA}
87 ref, _, err = client.Git.CreateRef(ctx, *sourceOwner, *sourceRepo, newRef)
88 return ref, err
89}
90
91// branchRef generates the fully qualified git reference for the given branch name.
92func branchRef(name string) string {

Callers 1

mainFunction · 0.85

Calls 3

branchRefFunction · 0.85
CreateRefMethod · 0.80
GetRefMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…