From 8cb87ee40ee42aec831da97b3f84a2545fec1f2e Mon Sep 17 00:00:00 2001 From: Gus Price Date: Mon, 11 Sep 2023 10:21:56 -0700 Subject: [PATCH 1/6] response value for encoding is "none" when the file is over 1 MB --- github/repos_contents.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_contents.go b/github/repos_contents.go index de7a0d5b82..047fca8a31 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -86,7 +86,7 @@ func (r *RepositoryContent) GetContent() (string, error) { } c, err := base64.StdEncoding.DecodeString(*r.Content) return string(c), err - case "": + case "", "none": if r.Content == nil { return "", nil } From 057d269bec25c1f4f8b8043bc7f0e2a3b20486bd Mon Sep 17 00:00:00 2001 From: Gus Price Date: Mon, 11 Sep 2023 10:31:24 -0700 Subject: [PATCH 2/6] add test case --- github/repos_contents_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index ab69b5cdcb..a264ece061 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -30,6 +30,12 @@ func TestRepositoryContent_GetContent(t *testing.T) { want: "hello", wantErr: false, }, + { + encoding: String("none"), + content: String("hello"), + want: "hello", + wantErr: false, + }, { encoding: nil, content: String("hello"), From b27e2d17e3f900a4437c3fddfc4bfa0b03cb0f5f Mon Sep 17 00:00:00 2001 From: Gus Price Date: Mon, 11 Sep 2023 11:51:43 -0700 Subject: [PATCH 3/6] better error messaging --- github/repos_contents.go | 4 +++- github/repos_contents_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/github/repos_contents.go b/github/repos_contents.go index 047fca8a31..41f5facee3 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -86,11 +86,13 @@ func (r *RepositoryContent) GetContent() (string, error) { } c, err := base64.StdEncoding.DecodeString(*r.Content) return string(c), err - case "", "none": + case "": if r.Content == nil { return "", nil } return *r.Content, nil + case "none": + return "", fmt.Errorf("unsupported content encoding: %v, this may occur when the file size > 1 MB, if that is the case consider using DownloadContents", encoding) default: return "", fmt.Errorf("unsupported content encoding: %v", encoding) } diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index a264ece061..f5a9760899 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -30,12 +30,6 @@ func TestRepositoryContent_GetContent(t *testing.T) { want: "hello", wantErr: false, }, - { - encoding: String("none"), - content: String("hello"), - want: "hello", - wantErr: false, - }, { encoding: nil, content: String("hello"), @@ -60,6 +54,12 @@ func TestRepositoryContent_GetContent(t *testing.T) { want: "", wantErr: true, }, + { + encoding: String("none"), + content: String(""), + want: "", + wantErr: true, + }, } for _, tt := range tests { From e140852ac1f0e45b92d499335e71b56d9b3009aa Mon Sep 17 00:00:00 2001 From: Gus Price Date: Mon, 11 Sep 2023 11:51:59 -0700 Subject: [PATCH 4/6] remove the --- github/repos_contents.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_contents.go b/github/repos_contents.go index 41f5facee3..75d76cb089 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -92,7 +92,7 @@ func (r *RepositoryContent) GetContent() (string, error) { } return *r.Content, nil case "none": - return "", fmt.Errorf("unsupported content encoding: %v, this may occur when the file size > 1 MB, if that is the case consider using DownloadContents", encoding) + return "", fmt.Errorf("unsupported content encoding: %v, this may occur when file size > 1 MB, if that is the case consider using DownloadContents", encoding) default: return "", fmt.Errorf("unsupported content encoding: %v", encoding) } From bee9a1ae16db50ce983fa004b89646911b79a871 Mon Sep 17 00:00:00 2001 From: Gus Price Date: Mon, 11 Sep 2023 13:19:43 -0700 Subject: [PATCH 5/6] nil content --- github/repos_contents_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index f5a9760899..f961306920 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -56,7 +56,7 @@ func TestRepositoryContent_GetContent(t *testing.T) { }, { encoding: String("none"), - content: String(""), + content: nil, want: "", wantErr: true, }, From 6e8946c632e25f60e3ec415e03a3e65448164fb1 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Mon, 18 Sep 2023 09:08:45 -0400 Subject: [PATCH 6/6] Update github/repos_contents.go --- github/repos_contents.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_contents.go b/github/repos_contents.go index 75d76cb089..d59c735df8 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -92,7 +92,7 @@ func (r *RepositoryContent) GetContent() (string, error) { } return *r.Content, nil case "none": - return "", fmt.Errorf("unsupported content encoding: %v, this may occur when file size > 1 MB, if that is the case consider using DownloadContents", encoding) + return "", errors.New("unsupported content encoding: none, this may occur when file size > 1 MB, if that is the case consider using DownloadContents") default: return "", fmt.Errorf("unsupported content encoding: %v", encoding) }