Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into issue-update
Browse files Browse the repository at this point in the history
  • Loading branch information
probablycorey committed Nov 18, 2019
1 parent 75a3496 commit e5af5be
Show file tree
Hide file tree
Showing 23 changed files with 1,354 additions and 65 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ The #ce-cli team is working on a publicly available CLI tool to reduce the frict

This tool is an endeavor separate from [github/hub](https://github.com/github/hub), which acts as a proxy to `git`, since our aim is to reimagine from scratch the kind of command line interface to GitHub that would serve our users' interests best.

# Installation

_warning, gh is in a very alpha phase_

`brew install github/gh/gh`

That's it. You are now ready to use `gh` on the command line. 🥳

# Process

- [Demo planning doc](https://docs.google.com/document/d/18ym-_xjFTSXe0-xzgaBn13Su7MEhWfLE5qSNPJV4M0A/edit)
- [Weekly tracking issue](https://github.com/github/gh-cli/labels/tracking%20issue)
- [Weekly sync notes](https://docs.google.com/document/d/1eUo9nIzXbC1DG26Y3dk9hOceLua2yFlwlvFPZ82MwHg/edit)

# How to create a release

This can all be done from your local terminal.

1. `git tag 'vVERSION_NUMBER' # example git tag 'v0.0.1'`
2. `git push origin vVERSION_NUMBER`
3. Wait a few minutes for the build to run and CI to pass. Look at the [actions tab](https://github.com/github/gh-cli/actions) to check the progress.
4. Go to https://github.com/github/homebrew-gh/releases and look at the release
215 changes: 207 additions & 8 deletions api/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,93 @@ type PullRequest struct {
State string
URL string
HeadRefName string

HeadRepositoryOwner struct {
Login string
}
HeadRepository struct {
Name string
DefaultBranchRef struct {
Name string
}
}
IsCrossRepository bool
MaintainerCanModify bool

ReviewDecision string

Commits struct {
Nodes []struct {
Commit struct {
StatusCheckRollup struct {
Contexts struct {
Nodes []struct {
State string
Conclusion string
}
}
}
}
}
}
}

func (pr PullRequest) HeadLabel() string {
if pr.IsCrossRepository {
return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName)
}
return pr.HeadRefName
}

type PullRequestReviewStatus struct {
ChangesRequested bool
Approved bool
ReviewRequired bool
}

func (pr *PullRequest) ReviewStatus() PullRequestReviewStatus {
status := PullRequestReviewStatus{}
switch pr.ReviewDecision {
case "CHANGES_REQUESTED":
status.ChangesRequested = true
case "APPROVED":
status.Approved = true
case "REVIEW_REQUIRED":
status.ReviewRequired = true
}
return status
}

type PullRequestChecksStatus struct {
Pending int
Failing int
Passing int
Total int
}

func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
if len(pr.Commits.Nodes) == 0 {
return
}
commit := pr.Commits.Nodes[0].Commit
for _, c := range commit.StatusCheckRollup.Contexts.Nodes {
state := c.State
if state == "" {
state = c.Conclusion
}
switch state {
case "SUCCESS", "NEUTRAL", "SKIPPED":
summary.Passing++
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
summary.Failing++
case "EXPECTED", "QUEUED", "PENDING", "IN_PROGRESS":
summary.Pending++
default:
panic(fmt.Errorf("unsupported status: %q", state))
}
summary.Total++
}
return
}

type Repo interface {
Expand Down Expand Up @@ -43,27 +130,54 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st
}

query := `
fragment pr on PullRequest {
number
title
url
headRefName
}
fragment pr on PullRequest {
number
title
url
headRefName
headRefName
headRepositoryOwner {
login
}
isCrossRepository
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
contexts(last: 100) {
nodes {
...on StatusContext {
state
}
...on CheckRun {
conclusion
}
}
}
}
}
}
}
}
fragment prWithReviews on PullRequest {
...pr
reviewDecision
}
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
repository(owner: $owner, name: $repo) {
pullRequests(headRefName: $headRefName, states: OPEN, first: 1) {
edges {
node {
...pr
...prWithReviews
}
}
}
}
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
edges {
node {
...pr
...prWithReviews
}
}
pageInfo {
Expand Down Expand Up @@ -127,6 +241,48 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st
return &payload, nil
}

func PullRequestByNumber(client *Client, ghRepo Repo, number int) (*PullRequest, error) {
type response struct {
Repository struct {
PullRequest PullRequest
}
}

query := `
query($owner: String!, $repo: String!, $pr_number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr_number) {
headRefName
headRepositoryOwner {
login
}
headRepository {
name
defaultBranchRef {
name
}
}
isCrossRepository
maintainerCanModify
}
}
}`

variables := map[string]interface{}{
"owner": ghRepo.RepoOwner(),
"repo": ghRepo.RepoName(),
"pr_number": number,
}

var resp response
err := client.GraphQL(query, variables, &resp)
if err != nil {
return nil, err
}

return &resp.Repository.PullRequest, nil
}

func PullRequestsForBranch(client *Client, ghRepo Repo, branch string) ([]PullRequest, error) {
type response struct {
Repository struct {
Expand Down Expand Up @@ -173,6 +329,45 @@ func PullRequestsForBranch(client *Client, ghRepo Repo, branch string) ([]PullRe
return prs, nil
}

func CreatePullRequest(client *Client, ghRepo Repo, params map[string]interface{}) (*PullRequest, error) {
repoID, err := GitHubRepoId(client, ghRepo)
if err != nil {
return nil, err
}

query := `
mutation CreatePullRequest($input: CreatePullRequestInput!) {
createPullRequest(input: $input) {
pullRequest {
url
}
}
}`

inputParams := map[string]interface{}{
"repositoryId": repoID,
}
for key, val := range params {
inputParams[key] = val
}
variables := map[string]interface{}{
"input": inputParams,
}

result := struct {
CreatePullRequest struct {
PullRequest PullRequest
}
}{}

err = client.GraphQL(query, variables, &result)
if err != nil {
return nil, err
}

return &result.CreatePullRequest.PullRequest, nil
}

func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]PullRequest, error) {
type response struct {
Repository struct {
Expand Down Expand Up @@ -214,6 +409,10 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
state
url
headRefName
headRepositoryOwner {
login
}
isCrossRepository
}
}
pageInfo {
Expand Down
6 changes: 3 additions & 3 deletions api/queries_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
}
query($owner: String!, $repo: String!, $since: DateTime!, $viewer: String!, $per_page: Int = 10) {
assigned: repository(owner: $owner, name: $repo) {
issues(filterBy: {assignee: $viewer}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
...issue
Expand All @@ -101,7 +101,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
}
}
mentioned: repository(owner: $owner, name: $repo) {
issues(filterBy: {mentioned: $viewer}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
...issue
Expand All @@ -110,7 +110,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
}
}
recent: repository(owner: $owner, name: $repo) {
issues(filterBy: {since: $since}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
issues(filterBy: {since: $since, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
...issue
Expand Down
2 changes: 1 addition & 1 deletion command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
&cobra.Command{
Use: "view <issue-number>",
Args: cobra.MinimumNArgs(1),
Short: "Open an issue in the browser",
Short: "View an issue in the browser",
RunE: issueView,
},
)
Expand Down
Loading

0 comments on commit e5af5be

Please sign in to comment.