Skip to content

Commit

Permalink
create branch through graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisStatham committed Jul 16, 2024
1 parent 083eb9f commit 96733f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions internal/scm/github/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,28 @@ func graphQLEndpoint(u string) (string, error) {
return baseEndpoint.String(), nil
}

func (g *Github) getRepositoryID(ctx context.Context, owner string, name string) (error, string) {
func (g *Github) getRepositoryID(ctx context.Context, owner string, name string) (string, error) {
query := `query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
databaseId
}
repository(owner: $owner, name: $name) {
id
}
}`

var v getRepositoryInput

var result getRepositoryOutput
v.Name = name
v.Owner = owner

var result getRepositoryOutput

err := g.makeGraphQLRequest(ctx, query, v, &result)

if err != nil {
return err, ""
return "", err
}

return nil, result.Data.Repository.DatabaseId
return result.Repository.ID, nil
}

func (g *Github) createRef(ctx context.Context, branchName string, oid string, repositoryId string) error {
func (g *Github) createRef(ctx context.Context, branchName string, oid string, iD string) error {
query := `mutation($input: CreateRefInput!){
createRef(input: $input) {
ref {
Expand All @@ -136,9 +134,11 @@ func (g *Github) createRef(ctx context.Context, branchName string, oid string, r

var v createRefInput

v.Input.Name = branchName
v.Input.Name = "refs/heads/" + branchName
v.Input.Oid = oid
v.Input.RepositoryId = repositoryId
v.Input.RepositoryID = iD

fmt.Printf("%v", v)

var result map[string]interface{}

Expand All @@ -163,7 +163,7 @@ func (g *Github) CommitThroughAPI(ctx context.Context, input CreateCommitOnBranc

var v createCommitOnBranchInput

err, repoID := g.getRepositoryID(ctx, input.Owner, input.BranchName)
repoID, err := g.getRepositoryID(ctx, input.Owner, input.RepositoryName)

if err != nil {
return err
Expand Down Expand Up @@ -275,7 +275,7 @@ type createRefInput struct {
Input struct {
Name string `json:"name"`
Oid string `json:"oid"`
RepositoryId string `json:"repositoryId"`
RepositoryID string `json:"repositoryId"`
} `json:"input"`
}

Expand All @@ -285,11 +285,9 @@ type getRepositoryInput struct {
}

type getRepositoryOutput struct {
Data struct {
Repository struct {
DatabaseId string `json:"databaseId"`
} `json:"repository"`
} `json:"data"`
Repository struct {
ID string `json:"id"`
} `json:"repository"`
}

type CreateCommitOnBranchInput struct {
Expand Down
Binary file modified multi-gitter
Binary file not shown.

0 comments on commit 96733f7

Please sign in to comment.