Skip to content

Commit

Permalink
wip: adding functionality for release branches
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Fu <[email protected]>
Co-authored-by: Taylor Silva <[email protected]>
  • Loading branch information
clarafu and taylorsilva committed Jul 21, 2020
1 parent 7a0cfc0 commit 3b9f979
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ func (g GitHub) FetchLatestReleaseCommitSHA(owner, repo string) (string, error)
return releaseSHA, nil
}

func (g GitHub) FetchCommitFromTag(owner, repo, tag string) (string, error) {
var releaseSHAQuery struct {
Repository struct {
Refs struct {
Nodes []struct {
Target struct {
Oid string
}
}
} `graphql:"refs(refPrefix: "refs/tags/", first: 1, query: $tag)"`
} `graphql:"repository(owner: $owner, name: $name)"`
}

releaseSHAVariables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(repo),
"tag": githubv4.String(tag),
}

err := g.client.Query(context.Background(), &releaseSHAQuery, releaseSHAVariables)
if err != nil {
return "", err
}

// If the repository does not have a release, return an empty string
var releaseSHA string
if len(releaseSHAQuery.Repository.Refs.Nodes) > 0 {
releaseSHA = releaseSHAQuery.Repository.Refs.Nodes[0].Target.Oid
}

return releaseSHA, nil
}

func (g GitHub) FetchPullRequestsAfterCommit(owner, repo, branch, commitSHA string) ([]PullRequest, error) {
var pullRequestsQuery struct {
Repository struct {
Expand Down

0 comments on commit 3b9f979

Please sign in to comment.