MCPcopy Create free account
hub / github.com/bluekeyes/patch2pr / Commit

Method Commit

graphql_applier.go:284–307  ·  view source on GitHub ↗

Commit creates a commit with all pending file changes. It updates the branch ref to point at the new commit and returns the OID (SHA) of the commit. The branch must already exist and reference at the current base commit of the GraphQLApplier. If header is not nil, Apply uses it to set the commit me

(ctx context.Context, ref string, header *gitdiff.PatchHeader)

Source from the content-addressed store, hash-verified

282// other fields set in header. In particular, the commit timestamp, author, and
283// committer are always set by GitHub.
284func (a *GraphQLApplier) Commit(ctx context.Context, ref string, header *gitdiff.PatchHeader) (string, error) {
285 if len(a.changes) == 0 {
286 return "", fmt.Errorf("no pending file changes")
287 }
288
289 var m struct {
290 CreateCommitOnBranch struct {
291 Commit struct {
292 OID string
293 }
294 } `graphql:"createCommitOnBranch(input: $input)"`
295 }
296
297 input := a.makeInput(ref, header)
298 if err := a.v4client.Mutate(ctx, &m, input, nil); err != nil {
299 return "", fmt.Errorf("commit failed: %w", err)
300 }
301
302 oid := m.CreateCommitOnBranch.Commit.OID
303 a.commit = oid
304 a.changes = make(map[string]pendingChange)
305
306 return oid, nil
307}
308
309func (a *GraphQLApplier) makeInput(ref string, header *gitdiff.PatchHeader) githubv4.CreateCommitOnBranchInput {
310 branch := githubv4.String(ref)

Callers 1

runGraphQLPatchTestFunction · 0.95

Calls 1

makeInputMethod · 0.95

Tested by 1

runGraphQLPatchTestFunction · 0.76