Signed-off-by: Will Andrews did:plc:dadhhalkfcq3gucaq25hjqon
+59
-7
Diff
round #1
+18
knotserver/git/git.go
+18
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")
286
+
if err != nil {
287
+
return "", err
288
+
}
289
+
290
+
if remote == nil {
291
+
return "", nil
292
+
}
293
+
294
+
urls := remote.Config().URLs
295
+
if len(urls) == 0 {
296
+
return "", nil
297
+
}
298
+
299
+
return urls[0], nil
300
+
}
301
+
284
302
// WriteTar writes itself from a tree into a binary tar file format.
285
303
// prefix is root folder to be appended.
286
304
func (g *GitRepo) WriteTar(w io.Writer, prefix string) error {
+41
-7
knotserver/internal.go
+41
-7
knotserver/internal.go
···
453
453
return err
454
454
}
455
455
456
+
upstreamRemote, err := gr.UpstreamRemote()
457
+
if err != nil {
458
+
return fmt.Errorf("checking for upstream remote: %w", err)
459
+
}
460
+
456
461
defaultBranch, err := gr.FindMainBranch()
457
462
if err != nil {
458
463
return err
···
471
476
user = userIdent.Handle.String()
472
477
}
473
478
474
-
query := url.Values{}
475
-
query.Set("source", "branch")
476
-
query.Set("sourceBranch", pushedBranch)
477
-
query.Set("targetBranch", defaultBranch)
478
-
479
-
basePath, err := url.JoinPath(h.c.AppViewEndpoint, user, repoName, "pulls", "new")
479
+
pullURL, err := createPullURL(h.c.AppViewEndpoint, upstreamRemote, user, repoName, pushedBranch, defaultBranch)
480
480
if err != nil {
481
481
return err
482
482
}
483
-
pullURL := basePath + "?" + query.Encode()
484
483
485
484
ZWS := "\u200B"
486
485
*clientMsgs = append(*clientMsgs, ZWS)
···
490
489
return nil
491
490
}
492
491
492
+
func createPullURL(appviewURL, upstreamRemote, user, repoName, pushedBranch, defaultBranch string) (string, error) {
493
+
if upstreamRemote != "" {
494
+
return createForkPullURL(upstreamRemote, upstreamRemote, repoName, pushedBranch, defaultBranch)
495
+
}
496
+
497
+
query := url.Values{}
498
+
499
+
query.Set("source", "branch")
500
+
query.Set("sourceBranch", pushedBranch)
501
+
query.Set("targetBranch", defaultBranch)
502
+
503
+
basePath, err := url.JoinPath(appviewURL, user, repoName, "pulls", "new")
504
+
if err != nil {
505
+
return "", err
506
+
}
507
+
pullURL := basePath + "?" + query.Encode()
508
+
return pullURL, nil
509
+
}
510
+
511
+
func createForkPullURL(upstreamRemote, user, repoName, pushedBranch, defaultBranch string) (string, error) {
512
+
query := url.Values{}
513
+
514
+
query.Set("fork", fmt.Sprintf("%s/%s", user, repoName))
515
+
query.Set("source", "fork")
516
+
query.Set("sourceBranch", pushedBranch)
517
+
query.Set("targetBranch", defaultBranch)
518
+
519
+
basePath, err := url.JoinPath(upstreamRemote, "pulls", "new")
520
+
if err != nil {
521
+
return "", err
522
+
}
523
+
pullURL := basePath + "?" + query.Encode()
524
+
return pullURL, nil
525
+
}
526
+
493
527
func Internal(ctx context.Context, c *config.Config, db *db.DB, e *rbac.Enforcer, n *notifier.Notifier, res *idresolver.Resolver) http.Handler {
494
528
r := chi.NewRouter()
495
529
l := log.FromContext(ctx)
History
2 rounds
0 comments
willdot.net
submitted
#1
1 commit
expand
collapse
knotserver: create a fork PR link
Signed-off-by: Will Andrews <did:plc:dadhhalkfcq3gucaq25hjqon>
no conflicts, ready to merge
expand 0 comments
willdot.net
submitted
#0
1 commit
expand
collapse
knotserver: create a fork PR link
Signed-off-by: Will Andrews <did:plc:dadhhalkfcq3gucaq25hjqon>