Monorepo for Tangled tangled.org
859
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: create a fork PR link #341

open opened by willdot.net targeting master from willdot.net/tangled-fork: fork-pr-command

This should allow the PR link when pushing, to cater for forks.

Full disclosure, I haven't tested this because I can't get my local knot setup to work properly 🫠

Signed-off-by: Will Andrews did:plc:dadhhalkfcq3gucaq25hjqon

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:dadhhalkfcq3gucaq25hjqon/sh.tangled.repo.pull/3ml7kaijyha22
+43 -8
Interdiff #1 #2
knotserver/git/git.go

This file has not been changed.

+28 -7
knotserver/internal.go
··· 8 8 "net/http" 9 9 "net/url" 10 10 "os" 11 + "path" 11 12 "path/filepath" 12 13 "strings" 13 14 ··· 476 477 user = userIdent.Handle.String() 477 478 } 478 479 479 - pullURL, err := createPullURL(h.c.AppViewEndpoint, remote, user, repoName, pushedBranch, defaultBranch) 480 + pullURL, err := h.createPullURL(h.c.AppViewEndpoint, remote, user, repoName, pushedBranch, defaultBranch) 480 481 if err != nil { 481 482 return err 482 483 } ··· 489 490 return nil 490 491 } 491 492 492 - func createPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 493 + func (h *InternalHandle) createPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 493 494 if remote != "" { 494 - return createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch) 495 + return h.createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch) 495 496 } 496 497 497 498 query := url.Values{} ··· 508 509 return pullURL, nil 509 510 } 510 511 511 - func createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 512 + func (h *InternalHandle) createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 512 513 query := url.Values{} 513 514 514 515 query.Set("fork", fmt.Sprintf("%s/%s", user, repoName)) ··· 516 517 query.Set("sourceBranch", pushedBranch) 517 518 query.Set("targetBranch", defaultBranch) 518 519 519 - u, err := url.Parse(remote) 520 + repoPath, err := h.getRemoteOwnerRepoNamePath(remote) 520 521 if err != nil { 521 - return "", fmt.Errorf("invalid remote: %w", err) 522 + return "", err 522 523 } 523 524 524 - basePath, err := url.JoinPath(appviewURL, u.Path, "pulls", "new") 525 + basePath, err := url.JoinPath(appviewURL, repoPath, "pulls", "new") 525 526 if err != nil { 526 527 return "", err 527 528 } ··· 529 530 return pullURL, nil 530 531 } 531 532 533 + func (h *InternalHandle) getRemoteOwnerRepoNamePath(remote string) (string, error) { 534 + u, err := url.Parse(remote) 535 + if err != nil { 536 + return "", fmt.Errorf("invalid remote: %w", err) 537 + } 538 + 539 + if u.Scheme != "file" { 540 + return u.Path, nil 541 + } 542 + 543 + repoDid := path.Base(u.String()) 544 + 545 + owner, name, err := h.db.GetRepoKeyOwner(repoDid) 546 + if err != nil { 547 + return "", err 548 + } 549 + 550 + return fmt.Sprintf("%s/%s", owner, name), nil 551 + } 552 + 532 553 func Internal(ctx context.Context, c *config.Config, db *db.DB, e *rbac.Enforcer, n *notifier.Notifier, res *idresolver.Resolver) http.Handler { 533 554 r := chi.NewRouter() 534 555 l := log.FromContext(ctx)
+15 -1
knotserver/internal_test.go
··· 5 5 6 6 "github.com/alecthomas/assert/v2" 7 7 "github.com/stretchr/testify/require" 8 + "tangled.org/core/knotserver/db" 8 9 ) 9 10 10 11 const ( ··· 31 32 remote: "https://knot1.tangled.sh/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing", 32 33 expectedURL: "https://tangled.org/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing/pulls/new?fork=did%3Aplc%3Adadhhalkfcq3gucaq25hjqon%2Fknot-testing-fork&source=fork&sourceBranch=feature-abc&targetBranch=main", 33 34 }, 35 + "is fork on same knot": { 36 + repoName: "knot-testing-fork", 37 + remote: "file:///home/git/repositories/did:plc:ixran6dpypl5lslliiqceshs", 38 + expectedURL: "https://tangled.org/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing/pulls/new?fork=did%3Aplc%3Adadhhalkfcq3gucaq25hjqon%2Fknot-testing-fork&source=fork&sourceBranch=feature-abc&targetBranch=main", 39 + }, 34 40 } 35 41 36 42 for name, tc := range tt { 37 43 t.Run(name, func(t *testing.T) { 38 - res, err := createPullURL(appviewURL, tc.remote, user, tc.repoName, pushedBranch, defaultBranch) 44 + database, err := db.Setup(t.Context(), ":memory:") 45 + require.NoError(t, err) 46 + err = database.StoreRepoKey("did:plc:ixran6dpypl5lslliiqceshs", []byte{}, "did:plc:dadhhalkfcq3gucaq25hjqon", "knot-testing", "at://uri") 47 + require.NoError(t, err) 48 + 49 + h := InternalHandle{ 50 + db: database, 51 + } 52 + res, err := h.createPullURL(appviewURL, tc.remote, user, tc.repoName, pushedBranch, defaultBranch) 39 53 require.NoError(t, err) 40 54 41 55 assert.Equal(t, tc.expectedURL, res)

History

5 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
knotserver: create a fork PR link
no conflicts, ready to merge
expand 0 comments
1 commit
expand
knotserver: create a fork PR link
expand 0 comments
1 commit
expand
knotserver: create a fork PR link
expand 0 comments
1 commit
expand
knotserver: create a fork PR link
expand 0 comments
1 commit
expand
knotserver: create a fork PR link
expand 0 comments