fix(gitea): WriteFile creates via POST, updates via PUT (real contents API)
A live token-scope probe against mathias/ai-sessions revealed gitea's contents API uses POST to create and PUT (sha required) to update — the first impl always PUT'd, so creating a new summary 422'd "[SHA]: Required". The httptest mock had the same wrong assumption. Pick the method by whether the file exists (GET sha). Token confirmed contents:write (push:true) by the probe. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,15 +109,19 @@ func (c *Client) WriteFile(ctx context.Context, repo, path, content string) erro
|
||||
"message": "capture: " + path,
|
||||
"content": base64.StdEncoding.EncodeToString([]byte(content)),
|
||||
}
|
||||
// Gitea contents API: POST creates a new file, PUT updates an existing
|
||||
// one (PUT requires the current sha). Pick by whether the file exists.
|
||||
method := http.MethodPost
|
||||
if sha != "" {
|
||||
payload["sha"] = sha // update in place
|
||||
method = http.MethodPut
|
||||
payload["sha"] = sha
|
||||
}
|
||||
status, body, err := c.request(ctx, http.MethodPut, cpath, payload)
|
||||
status, body, err := c.request(ctx, method, cpath, payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status < 200 || status >= 300 {
|
||||
return fmt.Errorf("gitea PUT %s: status %d: %s", cpath, status, strings.TrimSpace(string(body)))
|
||||
return fmt.Errorf("gitea %s %s: status %d: %s", method, cpath, status, strings.TrimSpace(string(body)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user