X Tutup
Skip to content

Commit e2fd7ce

Browse files
author
Nate Smith
authored
Merge pull request cli#5369 from cli/gh-status
2 parents 56fda0f + 5b060a2 commit e2fd7ce

File tree

11 files changed

+1518
-20
lines changed

11 files changed

+1518
-20
lines changed

api/client.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,41 +316,55 @@ func graphQLClient(h *http.Client, hostname string) *graphql.Client {
316316

317317
// REST performs a REST request and parses the response.
318318
func (c Client) REST(hostname string, method string, p string, body io.Reader, data interface{}) error {
319+
_, err := c.RESTWithNext(hostname, method, p, body, data)
320+
return err
321+
}
322+
323+
func (c Client) RESTWithNext(hostname string, method string, p string, body io.Reader, data interface{}) (string, error) {
319324
req, err := http.NewRequest(method, restURL(hostname, p), body)
320325
if err != nil {
321-
return err
326+
return "", err
322327
}
323328

324329
req.Header.Set("Content-Type", "application/json; charset=utf-8")
325330

326331
resp, err := c.http.Do(req)
327332
if err != nil {
328-
return err
333+
return "", err
329334
}
330335
defer resp.Body.Close()
331336

332337
success := resp.StatusCode >= 200 && resp.StatusCode < 300
333338
if !success {
334-
return HandleHTTPError(resp)
339+
return "", HandleHTTPError(resp)
335340
}
336341

337342
if resp.StatusCode == http.StatusNoContent {
338-
return nil
343+
return "", nil
339344
}
340345

341346
b, err := ioutil.ReadAll(resp.Body)
342347
if err != nil {
343-
return err
348+
return "", err
344349
}
345350

346351
err = json.Unmarshal(b, &data)
347352
if err != nil {
348-
return err
353+
return "", err
349354
}
350355

351-
return nil
356+
var next string
357+
for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) {
358+
if len(m) > 2 && m[2] == "next" {
359+
next = m[1]
360+
}
361+
}
362+
363+
return next, nil
352364
}
353365

