diff --git a/client.go b/client.go index 9fac2db..e3a41aa 100644 --- a/client.go +++ b/client.go @@ -4,12 +4,13 @@ import ( "bytes" "context" json "github.com/goccy/go-json" - "io" "mime/multipart" "net/http" "net/url" "strconv" + goio "io" + core "dappco.re/go/core" ) @@ -196,7 +197,7 @@ func (c *Client) PostRaw(ctx context.Context, path string, body any) ([]byte, er func (c *Client) postRawJSON(ctx context.Context, path string, body any) ([]byte, error) { url := c.baseURL + path - var bodyReader io.Reader + var bodyReader goio.Reader if body != nil { data, err := json.Marshal(body) if err != nil { @@ -226,7 +227,7 @@ func (c *Client) postRawJSON(ctx context.Context, path string, body any) ([]byte return nil, c.parseError(resp, path) } - data, err := io.ReadAll(resp.Body) + data, err := goio.ReadAll(resp.Body) if err != nil { return nil, core.E("Client.PostRaw", "forge: read response body", err) } @@ -259,7 +260,7 @@ func (c *Client) postRawText(ctx context.Context, path, body string) ([]byte, er return nil, c.parseError(resp, path) } - data, err := io.ReadAll(resp.Body) + data, err := goio.ReadAll(resp.Body) if err != nil { return nil, core.E("Client.PostText", "forge: read response body", err) } @@ -267,7 +268,7 @@ func (c *Client) postRawText(ctx context.Context, path, body string) ([]byte, er return data, nil } -func (c *Client) postMultipartJSON(ctx context.Context, path string, query map[string]string, fields map[string]string, fieldName, fileName string, content io.Reader, out any) error { +func (c *Client) postMultipartJSON(ctx context.Context, path string, query map[string]string, fields map[string]string, fieldName, fileName string, content goio.Reader, out any) error { target, err := url.Parse(c.baseURL + path) if err != nil { return core.E("Client.PostMultipart", "forge: parse url", err) @@ -293,7 +294,7 @@ func (c *Client) postMultipartJSON(ctx context.Context, path string, query map[s return core.E("Client.PostMultipart", "forge: create multipart form file", err) } if content != nil { - if _, err := io.Copy(part, content); err != nil { + if _, err := goio.Copy(part, content); err != nil { return core.E("Client.PostMultipart", "forge: write multipart form file", err) } } @@ -357,7 +358,7 @@ func (c *Client) GetRaw(ctx context.Context, path string) ([]byte, error) { return nil, c.parseError(resp, path) } - data, err := io.ReadAll(resp.Body) + data, err := goio.ReadAll(resp.Body) if err != nil { return nil, core.E("Client.GetRaw", "forge: read response body", err) } @@ -373,7 +374,7 @@ func (c *Client) do(ctx context.Context, method, path string, body, out any) err func (c *Client) doJSON(ctx context.Context, method, path string, body, out any) (*http.Response, error) { url := c.baseURL + path - var bodyReader io.Reader + var bodyReader goio.Reader if body != nil { data, err := json.Marshal(body) if err != nil { @@ -423,7 +424,7 @@ func (c *Client) parseError(resp *http.Response, path string) error { } // Read a bit of the body to see if we can get a message - data, _ := io.ReadAll(io.LimitReader(resp.Body, 1024)) + data, _ := goio.ReadAll(goio.LimitReader(resp.Body, 1024)) _ = json.Unmarshal(data, &errBody) msg := errBody.Message diff --git a/issues.go b/issues.go index 5490dd1..b993ebe 100644 --- a/issues.go +++ b/issues.go @@ -2,11 +2,12 @@ package forge import ( "context" - "io" "iter" "strconv" "time" + goio "io" + "dappco.re/go/core/forge/types" ) @@ -391,7 +392,7 @@ func attachmentUploadQuery(opts *AttachmentUploadOptions) map[string]string { return query } -func (s *IssueService) createAttachment(ctx context.Context, path string, opts *AttachmentUploadOptions, filename string, content io.Reader) (*types.Attachment, error) { +func (s *IssueService) createAttachment(ctx context.Context, path string, opts *AttachmentUploadOptions, filename string, content goio.Reader) (*types.Attachment, error) { var out types.Attachment if err := s.client.postMultipartJSON(ctx, path, attachmentUploadQuery(opts), nil, "attachment", filename, content, &out); err != nil { return nil, err @@ -400,7 +401,7 @@ func (s *IssueService) createAttachment(ctx context.Context, path string, opts * } // CreateAttachment uploads a new attachment to an issue. -func (s *IssueService) CreateAttachment(ctx context.Context, owner, repo string, index int64, opts *AttachmentUploadOptions, filename string, content io.Reader) (*types.Attachment, error) { +func (s *IssueService) CreateAttachment(ctx context.Context, owner, repo string, index int64, opts *AttachmentUploadOptions, filename string, content goio.Reader) (*types.Attachment, error) { path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/assets", pathParams("owner", owner, "repo", repo, "index", int64String(index))) return s.createAttachment(ctx, path, opts, filename, content) } @@ -466,7 +467,7 @@ func (s *IssueService) GetCommentAttachment(ctx context.Context, owner, repo str } // CreateCommentAttachment uploads a new attachment to an issue comment. -func (s *IssueService) CreateCommentAttachment(ctx context.Context, owner, repo string, id int64, opts *AttachmentUploadOptions, filename string, content io.Reader) (*types.Attachment, error) { +func (s *IssueService) CreateCommentAttachment(ctx context.Context, owner, repo string, id int64, opts *AttachmentUploadOptions, filename string, content goio.Reader) (*types.Attachment, error) { path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/comments/{id}/assets", pathParams("owner", owner, "repo", repo, "id", int64String(id))) return s.createAttachment(ctx, path, opts, filename, content) } diff --git a/releases.go b/releases.go index 66e5ef4..48a8176 100644 --- a/releases.go +++ b/releases.go @@ -2,9 +2,10 @@ package forge import ( "context" - "io" "iter" + goio "io" + "dappco.re/go/core/forge/types" ) @@ -79,7 +80,7 @@ func (s *ReleaseService) ListAssets(ctx context.Context, owner, repo string, rel // // If opts.ExternalURL is set, the upload uses the external_url form field and // ignores filename/content. -func (s *ReleaseService) CreateAttachment(ctx context.Context, owner, repo string, releaseID int64, opts *ReleaseAttachmentUploadOptions, filename string, content io.Reader) (*types.Attachment, error) { +func (s *ReleaseService) CreateAttachment(ctx context.Context, owner, repo string, releaseID int64, opts *ReleaseAttachmentUploadOptions, filename string, content goio.Reader) (*types.Attachment, error) { path := ResolvePath("/api/v1/repos/{owner}/{repo}/releases/{releaseID}/assets", pathParams("owner", owner, "repo", repo, "releaseID", int64String(releaseID))) fields := make(map[string]string, 1) fieldName := "attachment" @@ -107,7 +108,7 @@ func (s *ReleaseService) EditAttachment(ctx context.Context, owner, repo string, } // CreateAsset uploads a new asset to a release. -func (s *ReleaseService) CreateAsset(ctx context.Context, owner, repo string, releaseID int64, opts *ReleaseAttachmentUploadOptions, filename string, content io.Reader) (*types.Attachment, error) { +func (s *ReleaseService) CreateAsset(ctx context.Context, owner, repo string, releaseID int64, opts *ReleaseAttachmentUploadOptions, filename string, content goio.Reader) (*types.Attachment, error) { return s.CreateAttachment(ctx, owner, repo, releaseID, opts, filename, content) }