fix(files): route UpsertFile to POST when sha is empty so new files can be created
This commit is contained in:
@@ -92,13 +92,24 @@ type FileWriteResult struct {
|
|||||||
} `json:"commit"`
|
} `json:"commit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpsertFile creates a file when args.Sha is empty (POST) or updates an existing
|
||||||
|
// file when args.Sha is set (PUT). Gitea routes both operations by HTTP method on
|
||||||
|
// the same /contents/{path} URL, and rejects PUT without a sha.
|
||||||
func (c *Client) UpsertFile(ctx context.Context, owner, repo, path string, args UpsertFileArgs) (*FileWriteResult, error) {
|
func (c *Client) UpsertFile(ctx context.Context, owner, repo, path string, args UpsertFileArgs) (*FileWriteResult, error) {
|
||||||
p := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", owner, repo, path)
|
p := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", owner, repo, path)
|
||||||
payload, err := json.Marshal(args)
|
payload, err := json.Marshal(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
body, status, err := c.PutJSON(ctx, p, payload)
|
var (
|
||||||
|
body []byte
|
||||||
|
status int
|
||||||
|
)
|
||||||
|
if args.Sha == "" {
|
||||||
|
body, status, err = c.PostJSON(ctx, p, payload)
|
||||||
|
} else {
|
||||||
|
body, status, err = c.PutJSON(ctx, p, payload)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user