366+
var linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`)
367+
354368
func restURL(hostname string, pathOrURL string) string {
355369
if strings.HasPrefix(pathOrURL, "https://") || strings.HasPrefix(pathOrURL, "http://") {
356370
return pathOrURL

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/MakeNowJust/heredoc v1.0.0
88
github.com/briandowns/spinner v1.18.1
99
github.com/charmbracelet/glamour v0.4.0
10+
github.com/charmbracelet/lipgloss v0.5.0
1011
github.com/cli/browser v1.1.0
1112
github.com/cli/oauth v0.9.0
1213
github.com/cli/safeexec v1.0.0
@@ -27,7 +28,7 @@ require (
2728
github.com/mattn/go-isatty v0.0.14
2829
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
2930
github.com/muesli/reflow v0.3.0
30-
github.com/muesli/termenv v0.9.0
31+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0
3132
github.com/muhammadmuzzammil1998/jsonc v0.0.0-20201229145248-615b0916ca38
3233
github.com/opentracing/opentracing-go v1.1.0
3334
github.com/shurcooL/githubv4 v0.0.0-20200928013246-d292edc3691b

go.sum

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/pp
4848
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4949
github.com/charmbracelet/glamour v0.4.0 h1:scR+smyB7WdmrlIaff6IVlm48P48JaNM7JypM/VGl4k=
5050
github.com/charmbracelet/glamour v0.4.0/go.mod h1:9ZRtG19AUIzcTm7FGLGbq3D5WKQ5UyZBbQsMQN0XIqc=
51+
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
52+
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
5153
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
5254
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5355
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -182,6 +184,7 @@ github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
182184
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
183185
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
184186
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
187+
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
185188
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
186189
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
187190
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -190,10 +193,12 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
190193
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
191194
github.com/microcosm-cc/bluemonday v1.0.17 h1:Z1a//hgsQ4yjC+8zEkV8IWySkXnsxmdSY642CTFQb5Y=
192195
github.com/microcosm-cc/bluemonday v1.0.17/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
196+
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
193197
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
194198
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
195-
github.com/muesli/termenv v0.9.0 h1:wnbOaGz+LUR3jNT0zOzinPnyDaCZUQRZj9GxK8eRVl8=
196199
github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
200+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
201+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
197202
github.com/muhammadmuzzammil1998/jsonc v0.0.0-20201229145248-615b0916ca38 h1:0FrBxrkJ0hVembTb/e4EU5Ml6vLcOusAqymmYISg5Uo=
198203
github.com/muhammadmuzzammil1998/jsonc v0.0.0-20201229145248-615b0916ca38/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
199204
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=

pkg/cmd/root/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
searchCmd "github.com/cli/cli/v2/pkg/cmd/search"
2929
secretCmd "github.com/cli/cli/v2/pkg/cmd/secret"
3030
sshKeyCmd "github.com/cli/cli/v2/pkg/cmd/ssh-key"
31+
statusCmd "github.com/cli/cli/v2/pkg/cmd/status"
3132
versionCmd "github.com/cli/cli/v2/pkg/cmd/version"
3233
workflowCmd "github.com/cli/cli/v2/pkg/cmd/workflow"
3334
"github.com/cli/cli/v2/pkg/cmdutil"
@@ -83,6 +84,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
8384
cmd.AddCommand(searchCmd.NewCmdSearch(f))
8485
cmd.AddCommand(secretCmd.NewCmdSecret(f))
8586
cmd.AddCommand(sshKeyCmd.NewCmdSSHKey(f))
87+
cmd.AddCommand(statusCmd.NewCmdStatus(f, nil))
8688
cmd.AddCommand(newCodespaceCmd(f))
8789

8890
// the `api` command should not inherit any extra HTTP headers
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
[
2+
{
3+
"type": "PullRequestEvent",
4+
"repo": {
5+
"name": "rpd/todo"
6+
},
7+
"payload": {
8+
"action": "opened",
9+
"number": 5326,
10+
"pull_request": {
11+
"number": 5326,
12+
"title": "Only write UTF-8 BOM on Windows where it is needed"
13+
}
14+
},
15+
"created_at": "2022-03-17T15:42:28Z",
16+
"org": {
17+
"login": "rpd"
18+
}
19+
},
20+
{
21+
"type": "IssueCommentEvent",
22+
"repo": {
23+
"name": "vilmibm/testing"
24+
},
25+
"payload": {
26+
"action": "created",
27+
"issue": {
28+
"number": 5325,
29+
"title": "Ability to search \"not\" thing"
30+
},
31+
"comment": {
32+
"html_url": "https://github.com/vilmibm/testing/issues/5325#issuecomment-1070868636",
33+
"body": "We are working on dedicated `search` functionality and might be exploring some syntax for denoting \"NOT\" qualifiers. However, until something like this is added, you can always make \"NOT\" searches by using the `--search` flag:\r\n```\r\ngh pr list --search \"-author:app/dependabot\"\r\n```\r\n/cc @samcoe "
34+
}
35+
},
36+
"created_at": "2022-03-17T12:36:31Z"
37+
},
38+
{
39+
"type": "DeleteEvent",
40+
"repo": {
41+
"name": "cli/cli"
42+
},
43+
"payload": {
44+
"ref": "dependabot/go_modules/github.com/stretchr/testify-1.7.1",
45+
"ref_type": "branch",
46+
"pusher_type": "user"
47+
},
48+
"created_at": "2022-03-16T14:41:30Z",
49+
"org": {
50+
"login": "cli",
51+
"avatar_url": "https://avatars.githubusercontent.com/u/59704711?"
52+
}
53+
},
54+
{
55+
"type": "CreateEvent",
56+
"repo": {
57+
"name": "cli/cli"
58+
},
59+
"payload": {
60+
"ref": "dependabot/go_modules/github.com/stretchr/testify-1.7.1",
61+
"ref_type": "branch",
62+
"master_branch": "trunk",
63+
"description": "GitHub’s official command line tool",
64+
"pusher_type": "user"
65+
},
66+
"created_at": "2022-03-16T14:25:19Z",
67+
"org": {
68+
"login": "cli",
69+
"avatar_url": "https://avatars.githubusercontent.com/u/59704711?"
70+
}
71+
},
72+
{
73+
"type": "PullRequestReviewCommentEvent",
74+
"repo": {
75+
"name": "cli/cli"
76+
},
77+
"payload": {
78+
"action": "created",
79+
"comment": {
80+
"body": "Wondering if we shouldn't name this something more generic and use it everywhere else to DRY things up a bit?",
81+
"html_url": "https://github.com/cli/cli/pull/5319#discussion_r827935007"
82+
},
83+
"pull_request": {
84+
"number": 5319,
85+
"title": "[Codespaces] Disallow some operations on codespaces that have a pending operation"
86+
}
87+
},
88+
"created_at": "2022-03-16T12:08:02Z",
89+
"org": {
90+
"login": "cli"
91+
}
92+
},
93+
{
94+
"type": "CommitCommentEvent",
95+
"repo": {
96+
"name": "cli/cli"
97+
},
98+
"payload": {
99+
"comment": {
100+
"html_url": "https://github.com/cli/cli/commit/1b50852b2dfecd17ca5d3a2a12eb5c16df9fe46b#r68794505",
101+
"body": "spam"
102+
}
103+
},
104+
"created_at": "2022-03-16T03:32:59Z",
105+
"org": {
106+
"login": "cli"
107+
}
108+
},
109+
{
110+
"type": "PushEvent",
111+
"repo": {
112+
"name": "cli/cli"
113+
},
114+
"payload": {
115+
"push_id": 9359833428,
116+
"size": 1,
117+
"distinct_size": 1,
118+
"ref": "refs/heads/jg/event-handling",
119+
"head": "7d07249150fe1a24b2b49b3ff7c55e2152446a5e",
120+
"before": "06f1f6eb527a34af1222ca03807a9205a17d6e90",
121+
"commits": [
122+
{
123+
"sha": "7d07249150fe1a24b2b49b3ff7c55e2152446a5e",
124+
"author": {
125+
"email": "68619889+bchuecos@users.noreply.github.com",
126+
"name": "Bernardo"
127+
},
128+
"message": "review suggestions",
129+
"distinct": true,
130+
"url": "https://api.github.com/repos/cli/cli/commits/7d07249150fe1a24b2b49b3ff7c55e2152446a5e"
131+
}
132+
]
133+
},
134+
"created_at": "2022-03-15T18:22:41Z",
135+
"org": {
136+
"login": "cli"
137+
}
138+
},
139+
{
140+
"type": "WatchEvent",
141+
"repo": {
142+
"name": "fengari-lua/fengari",
143+
"url": "https://api.github.com/repos/fengari-lua/fengari"
144+
},
145+
"payload": {
146+
"action": "started"
147+
},
148+
"created_at": "2022-03-14T13:03:51Z",
149+
"org": {
150+
"login": "fengari-lua",
151+
"avatar_url": "https://avatars.githubusercontent.com/u/28658472?"
152+
}
153+
},
154+
{
155+
"type": "IssuesEvent",
156+
"repo": {
157+
"name": "cli/cli"
158+
},
159+
"payload": {
160+
"action": "closed",
161+
"issue": {
162+
"number": 5301,
163+
"title": "wheee"
164+
}
165+
},
166+
"created_at": "2022-03-14T12:21:59Z",
167+
"org": {
168+
"login": "cli"
169+
}
170+
},
171+
{
172+
"type": "IssuesEvent",
173+
"repo": {
174+
"name": "cli/cli"
175+
},
176+
"payload": {
177+
"action": "opened",
178+
"issue": {
179+
"number": 5300,
180+
"title": "Terminal bell when a running task is done"
181+
}
182+
},
183+
"created_at": "2022-03-14T12:21:59Z",
184+
"org": {
185+
"login": "cli"
186+
}
187+
}
188+
]

0 commit comments

Comments
 (0)
X Tutup