34 lines
943 B
Go
34 lines
943 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
// headsBucket is the module's state bucket heads, `<module>_<name>` as the indexer's buckets are named: the head last
|
|
// written on FORGE for each pull request (manifest state entry heads, novox/hq ADR 0443 §5).
|
|
const headsBucket = forgeBridgeModule + "_heads"
|
|
|
|
// kvHeads is the bucket heads as the bridge's headStore.
|
|
type kvHeads struct{ kv jetstream.KeyValue }
|
|
|
|
func (s kvHeads) Get(ctx context.Context, key string) (string, bool, error) {
|
|
e, err := s.kv.Get(ctx, key)
|
|
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
|
return "", false, nil
|
|
}
|
|
if err != nil {
|
|
return "", false, err
|
|
}
|
|
return string(e.Value()), true, nil
|
|
}
|
|
|
|
func (s kvHeads) Put(ctx context.Context, key, head string) error {
|
|
_, err := s.kv.PutString(ctx, key, head)
|
|
return err
|
|
}
|
|
|
|
func (s kvHeads) Delete(ctx context.Context, key string) error { return s.kv.Delete(ctx, key) }
|