diff --git a/knotfeed/legacy.go b/knotfeed/legacy.go index e437c824c..5ca01a501 100644 --- a/knotfeed/legacy.go +++ b/knotfeed/legacy.go @@ -42,7 +42,7 @@ type legacyRefUpdate struct { Ref string `json:"ref"` OldSha string `json:"oldSha"` NewSha string `json:"newSha"` - CommitterDid syntax.DID `json:"committerDid"` + CommitterDid string `json:"committerDid"` PushOptions []string `json:"pushOptions"` } @@ -92,9 +92,14 @@ func legacyRefOp(payload json.RawMessage, commit *Commit) error { Prior: ParsePriorSha(event.OldSha), } if !newSha.IsZero() { + // old knots leave committerDid empty; attribute those pushes to the repo itself + editor, err := syntax.ParseDID(event.CommitterDid) + if err != nil { + editor = event.Repo + } record, err := encodeRefRecord(RefRecord{ Sha: newSha, - Editor: event.CommitterDid, + Editor: editor, PushOptions: event.PushOptions, }) if err != nil { diff --git a/knotfeed/legacy_test.go b/knotfeed/legacy_test.go index f8fca9f9e..e81720ddc 100644 --- a/knotfeed/legacy_test.go +++ b/knotfeed/legacy_test.go @@ -118,7 +118,7 @@ func TestLegacyFrameReadsAsCommit(t *testing.T) { Repo: "did:plc:scallop", Seq: 11, Records: []RecordOp{refOp(t, "refs/heads/new", zeroSha1, - RefRecord{Sha: sha(t, legacyNewSha)})}, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, }, }, { @@ -128,7 +128,19 @@ func TestLegacyFrameReadsAsCommit(t *testing.T) { Repo: "did:plc:scallop", Seq: 11, Records: []RecordOp{refOp(t, "refs/heads/new", "", - RefRecord{Sha: sha(t, legacyNewSha)})}, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, + }, + }, + { + name: "push with an empty committerDid", + frame: `{"nsid":"sh.tangled.git.refUpdate","created":11,` + + `"event":{"ref":"refs/heads/main","repo":"did:plc:scallop","committerDid":"",` + + `"oldSha":"` + legacyOldSha + `","newSha":"` + legacyNewSha + `"}}`, + want: Commit{ + Repo: "did:plc:scallop", + Seq: 11, + Records: []RecordOp{refOp(t, "refs/heads/main", legacyOldSha, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, }, }, {