Skip to content

Commit 993c73c

Browse files
committed
Merge remote-tracking branch 'origin/trunk' into actions
2 parents 631a1ae + eddd8f0 commit 993c73c

24 files changed

+181
-22
lines changed

api/queries_pr.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type PullRequest struct {
3939
HeadRefName string
4040
Body string
4141
Mergeable string
42+
Additions int
43+
Deletions int
4244
MergeStateStatus string
4345

4446
Author struct {
@@ -571,6 +573,8 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu
571573
closed
572574
body
573575
mergeable
576+
additions
577+
deletions
574578
author {
575579
login
576580
}
@@ -672,6 +676,8 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea
672676
state
673677
body
674678
mergeable
679+
additions
680+
deletions
675681
author {
676682
login
677683
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/cli/safeexec v1.0.0
1212
github.com/cpuguy83/go-md2man/v2 v2.0.0
1313
github.com/enescakir/emoji v1.0.0
14+
github.com/gabriel-vasile/mimetype v1.1.2
1415
github.com/google/go-cmp v0.5.2
1516
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1617
github.com/hashicorp/go-version v1.2.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkK
7474
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
7575
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
7676
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
77+
github.com/gabriel-vasile/mimetype v1.1.2 h1:gaPnPcNor5aZSVCJVSGipcpbgMWiAAj9z182ocSGbHU=
78+
github.com/gabriel-vasile/mimetype v1.1.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
7779
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
7880
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
7981
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=

pkg/cmd/alias/set/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command
5656
$ gh alias set bugs 'issue list --label="bugs"'
5757
$ gh bugs
5858
59-
$ gh alias set homework 'issue list --assigned @me'
59+
$ gh alias set homework 'issue list --assignee @me'
6060
$ gh homework
6161
6262
$ gh alias set epicsBy 'issue list --author="$1" --label="epic"'

pkg/cmd/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
131131
$ gh api --preview baptiste,nebula ...
132132
133133
# print only specific fields from the response
134-
$ gh api repos/:owner/:repo/issues --filter '.[].title'
134+
$ gh api repos/:owner/:repo/issues --jq '.[].title'
135135
136136
# use a template for the output
137137
$ gh api repos/:owner/:repo/issues --template \

pkg/cmd/gist/create/create.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ type CreateOptions struct {
3030
Public bool
3131
Filenames []string
3232
FilenameOverride string
33-
34-
WebMode bool
33+
WebMode bool
3534

3635
HttpClient func() (*http.Client, error)
3736
}
@@ -164,6 +163,7 @@ func processFiles(stdin io.ReadCloser, filenameOverride string, filenames []stri
164163
var filename string
165164
var content []byte
166165
var err error
166+
167167
if f == "-" {
168168
if filenameOverride != "" {
169169
filename = filenameOverride
@@ -175,11 +175,24 @@ func processFiles(stdin io.ReadCloser, filenameOverride string, filenames []stri
175175
return fs, fmt.Errorf("failed to read from stdin: %w", err)
176176
}
177177
stdin.Close()
178+
179+
if shared.IsBinaryContents(content) {
180+
return nil, fmt.Errorf("binary file contents not supported")
181+
}
178182
} else {
183+
isBinary, err := shared.IsBinaryFile(f)
184+
if err != nil {
185+
return fs, fmt.Errorf("failed to read file %s: %w", f, err)
186+
}
187+
if isBinary {
188+
return nil, fmt.Errorf("failed to upload %s: binary file not supported", f)
189+
}
190+
179191
content, err = ioutil.ReadFile(f)
180192
if err != nil {
181193
return fs, fmt.Errorf("failed to read file %s: %w", f, err)
182194
}
195+
183196
filename = path.Base(f)
184197
}
185198

pkg/cmd/gist/edit/edit.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,25 @@ func editRun(opts *EditOptions) error {
144144
}
145145
}
146146

147-
if _, ok := gist.Files[filename]; !ok {
147+
gistFile, found := gist.Files[filename]
148+
if !found {
148149
return fmt.Errorf("gist has no file %q", filename)
149150
}
151+
if shared.IsBinaryContents([]byte(gistFile.Content)) {
152+
return fmt.Errorf("editing binary files not supported")
153+
}
150154

151155
editorCommand, err := cmdutil.DetermineEditor(opts.Config)
152156
if err != nil {
153157
return err
154158
}
155-
text, err := opts.Edit(editorCommand, filename, gist.Files[filename].Content, opts.IO)
159+
text, err := opts.Edit(editorCommand, filename, gistFile.Content, opts.IO)
156160

157161
if err != nil {
158162
return err
159163
}
160164

161-
if text != gist.Files[filename].Content {
162-
gistFile := gist.Files[filename]
165+
if text != gistFile.Content {
163166
gistFile.Content = text // so it appears if they re-edit
164167
filesToUpdate[filename] = text
165168
}
@@ -242,6 +245,14 @@ func updateGist(apiClient *api.Client, hostname string, gist *shared.Gist) error
242245
}
243246

244247
func getFilesToAdd(file string) (map[string]*shared.GistFile, error) {
248+
isBinary, err := shared.IsBinaryFile(file)
249+
if err != nil {
250+
return nil, fmt.Errorf("failed to read file %s: %w", file, err)
251+
}
252+
if isBinary {
253+
return nil, fmt.Errorf("failed to upload %s: binary file not supported", file)
254+
}
255+
245256
content, err := ioutil.ReadFile(file)
246257
if err != nil {
247258
return nil, fmt.Errorf("failed to read file %s: %w", file, err)

pkg/cmd/gist/edit/edit_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ func Test_editRun(t *testing.T) {
301301
io.SetStdoutTTY(!tt.nontty)
302302
io.SetStdinTTY(!tt.nontty)
303303
tt.opts.IO = io
304-
305304
tt.opts.Selector = "1234"
306305

307306
tt.opts.Config = func() (config.Config, error) {

pkg/cmd/gist/shared/shared.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/cli/cli/api"
1213
"github.com/cli/cli/internal/ghinstance"
14+
"github.com/gabriel-vasile/mimetype"
1315
"github.com/shurcooL/githubv4"
1416
"github.com/shurcooL/graphql"
15-
16-
"github.com/cli/cli/api"
1717
)
1818

1919
type GistFile struct {
@@ -147,3 +147,30 @@ pagination:
147147

148148
return gists, nil
149149
}
150+
151+
func IsBinaryFile(file string) (bool, error) {
152+
detectedMime, err := mimetype.DetectFile(file)
153+
if err != nil {
154+
return false, err
155+
}
156+
157+
isBinary := true
158+
for mime := detectedMime; mime != nil; mime = mime.Parent() {
159+
if mime.Is("text/plain") {
160+
isBinary = false
161+
break
162+
}
163+
}
164+
return isBinary, nil
165+
}
166+
167+
func IsBinaryContents(contents []byte) bool {
168+
isBinary := true
169+
for mime := mimetype.Detect(contents); mime != nil; mime = mime.Parent() {
170+
if mime.Is("text/plain") {
171+
isBinary = false
172+
break
173+
}
174+
}
175+
return isBinary
176+
}

pkg/cmd/gist/shared/shared_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,38 @@ func Test_GetGistIDFromURL(t *testing.T) {
5050
})
5151
}
5252
}
53+
54+
func TestIsBinaryContents(t *testing.T) {
55+
tests := []struct {
56+
fileContent []byte
57+
want bool
58+
}{
59+
{
60+
want: false,
61+
fileContent: []byte("package main"),
62+
},
63+
{
64+
want: false,
65+
fileContent: []byte(""),
66+
},
67+
{
68+
want: false,
69+
fileContent: []byte(nil),
70+
},
71+
{
72+
want: true,
73+
fileContent: []byte{239, 191, 189, 239, 191, 189, 239, 191, 189, 239,
74+
191, 189, 239, 191, 189, 16, 74, 70, 73, 70, 239, 191, 189, 1, 1, 1,
75+
1, 44, 1, 44, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191,
76+
189, 239, 191, 189, 67, 239, 191, 189, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7,
77+
9, 9, 8, 10, 12, 20, 10, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26,
78+
31, 30, 29, 26, 28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40,
79+
55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51,
80+
52, 50, 239, 191, 189, 239, 191, 189, 239, 191, 189, 67, 1, 9, 9, 9, 12},
81+
},
82+
}
83+
84+
for _, tt := range tests {
85+
assert.Equal(t, tt.want, IsBinaryContents(tt.fileContent))
86+
}
87+
}

0 commit comments

Comments
 (0)