Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into wingkwong/master
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed May 20, 2020
2 parents f644c11 + 4e73c83 commit 509be34
Show file tree
Hide file tree
Showing 21 changed files with 560 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ jobs:
token: ${{secrets.SITE_GITHUB_TOKEN}}
- name: Publish documentation site
if: "!contains(github.ref, '-')" # skip prereleases
env:
GIT_COMMITTER_NAME: cli automation
GIT_AUTHOR_NAME: cli automation
GIT_COMMITTER_EMAIL: [email protected]
GIT_AUTHOR_EMAIL: [email protected]
run: make site-publish
- name: Move project cards
if: "!contains(github.ref, '-')" # skip prereleases
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin
/share/man/man1
/gh-cli
.envrc
/dist
Expand Down
13 changes: 12 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ release:
before:
hooks:
- go mod tidy
- make manpages

builds:
- <<: &build_defaults
Expand All @@ -17,10 +18,12 @@ builds:
id: macos
goos: [darwin]
goarch: [amd64]

- <<: *build_defaults
id: linux
goos: [linux]
goarch: [386, amd64, arm64]

- <<: *build_defaults
id: windows
goos: [windows]
Expand All @@ -35,11 +38,16 @@ archives:
replacements:
darwin: macOS
format: tar.gz
files:
- LICENSE
- ./share/man/man1/gh*.1
- id: windows
builds: [windows]
<<: *archive_defaults
wrap_in_directory: false
format: zip
files:
- LICENSE

brews:
- name: gh
Expand All @@ -57,8 +65,9 @@ brews:
depends_on "go"
end
install: |
system "make" if build.head?
system "make", "bin/gh", "manpages" if build.head?
bin.install "bin/gh"
man1.install Dir["./share/man/man1/gh*.1"]
(bash_completion/"gh.sh").write `#{bin}/gh completion -s bash`
(zsh_completion/"_gh").write `#{bin}/gh completion -s zsh`
(fish_completion/"gh.fish").write `#{bin}/gh completion -s fish`
Expand All @@ -76,6 +85,8 @@ nfpms:
formats:
- deb
- rpm
files:
"./share/man/man1/gh*.1": "/usr/share/man/man1"

scoop:
bucket:
Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ test:
go test ./...
.PHONY: test

site:
git clone https://github.com/github/cli.github.com.git "$@"
site: bin/gh
bin/gh repo clone github/cli.github.com "$@"

