(ctx context.Context, cache dagql.PersistedObjectCache)
| 251 | } |
| 252 | |
| 253 | func (repo *GitRepository) EncodePersistedObject(ctx context.Context, cache dagql.PersistedObjectCache) (dagql.PersistedObjectEncoding, error) { |
| 254 | if repo == nil { |
| 255 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git repository: nil repository") |
| 256 | } |
| 257 | remoteJSON, err := json.Marshal(repo.Remote) |
| 258 | if err != nil { |
| 259 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("marshal persisted git repository remote: %w", err) |
| 260 | } |
| 261 | payload := persistedGitRepositoryPayload{ |
| 262 | DiscardGitDir: repo.DiscardGitDir, |
| 263 | RemoteJSON: remoteJSON, |
| 264 | } |
| 265 | switch backend := repo.Backend.(type) { |
| 266 | case *LocalGitRepository: |
| 267 | dirID, err := encodePersistedObjectRef(cache, backend.Directory, "git repository directory") |
| 268 | if err != nil { |
| 269 | return dagql.PersistedObjectEncoding{}, err |
| 270 | } |
| 271 | payload.Form = persistedGitRepositoryFormLocal |
| 272 | payload.Local = &persistedLocalGitRepositoryPayload{ |
| 273 | DirectoryResultID: dirID, |
| 274 | } |
| 275 | case *RemoteGitRepository: |
| 276 | if backend.URL == nil { |
| 277 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git repository: remote backend missing URL") |
| 278 | } |
| 279 | payload.Form = persistedGitRepositoryFormRemote |
| 280 | payload.Remote = &persistedRemoteGitRepositoryPayload{ |
| 281 | URL: backend.URL.String(), |
| 282 | SSHKnownHosts: backend.SSHKnownHosts, |
| 283 | AuthUsername: backend.AuthUsername, |
| 284 | Platform: backend.Platform, |
| 285 | } |
| 286 | default: |
| 287 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git repository: unsupported backend %T", repo.Backend) |
| 288 | } |
| 289 | payloadJSON, err := json.Marshal(payload) |
| 290 | if err != nil { |
| 291 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("marshal persisted git repository payload: %w", err) |
| 292 | } |
| 293 | return encodePersistedObjectRawJSON(payloadJSON), nil |
| 294 | } |
| 295 | |
| 296 | func (*GitRepository) DecodePersistedObject(ctx context.Context, dag *dagql.Server, resultID uint64, _ *dagql.ResultCall, payload json.RawMessage) (dagql.Typed, error) { |
| 297 | var persisted persistedGitRepositoryPayload |
nothing calls this directly
no test coverage detected