MCPcopy Create free account
hub / github.com/git-bug/git-bug / operationUnmarshaler

Function operationUnmarshaler

entity/dag/example_test.go:221–270  ·  view source on GitHub ↗

operationUnmarshaler is a function doing the de-serialization of the JSON data into our own concrete Operations. If needed, we can use the resolver to connect to other entities.

(raw json.RawMessage, resolvers entity.Resolvers)

Source from the content-addressed store, hash-verified

219// operationUnmarshaler is a function doing the de-serialization of the JSON data into our own
220// concrete Operations. If needed, we can use the resolver to connect to other entities.
221func operationUnmarshaler(raw json.RawMessage, resolvers entity.Resolvers) (dag.Operation, error) {
222 var t struct {
223 OperationType dag.OperationType `json:"type"`
224 }
225
226 if err := json.Unmarshal(raw, &t); err != nil {
227 return nil, err
228 }
229
230 var op dag.Operation
231
232 switch t.OperationType {
233 case AddAdministratorOp:
234 op = &AddAdministrator{}
235 case RemoveAdministratorOp:
236 op = &RemoveAdministrator{}
237 case SetSignatureRequiredOp:
238 op = &SetSignatureRequired{}
239 default:
240 panic(fmt.Sprintf("unknown operation type %v", t.OperationType))
241 }
242
243 err := json.Unmarshal(raw, &op)
244 if err != nil {
245 return nil, err
246 }
247
248 switch op := op.(type) {
249 case *AddAdministrator:
250 // We need to resolve identities
251 for i, stub := range op.ToAdd {
252 iden, err := entity.Resolve[identity.Interface](resolvers, stub.Id())
253 if err != nil {
254 return nil, err
255 }
256 op.ToAdd[i] = iden
257 }
258 case *RemoveAdministrator:
259 // We need to resolve identities
260 for i, stub := range op.ToRemove {
261 iden, err := entity.Resolve[identity.Interface](resolvers, stub.Id())
262 if err != nil {
263 return nil, err
264 }
265 op.ToRemove[i] = iden
266 }
267 }
268
269 return op, nil
270}
271
272// Compile compute a view of the final state. This is what we would use to display the state
273// in a user interface.

Callers

nothing calls this directly

Calls 2

ResolveFunction · 0.92
IdMethod · 0.65

Tested by

no test coverage detected