Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions responses/differential_getrawdiff.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
package responses

import "github.com/thought-machine/gonduit/entities"
import (
"encoding/json"

"github.com/thought-machine/gonduit/entities"
)

// DifferentialGetRawDiffResponse is the response from calling differential.getrawdiff.
type DifferentialGetRawDiffResponse *entities.DifferentialRawDiff
type DifferentialGetRawDiffResponse struct {
*entities.DifferentialRawDiff
}

// UnmarshalJSON handles the fact that Phabricator returns the diff as a JSON-encoded string.
func (r *DifferentialGetRawDiffResponse) UnmarshalJSON(b []byte) error {
var rawString string
if err := json.Unmarshal(b, &rawString); err == nil {
r.DifferentialRawDiff = &entities.DifferentialRawDiff{
Diff: rawString,
}
return nil
}

// If it is a real JSON object, unmarshal it into the underlying struct normally.
r.DifferentialRawDiff = &entities.DifferentialRawDiff{}
return json.Unmarshal(b, r.DifferentialRawDiff)
}
Loading