Monorepo for Tangled tangled.org

appview,knotserver/xrpc: create repo on knot-side first #1206

deleted opened by boltless.me targeting master from sl/rvyxvsnxkkql

Because knotmirror is listening to creation of sh.tangled.repo records, the actual git repository should exist on sh.tangled.repo creation event.

Signed-off-by: Seongmin Lee git@boltless.me

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mhl5w55wch22
+30 -46
Diff #1
+28 -25
appview/state/state.go
··· 458 458 459 459 // create atproto record for this repo 460 460 rkey := tid.TID() 461 + 462 + client, err := s.oauth.ServiceClient( 463 + r, 464 + oauth.WithService(domain), 465 + oauth.WithLxm(tangled.RepoCreateNSID), 466 + oauth.WithDev(s.config.Core.Dev), 467 + ) 468 + if err != nil { 469 + l.Error("service auth failed", "err", err) 470 + s.pages.Notice(w, "repo", "Failed to reach PDS.") 471 + return 472 + } 473 + 474 + xe := tangled.RepoCreate( 475 + r.Context(), 476 + client, 477 + &tangled.RepoCreate_Input{ 478 + Rkey: rkey, 479 + Name: repoName, 480 + DefaultBranch: &defaultBranch, 481 + }, 482 + ) 483 + if err := xrpcclient.HandleXrpcErr(xe); err != nil { 484 + l.Error("xrpc error", "xe", xe) 485 + s.pages.Notice(w, "repo", err.Error()) 486 + return 487 + } 488 + 461 489 repo := &models.Repo{ 462 490 Did: user.Active.Did, 463 491 Name: repoName, ··· 522 550 } 523 551 defer rollback() 524 552 525 - client, err := s.oauth.ServiceClient( 526 - r, 527 - oauth.WithService(domain), 528 - oauth.WithLxm(tangled.RepoCreateNSID), 529 - oauth.WithDev(s.config.Core.Dev), 530 - ) 531 - if err != nil { 532 - l.Error("service auth failed", "err", err) 533 - s.pages.Notice(w, "repo", "Failed to reach PDS.") 534 - return 535 - } 536 - 537 - xe := tangled.RepoCreate( 538 - r.Context(), 539 - client, 540 - &tangled.RepoCreate_Input{ 541 - Rkey: rkey, 542 - }, 543 - ) 544 - if err := xrpcclient.HandleXrpcErr(xe); err != nil { 545 - l.Error("xrpc error", "xe", xe) 546 - s.pages.Notice(w, "repo", err.Error()) 547 - return 548 - } 549 - 550 553 err = db.AddRepo(tx, repo) 551 554 if err != nil { 552 555 l.Error("db write failed", "err", err)
+2 -21
knotserver/xrpc/create_repo.go
··· 10 10 "strings" 11 11 "time" 12 12 13 - comatproto "github.com/bluesky-social/indigo/api/atproto" 14 13 "github.com/bluesky-social/indigo/atproto/syntax" 15 14 "github.com/bluesky-social/indigo/xrpc" 16 15 securejoin "github.com/cyphar/filepath-securejoin" ··· 53 52 54 53 rkey := data.Rkey 55 54 56 - ident, err := h.Resolver.ResolveIdent(r.Context(), actorDid.String()) 57 - if err != nil || ident.Handle.IsInvalidHandle() { 58 - fail(xrpcerr.GenericError(err)) 59 - return 60 - } 61 - 62 - xrpcc := xrpc.Client{ 63 - Host: ident.PDSEndpoint(), 64 - } 65 - 66 - resp, err := comatproto.RepoGetRecord(r.Context(), &xrpcc, "", tangled.RepoNSID, actorDid.String(), rkey) 67 - if err != nil { 68 - fail(xrpcerr.GenericError(err)) 69 - return 70 - } 71 - 72 - repo := resp.Value.Val.(*tangled.Repo) 73 - 74 55 defaultBranch := h.Config.Repo.MainBranch 75 56 if data.DefaultBranch != nil && *data.DefaultBranch != "" { 76 57 defaultBranch = *data.DefaultBranch 77 58 } 78 59 79 - if err := validateRepoName(repo.Name); err != nil { 60 + if err := validateRepoName(data.Name); err != nil { 80 61 l.Error("creating repo", "error", err.Error()) 81 62 fail(xrpcerr.GenericError(err)) 82 63 return 83 64 } 84 65 85 - relativeRepoPath := filepath.Join(actorDid.String(), repo.Name) 66 + relativeRepoPath := filepath.Join(actorDid.String(), data.Name) 86 67 repoPath, _ := securejoin.SecureJoin(h.Config.Repo.ScanPath, relativeRepoPath) 87 68 88 69 if data.Source != nil && *data.Source != "" {

History

2 rounds 3 comments
sign up or login to add to the discussion
1 commit
expand
appview,knotserver/xrpc: create repo on knot-side first
expand 3 comments

you you explain the transaction rollback steps here? if the record creation fails will the knot have the directory created inside it?

Ah, right, so that was why we were creating PDS records first. I will bring @oyster.cafe's work to support that.

#1140 appview/state/state.go:511-544

makes sense, in which case, we can abandon this PR and live with the slight delay for now!

This pull has been deleted (possibly by jj abandon or jj squash)
1 commit
expand
appview,knotserver/xrpc: create repo on knot-side first
expand 0 comments