feat(redmine): partial UpdateVersion and GetVersion with fake endpoints
UpdateVersion issues PUT /versions/N.json sending only the fields the
caller set (untouched attributes never travel), and never parses the
empty 204 body Redmine answers with. GetVersion backs re-fetching one
milestone. The fake serves both endpoints with Redmine's semantics
(partial apply, 204 empty, 404 for unknown ids), and table tests pin
the exact request bodies, partiality, and error mapping.
💘 Generated with Crush
Assisted-by: Crush:glm-5.2
This commit is contained in:
+38
-2
@@ -16,11 +16,12 @@ type Version struct {
|
||||
Sharing string `json:"sharing,omitempty"`
|
||||
}
|
||||
|
||||
// VersionParams is the write shape for CreateVersion.
|
||||
// VersionParams is the write shape for CreateVersion/UpdateVersion. On
|
||||
// update, zero fields are omitted so only what you set travels.
|
||||
type VersionParams struct {
|
||||
Name string
|
||||
DueDate string
|
||||
Status string // "" defaults to open on the server
|
||||
Status string // "" defaults to open on create; omitted on update
|
||||
Sharing string // "" omits; "descendants" mirrors the PMO roadmap scripts
|
||||
}
|
||||
|
||||
@@ -55,6 +56,41 @@ func (c *Client) CreateVersion(ctx context.Context, project string, p VersionPar
|
||||
return &body.Version, nil
|
||||
}
|
||||
|
||||
// UpdateVersion partially updates a version (PUT /versions/N.json).
|
||||
// The server answers 204 with an EMPTY body — it is never parsed. Only
|
||||
// the fields set in p are sent; untouched attributes are not clobbered.
|
||||
func (c *Client) UpdateVersion(ctx context.Context, id int, p VersionParams) error {
|
||||
fields := map[string]any{}
|
||||
if p.Name != "" {
|
||||
fields["name"] = p.Name
|
||||
}
|
||||
if p.DueDate != "" {
|
||||
fields["due_date"] = p.DueDate
|
||||
}
|
||||
if p.Status != "" {
|
||||
fields["status"] = p.Status
|
||||
}
|
||||
if p.Sharing != "" {
|
||||
fields["sharing"] = p.Sharing
|
||||
}
|
||||
if len(fields) == 0 {
|
||||
return fmt.Errorf("%w: nothing to update", ErrValidation)
|
||||
}
|
||||
payload := map[string]any{"version": fields}
|
||||
return c.do(ctx, "PUT", "/versions/"+strconv.Itoa(id)+".json", nil, payload, nil)
|
||||
}
|
||||
|
||||
// GetVersion fetches one version by id.
|
||||
func (c *Client) GetVersion(ctx context.Context, id int) (*Version, error) {
|
||||
var body struct {
|
||||
Version Version `json:"version"`
|
||||
}
|
||||
if err := c.do(ctx, "GET", "/versions/"+strconv.Itoa(id)+".json", nil, nil, &body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &body.Version, nil
|
||||
}
|
||||
|
||||
// Category is an issue category within a project.
|
||||
type Category struct {
|
||||
ID int `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user