Monorepo for Tangled tangled.org
856
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
+58 -9
Interdiff #0 #1
+2 -2
knotserver/git/git.go
··· 281 281 return strings.TrimSpace(string(output)), nil 282 282 } 283 283 284 - func (g *GitRepo) UpstreamRemote() (string, error) { 285 - remote, err := g.r.Remote("upstream") 284 + func (g *GitRepo) Remote() (string, error) { 285 + remote, err := g.r.Remote("origin") 286 286 if err != nil { 287 287 return "", err 288 288 }
+12 -7
knotserver/internal.go
··· 453 453 return err 454 454 } 455 455 456 - upstreamRemote, err := gr.UpstreamRemote() 456 + remote, err := gr.Remote() 457 457 if err != nil { 458 458 return fmt.Errorf("checking for upstream remote: %w", err) 459 459 } ··· 476 476 user = userIdent.Handle.String() 477 477 } 478 478 479 - pullURL, err := createPullURL(h.c.AppViewEndpoint, upstreamRemote, user, repoName, pushedBranch, defaultBranch) 479 + pullURL, err := createPullURL(h.c.AppViewEndpoint, remote, user, repoName, pushedBranch, defaultBranch) 480 480 if err != nil { 481 481 return err 482 482 } ··· 489 489 return nil 490 490 } 491 491 492 - func createPullURL(appviewURL, upstreamRemote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 493 - if upstreamRemote != "" { 494 - return createForkPullURL(upstreamRemote, upstreamRemote, repoName, pushedBranch, defaultBranch) 492 + func createPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 493 + if remote != "" { 494 + return createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch) 495 495 } 496 496 497 497 query := url.Values{} ··· 508 508 return pullURL, nil 509 509 } 510 510 511 - func createForkPullURL(upstreamRemote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 511 + func createForkPullURL(appviewURL, remote, user, repoName, pushedBranch, defaultBranch string) (string, error) { 512 512 query := url.Values{} 513 513 514 514 query.Set("fork", fmt.Sprintf("%s/%s", user, repoName)) ··· 516 516 query.Set("sourceBranch", pushedBranch) 517 517 query.Set("targetBranch", defaultBranch) 518 518 519 - basePath, err := url.JoinPath(upstreamRemote, "pulls", "new") 519 + u, err := url.Parse(remote) 520 + if err != nil { 521 + return "", fmt.Errorf("invalid remote: %w", err) 522 + } 523 + 524 + basePath, err := url.JoinPath(appviewURL, u.Path, "pulls", "new") 520 525 if err != nil { 521 526 return "", err 522 527 }
+44
knotserver/internal_test.go
··· 1 + package knotserver 2 + 3 + import ( 4 + "testing" 5 + 6 + "github.com/alecthomas/assert/v2" 7 + "github.com/stretchr/testify/require" 8 + ) 9 + 10 + const ( 11 + appviewURL = "https://tangled.org/" 12 + user = "did:plc:dadhhalkfcq3gucaq25hjqon" 13 + pushedBranch = "feature-abc" 14 + defaultBranch = "main" 15 + ) 16 + 17 + func TestCreatePullURL(t *testing.T) { 18 + 19 + tt := map[string]struct { 20 + repoName string 21 + remote string 22 + expectedURL string 23 + }{ 24 + "not a fork": { 25 + repoName: "knot-testing", 26 + remote: "", 27 + expectedURL: "https://tangled.org/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing/pulls/new?source=branch&sourceBranch=feature-abc&targetBranch=main", 28 + }, 29 + "is fork": { 30 + repoName: "knot-testing-fork", 31 + remote: "https://knot1.tangled.sh/did:plc:dadhhalkfcq3gucaq25hjqon/knot-testing", 32 + 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 + 36 + for name, tc := range tt { 37 + t.Run(name, func(t *testing.T) { 38 + res, err := createPullURL(appviewURL, tc.remote, user, tc.repoName, pushedBranch, defaultBranch) 39 + require.NoError(t, err) 40 + 41 + assert.Equal(t, tc.expectedURL, res) 42 + }) 43 + } 44 + }

History

5 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
knotserver: create a fork PR link
merge conflicts detected
expand
  • knotserver/git/git.go:13
  • knotserver/internal.go:8
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