add func to DownloadReleaseAttachment #609

Closed
edieruby wants to merge 7 commits from edieruby/go-sdk:download.attachment into main
Contributor
No description provided.
edieruby added 1 commit 2022-10-11 06:09:27 +00:00
add func to DownloadReleaseAttachment
Some checks failed
continuous-integration/drone/pr Build is failing
a94443711e
edieruby added 1 commit 2022-10-11 06:37:01 +00:00
add comment
All checks were successful
continuous-integration/drone/pr Build is passing
424487f641
lunny reviewed 2022-10-13 10:58:41 +00:00
@ -111,1 +111,4 @@
}
// DownloadReleaseAttachment Download an Attachment of the Release by UUID
func (c *Client) DownloadReleaseAttachment(UUID string) ([]byte, *Response, error) {
Owner

A io.Reader return parameter maybe better?

A `io.Reader` return parameter maybe better?
Author
Contributor

I will update it.

I will update it.
6543 marked this conversation as resolved
edieruby added 1 commit 2022-10-14 01:39:29 +00:00
change to io.ReadCloser
All checks were successful
continuous-integration/drone/pr Build is passing
592eb3d33f
Owner

@edieruby please allow "maintainers edit" on pulls :)

@edieruby please allow "maintainers edit" on pulls :)
Author
Contributor

@edieruby please allow "maintainers edit" on pulls :)

allowed

> @edieruby please allow "maintainers edit" on pulls :) allowed
6543 added 1 commit 2022-10-19 15:15:16 +00:00
Merge branch 'main' into download.attachment
Some checks failed
continuous-integration/drone/pr Build is failing
eb0e6c07f9
6543 reviewed 2022-10-19 15:18:28 +00:00
gitea/client.go Outdated
@ -396,6 +450,21 @@ func (c *Client) getStatusCode(method, path string, header http.Header, body io.
return resp.StatusCode, resp, nil
}
func (c *Client) getRawResponse(method, path string, header http.Header, body io.Reader) (io.ReadCloser, *Response, error) {
Owner

ther exist a getResponseReader already

ther exist a `getResponseReader` already
6543 marked this conversation as resolved
6543 reviewed 2022-10-19 15:19:13 +00:00
@ -303,6 +303,60 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
return &Response{resp}, nil
}
func (c *Client) doRawRequest(method, path string, header http.Header, body io.Reader) (*Response, error) {
Owner

why we need this?

why we need this?
Owner

ah you do use the web url ... as there is no api equivalent

in this case we have to refactor getWebResponse()

ah you do use the web url ... as there is no api equivalent in this case we have to refactor getWebResponse()
Author
Contributor

Used this func at the beginning.
Seems not work.
lack header setting.
different from this func.
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*Response, error)

Used this func at the beginning. Seems not work. lack header setting. different from this func. func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*Response, error)
6543 marked this conversation as resolved
Owner
https://gitea.com/edieruby/go-sdk/pulls/1
Owner

also it would be nice to have a test in place :)

also it would be nice to have a test in place :)
edieruby closed this pull request 2022-10-20 01:56:11 +00:00
edieruby reopened this pull request 2022-10-20 01:56:16 +00:00
Author
Contributor

also it would be nice to have a test in place :)

Hello, I used the current func at the beginning.
It does not work.
I tested it with my local gitea.
I get the response is 404 Not Found.

It seems that this API works with auth.
gitea/client.go:224 func (c *Client) doWebRequest(method, path string, body io.Reader) (*Response, error)
This func is lack of req.Header.Set("Authorization", "token "+c.accessToken)
or req.SetBasicAuth(c.username, c.password)

> also it would be nice to have a test in place :) Hello, I used the current func at the beginning. It does not work. I tested it with my local gitea. I get the response is 404 Not Found. It seems that this API works with auth. gitea/client.go:224 func (c *Client) doWebRequest(method, path string, body io.Reader) (*Response, error) This func is lack of req.Header.Set("Authorization", "token "+c.accessToken) or req.SetBasicAuth(c.username, c.password)
Owner

well atm it only works on public repos ...
as there is no api for it it looks like

well atm it only works on public repos ... as there is no api for it it looks like
Owner

test this func against public attachments!

for private once we have to either add some roules to the web routes or else add a api dedicated download api

test this func against public attachments! for private once we have to either add some roules to the web routes or else add a api dedicated download api
edieruby added 2 commits 2022-11-03 01:43:52 +00:00
Author
Contributor

Download the attachment in public repo is okay.

My original purpose is download the attachment in private repo.

The gitea was deployed in my local environment, and most repos are private.

Download the attachment in public repo is okay. My original purpose is download the attachment in private repo. The gitea was deployed in my local environment, and most repos are private.
6543 reviewed 2022-11-12 00:22:49 +00:00
@ -112,0 +112,4 @@
// DownloadReleaseAttachment Download an Attachment of the Release by UUID
func (c *Client) DownloadReleaseAttachment(UUID string) (io.ReadCloser, *Response, error) {
if err := escapeValidatePathSegments(&UUID); err != nil {
Owner

asap there is an official api ... we could add this here instead and use the old method only as fallback

asap there is an official api ... we could add this here instead and use the old method only as fallback
6543 marked this conversation as resolved
6543 reviewed 2022-11-12 00:24:49 +00:00
gitea/client.go Outdated
@ -232,21 +232,42 @@ func (c *Client) getWebResponse(method, path string, body io.Reader) ([]byte, *R
client := c.client // client ref can change from this point on so safe it
Owner

L230 error need to be checked

L230 error need to be checked
Author
Contributor

add the check

add the check
edieruby added 1 commit 2022-11-14 02:02:56 +00:00
add the error check
All checks were successful
continuous-integration/drone/pr Build is passing
19e129e36b
lunny reviewed 2022-11-22 02:51:03 +00:00
@ -248,0 +255,4 @@
// check for errors
data, err := statusCodeToErr(resp)
if err != nil {
return io.NopCloser(bytes.NewReader(data)), resp, err
Owner

if err != nil, will data be still kept correct content?

if err != nil, will `data` be still kept correct content?
Author
Contributor

Data will contain the error message.
It's just same with the process in getResponseReader Line:380

Data will contain the error message. It's just same with the process in getResponseReader Line:380
edieruby closed this pull request 2023-12-28 07:35:08 +00:00
Some checks are pending
continuous-integration/drone/pr Build is passing
testing / testing*
Required

Pull request closed

Sign in to join this conversation.
No description provided.