X Tutup
Skip to content

Commit 4148cf7

Browse files
committed
Merge remote-tracking branch 'origin' into win-ansi-color
2 parents 4be04ad + 07df89f commit 4148cf7

File tree

7 files changed

+65
-39
lines changed

7 files changed

+65
-39
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ _warning, gh is in a very alpha phase_
1414

1515
## Debian/Ubuntu Linux
1616

17-
1. Download the latest `.deb` file from the [releases page](https://github.com/github/gh-cli/releases)
18-
2. Install it with `sudo dpkg -i gh_0.2.2_linux_amd64.deb`, changing version number accordingly
17+
1. `sudo apt install git` if you don't already have git
18+
2. Download the `.deb` file from the [releases page](https://github.com/github/gh-cli/releases/latest)
19+
3. `sudo dpkg -i gh_*_linux_amd64.deb` install the downloaded file
1920

2021
_(Uninstall with `sudo apt remove gh`)_
2122

2223
## Fedora/Centos Linux
2324

24-
1. Download the latest `.rpm` file from the [releases page](https://github.com/github/gh-cli/releases)
25-
2. Install it with `sudo yum localinstall gh_0.2.2_linux_amd64.rpm`, changing version number accordingly
25+
1. Download the `.rpm` file from the [releases page](https://github.com/github/gh-cli/releases/latest)
26+
2. `sudo yum localinstall gh_*_linux_amd64.rpm` install the downloaded file
2627

2728
_(Uninstall with `sudo yum remove gh`)_
2829

2930
## Other Linux
3031

31-
1. Download the latest `_linux_amd64.tar.gz` file from the [releases page](https://github.com/github/gh-cli/releases)
32-
2. `tar -xvf gh_0.2.2_linux_amd64.tar.gz`, changing version number accordingly
33-
3. Copy the uncompressed `gh` somewhere on your `$PATH` (e.g. `sudo cp gh /usr/local/bin/`)
32+
1. Download the `_linux_amd64.tar.gz` file from the [releases page](https://github.com/github/gh-cli/releases/latest)
33+
2. `tar -xf gh_*_linux_amd64.tar.gz`
34+
3. Copy the uncompressed `gh` somewhere on your `$PATH` (e.g. `sudo cp gh_*_linux_amd64/bin/gh /usr/local/bin/`)
3435

3536
_(Uninstall with `rm`)_
3637

api/queries_issue.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package api
22

33
import (
44
"fmt"
5-
"time"
65
)
76

87
type IssuesPayload struct {
98
Assigned []Issue
109
Mentioned []Issue
11-
Recent []Issue
10+
Authored []Issue
1211
}
1312

1413
type Issue struct {
@@ -91,11 +90,11 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
9190
type response struct {
9291
Assigned apiIssues
9392
Mentioned apiIssues
94-
Recent apiIssues
93+
Authored apiIssues
9594
}
9695

9796
query := fragments + `
98-
query($owner: String!, $repo: String!, $since: DateTime!, $viewer: String!, $per_page: Int = 10) {
97+
query($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) {
9998
assigned: repository(owner: $owner, name: $repo) {
10099
issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
101100
nodes {
@@ -110,8 +109,8 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
110109
}
111110
}
112111
}
113-
recent: repository(owner: $owner, name: $repo) {
114-
issues(filterBy: {since: $since, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
112+
authored: repository(owner: $owner, name: $repo) {
113+
issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
115114
nodes {
116115
...issue
117116
}
@@ -122,12 +121,10 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
122121

123122
owner := ghRepo.RepoOwner()
124123
repo := ghRepo.RepoName()
125-
since := time.Now().UTC().Add(time.Hour * -24).Format("2006-01-02T15:04:05-0700")
126124
variables := map[string]interface{}{
127125
"owner": owner,
128126
"repo": repo,
129127
"viewer": currentUsername,
130-
"since": since,
131128
}
132129

133130
var resp response
@@ -139,7 +136,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
139136
payload := IssuesPayload{
140137
Assigned: resp.Assigned.Issues.Nodes,
141138
Mentioned: resp.Mentioned.Issues.Nodes,
142-
Recent: resp.Recent.Issues.Nodes,
139+
Authored: resp.Authored.Issues.Nodes,
143140
}
144141

145142
return &payload, nil

auth/oauth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"runtime"
14+
"strings"
1415
)
1516

1617
func randomString(length int) (string, error) {
@@ -101,11 +102,14 @@ func openInBrowser(url string) error {
101102
args = []string{"open"}
102103
case "windows":
103104
args = []string{"cmd", "/c", "start"}
105+
r := strings.NewReplacer("&", "^&")
106+
url = r.Replace(url)
104107
default:
105108
args = []string{"xdg-open"}
106109
}
107110

108111
args = append(args, url)
109112
cmd := exec.Command(args[0], args[1:]...)
113+
cmd.Stderr = os.Stderr
110114
return cmd.Run()
111115
}

command/issue.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,9 @@ import (
1414

1515
func init() {
1616
RootCmd.AddCommand(issueCmd)
17-
issueCmd.AddCommand(
18-
&cobra.Command{
19-
Use: "status",
20-
Short: "Show status of relevant issues",
21-
RunE: issueStatus,
22-
},
23-
&cobra.Command{
24-
Use: "view <issue-number>",
25-
Args: cobra.MinimumNArgs(1),
26-
Short: "View an issue in the browser",
27-
RunE: issueView,
28-
},
29-
)
3017
issueCmd.AddCommand(issueCreateCmd)
18+
issueCmd.AddCommand(issueStatusCmd)
19+
issueCmd.AddCommand(issueViewCmd)
3120
issueCreateCmd.Flags().StringP("title", "t", "",
3221
"Supply a title. Will prompt for one otherwise.")
3322
issueCreateCmd.Flags().StringP("body", "b", "",
@@ -56,6 +45,17 @@ var issueCreateCmd = &cobra.Command{
5645
Short: "Create a new issue",
5746
RunE: issueCreate,
5847
}
48+
var issueStatusCmd = &cobra.Command{
49+
Use: "status",
50+
Short: "Show status of relevant issues",
51+
RunE: issueStatus,
52+
}
53+
var issueViewCmd = &cobra.Command{
54+
Use: "view <issue-number>",
55+
Args: cobra.MinimumNArgs(1),
56+
Short: "View an issue in the browser",
57+
RunE: issueView,
58+
}
5959

6060
func issueList(cmd *cobra.Command, args []string) error {
6161
ctx := contextForCommand(cmd)
@@ -158,11 +158,11 @@ func issueStatus(cmd *cobra.Command, args []string) error {
158158
}
159159
fmt.Println()
160160

161-
printHeader("Recent issues")
162-
if len(issuePayload.Recent) > 0 {
163-
printIssues(" ", issuePayload.Recent...)
161+
printHeader("Issues opened by you")
162+
if len(issuePayload.Authored) > 0 {
163+
printIssues(" ", issuePayload.Authored...)
164164
} else {
165-
printMessage(" There are no recent issues")
165+
printMessage(" There are no issues opened by you")
166166
}
167167
fmt.Println()
168168

command/root.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package command
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/github/gh-cli/api"
89
"github.com/github/gh-cli/context"
@@ -17,7 +18,9 @@ var Version = "DEV"
1718
var BuildDate = "YYYY-MM-DD"
1819

1920
func init() {
20-
RootCmd.Version = fmt.Sprintf("%s (%s)", Version, BuildDate)
21+
RootCmd.Version = fmt.Sprintf("%s (%s)", strings.TrimPrefix(Version, "v"), BuildDate)
22+
RootCmd.AddCommand(versionCmd)
23+
2124
RootCmd.PersistentFlags().StringP("repo", "R", "", "current GitHub repository")
2225
RootCmd.PersistentFlags().StringP("current-branch", "B", "", "current git branch")
2326
// TODO:
@@ -37,11 +40,20 @@ type FlagError struct {
3740
var RootCmd = &cobra.Command{
3841
Use: "gh",
3942
Short: "GitHub CLI",
40-
Long: `Work seamlessly with GitHub from the command line`,
43+
Long: `Work seamlessly with GitHub from the command line`,
44+
4145
SilenceErrors: true,
4246
SilenceUsage: true,
4347
}
4448

49+
var versionCmd = &cobra.Command{
50+
Use: "version",
51+
Hidden: true,
52+
Run: func(cmd *cobra.Command, args []string) {
53+
fmt.Printf("gh version %s\n", RootCmd.Version)
54+
},
55+
}
56+
4557
// overriden in tests
4658
var initContext = func() context.Context {
4759
ctx := context.New()

test/fixtures/issueStatus.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
]
2929
}
3030
},
31-
"recent": {
31+
"authored": {
3232
"issues": {
3333
"nodes": []
3434
}

utils/table_printer.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"os/exec"
8+
"strconv"
9+
"strings"
710

811
"github.com/mattn/go-colorable"
12+
"github.com/mattn/go-isatty"
913
"golang.org/x/crypto/ssh/terminal"
1014
)
1115

@@ -18,11 +22,19 @@ type TablePrinter interface {
1822

1923
func NewTablePrinter(w io.Writer) TablePrinter {
2024
if outFile, isFile := w.(*os.File); isFile {
21-
fd := int(outFile.Fd())
22-
if terminal.IsTerminal(fd) {
25+
isCygwin := isatty.IsCygwinTerminal(outFile.Fd())
26+
if isatty.IsTerminal(outFile.Fd()) || isCygwin {
2327
ttyWidth := 80
24-
if w, _, err := terminal.GetSize(fd); err == nil {
28+
if w, _, err := terminal.GetSize(int(outFile.Fd())); err == nil {
2529
ttyWidth = w
30+
} else if isCygwin {
31+
tputCmd := exec.Command("tput", "cols")
32+
tputCmd.Stdin = os.Stdin
33+
if out, err := tputCmd.Output(); err == nil {
34+
if w, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil {
35+
ttyWidth = w
36+
}
37+
}
2638
}
2739
return &ttyTablePrinter{
2840
out: colorable.NewColorable(outFile),

0 commit comments

Comments
 (0)
X Tutup