Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use syntax.ParseRepoPath when appropriate #889

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions automod/consumer/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (fc *FirehoseConsumer) HandleRepoCommit(ctx context.Context, evt *comatprot

for _, op := range evt.Ops {
logger = logger.With("eventKind", op.Action, "path", op.Path)
collection, rkey, err := splitRepoPath(op.Path)
collection, rkey, err := syntax.ParseRepoPath(op.Path)
if err != nil {
logger.Error("invalid path in repo op")
logger.Error("invalid path in repo op", "err", err)
return nil
}

Expand Down
25 changes: 0 additions & 25 deletions automod/consumer/util.go

This file was deleted.

20 changes: 1 addition & 19 deletions cmd/beemo/firehose_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log/slog"
"net/http"
"net/url"
"strings"

comatproto "github.com/bluesky-social/indigo/api/atproto"
appbsky "github.com/bluesky-social/indigo/api/bsky"
Expand Down Expand Up @@ -60,23 +59,6 @@ func RunFirehoseConsumer(ctx context.Context, logger *slog.Logger, relayHost str
return events.HandleRepoStream(ctx, con, scheduler, logger)
}

// TODO: move this to a "ParsePath" helper in syntax package?
func splitRepoPath(path string) (syntax.NSID, syntax.RecordKey, error) {
parts := strings.SplitN(path, "/", 3)
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid record path: %s", path)
}
collection, err := syntax.ParseNSID(parts[0])
if err != nil {
return "", "", err
}
rkey, err := syntax.ParseRecordKey(parts[1])
if err != nil {
return "", "", err
}
return collection, rkey, nil
}

// NOTE: for now, this function basically never errors, just logs and returns nil. Should think through error processing better.
func HandleRepoCommit(ctx context.Context, logger *slog.Logger, evt *comatproto.SyncSubscribeRepos_Commit, postCallback func(context.Context, syntax.DID, syntax.RecordKey, appbsky.FeedPost) error) error {

Expand All @@ -102,7 +84,7 @@ func HandleRepoCommit(ctx context.Context, logger *slog.Logger, evt *comatproto.

for _, op := range evt.Ops {
logger = logger.With("eventKind", op.Action, "path", op.Path)
collection, rkey, err := splitRepoPath(op.Path)
collection, rkey, err := syntax.ParseRepoPath(op.Path)
if err != nil {
logger.Error("invalid path in repo op")
return nil
Expand Down
19 changes: 1 addition & 18 deletions cmd/goat/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,6 @@ func runFirehose(cctx *cli.Context) error {
return events.HandleRepoStream(ctx, con, scheduler, nil)
}

// TODO: move this to a "ParsePath" helper in syntax package?
func splitRepoPath(path string) (syntax.NSID, syntax.RecordKey, error) {
parts := strings.SplitN(path, "/", 3)
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid record path: %s", path)
}
collection, err := syntax.ParseNSID(parts[0])
if err != nil {
return "", "", err
}
rkey, err := syntax.ParseRecordKey(parts[1])
if err != nil {
return "", "", err
}
return collection, rkey, nil
}

func (gfc *GoatFirehoseConsumer) handleIdentityEvent(ctx context.Context, evt *comatproto.SyncSubscribeRepos_Identity) error {
out := make(map[string]interface{})
out["type"] = "identity"
Expand Down Expand Up @@ -229,7 +212,7 @@ func (gfc *GoatFirehoseConsumer) handleCommitEventOps(ctx context.Context, evt *
}

for _, op := range evt.Ops {
collection, rkey, err := splitRepoPath(op.Path)
collection, rkey, err := syntax.ParseRepoPath(op.Path)
if err != nil {
logger.Error("invalid path in repo op", "eventKind", op.Action, "path", op.Path)
return nil
Expand Down
Loading