site-docs: site
git -C site pull
git -C site rm 'manual/gh*.md' 2>/dev/null || true
go run ./cmd/gen-docs site/manual
go run ./cmd/gen-docs --website --doc-path site/manual
for f in site/manual/gh*.md; do sed -i.bak -e '/^### SEE ALSO/,$$d' "$$f"; done
rm -f site/manual/*.bak
git -C site add 'manual/gh*.md'
Expand All @@ -44,3 +44,8 @@ endif
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
git -C site push
.PHONY: site-publish


.PHONY: manpages
manpages:
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/
3 changes: 2 additions & 1 deletion api/queries_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func TestIssueList(t *testing.T) {
} } }
`))

_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251, "")
repo, _ := ghrepo.FromFullName("OWNER/REPO")
_, err := IssueList(client, repo, "open", []string{}, "", 251, "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
57 changes: 57 additions & 0 deletions api/queries_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package api

import (
"context"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"

"github.com/shurcooL/githubv4"
Expand Down Expand Up @@ -201,6 +204,39 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
return
}

func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNum int) (string, error) {
url := fmt.Sprintf("https://api.github.com/repos/%s/pulls/%d",
ghrepo.FullName(baseRepo), prNum)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}

req.Header.Set("Accept", "application/vnd.github.v3.diff; charset=utf-8")

resp, err := c.http.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

if resp.StatusCode == 200 {
return string(b), nil
}

if resp.StatusCode == 404 {
return "", &NotFoundError{errors.New("pull request not found")}
}

return "", errors.New("pull request diff lookup failed")

}

func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) {
type edges struct {
TotalCount int
Expand Down Expand Up @@ -953,6 +989,27 @@ func PullRequestMerge(client *Client, repo ghrepo.Interface, pr *PullRequest, m
return err
}

func PullRequestReady(client *Client, repo ghrepo.Interface, pr *PullRequest) error {
var mutation struct {
MarkPullRequestReadyForReviewInput struct {
PullRequest struct {
ID githubv4.ID
}
} `graphql:"markPullRequestReadyForReview(input: $input)"`
}

type MarkPullRequestReadyForReviewInput struct {
PullRequestID githubv4.ID `json:"pullRequestId"`
}

input := MarkPullRequestReadyForReviewInput{PullRequestID: pr.ID}

v4 := githubv4.NewClient(client.http)
err := v4.Mutate(context.Background(), &mutation, input, nil)

return err
}

func min(a, b int) int {
if a < b {
return a
Expand Down
4 changes: 2 additions & 2 deletions api/queries_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Test_RepoMetadata(t *testing.T) {
http := &httpmock.Registry{}
client := NewClient(ReplaceTripper(http))

repo := ghrepo.FromFullName("OWNER/REPO")
repo, _ := ghrepo.FromFullName("OWNER/REPO")
input := RepoMetadataInput{
Assignees: true,
Reviewers: true,
Expand Down Expand Up @@ -181,7 +181,7 @@ func Test_RepoResolveMetadataIDs(t *testing.T) {
http := &httpmock.Registry{}
client := NewClient(ReplaceTripper(http))

repo := ghrepo.FromFullName("OWNER/REPO")
repo, _ := ghrepo.FromFullName("OWNER/REPO")
input := RepoResolveInput{
Assignees: []string{"monalisa", "hubot"},
Reviewers: []string{"monalisa", "octocat", "OWNER/core", "/robots"},
Expand Down
49 changes: 42 additions & 7 deletions cmd/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,58 @@ import (

"github.com/cli/cli/command"
"github.com/spf13/cobra/doc"
"github.com/spf13/pflag"
)

func main() {
if len(os.Args) < 2 {
fatal("Usage: gen-docs <destination-dir>")

var flagError pflag.ErrorHandling
docCmd := pflag.NewFlagSet("", flagError)
manPage := docCmd.BoolP("man-page", "", false, "Generate manual pages")
website := docCmd.BoolP("website", "", false, "Generate website pages")
dir := docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files")
help := docCmd.BoolP("help", "h", false, "Help about any command")

if err := docCmd.Parse(os.Args); err != nil {
os.Exit(1)
}
dir := os.Args[1]

err := os.MkdirAll(dir, 0755)
if err != nil {
fatal(err)
if *help {
_, err := fmt.Fprintf(os.Stderr, "Usage of %s:\n\n%s", os.Args[0], docCmd.FlagUsages())
if err != nil {
fatal(err)
}
os.Exit(1)
}

if *dir == "" {
fatal("no dir set")
}

err = doc.GenMarkdownTreeCustom(command.RootCmd, dir, filePrepender, linkHandler)
err := os.MkdirAll(*dir, 0755)
if err != nil {
fatal(err)
}

if *website {
err = doc.GenMarkdownTreeCustom(command.RootCmd, *dir, filePrepender, linkHandler)
if err != nil {
fatal(err)
}
}

if *manPage {
header := &doc.GenManHeader{
Title: "gh",
Section: "1",
Source: "", //source and manual are just put at the top of the manpage, before name
Manual: "", //if source is an empty string, it's set to "Auto generated by spf13/cobra"
}
err = doc.GenManTree(command.RootCmd, header, *dir)
if err != nil {
fatal(err)
}
}
}

func filePrepender(filename string) string {
Expand Down
4 changes: 2 additions & 2 deletions command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Current respected settings:

var configGetCmd = &cobra.Command{
Use: "get <key>",
Short: "Prints the value of a given configuration key.",
Short: "Prints the value of a given configuration key",
Long: `Get the value for a given configuration key.
Examples:
Expand All @@ -45,7 +45,7 @@ Examples:

var configSetCmd = &cobra.Command{
Use: "set <key> <value>",
Short: "Updates configuration with the value of a given key.",
Short: "Updates configuration with the value of a given key",
Long: `Update the configuration by setting a key to a value.
Examples:
Expand Down
4 changes: 2 additions & 2 deletions command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ With '--web', open the issue in a web browser instead.`,
}
var issueCloseCmd = &cobra.Command{
Use: "close {<number> | <url>}",
Short: "close issue",
Short: "Close issue",
Args: cobra.ExactArgs(1),
RunE: issueClose,
}
var issueReopenCmd = &cobra.Command{
Use: "reopen {<number> | <url>}",
Short: "reopen issue",
Short: "Reopen issue",
Args: cobra.ExactArgs(1),
RunE: issueReopen,
}
Expand Down
Loading

0 comments on commit 509be34

Please sign in to comment.