+13
-2
appview/state/pull.go
+13
-2
appview/state/pull.go
···
9
9
"log"
10
10
"net/http"
11
11
"strconv"
12
+
"strings"
12
13
"time"
13
14
14
15
"tangled.sh/tangled.sh/core/api/tangled"
···
295
296
Submission: pull.Submissions[roundIdInt],
296
297
Diff: &diff,
297
298
})
298
-
299
299
}
300
300
301
301
func (s *State) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) {
···
1534
1534
log.Printf("failed to get primary email: %s", err)
1535
1535
}
1536
1536
1537
+
actor := s.oauth.GetUser(r) // no need to check for nil as this is an authenticated request
1538
+
1539
+
footers := strings.Join([]string{
1540
+
fmt.Sprintf("Pull-id: %s", pull.PullAt()),
1541
+
fmt.Sprintf("Merged-by: %s", actor.Did),
1542
+
}, "\n")
1543
+
1544
+
pullBody := pull.Body + "\n\n" + footers
1545
+
1546
+
patch := patchutil.AddCommitFooters(pull.LatestPatch(), footers)
1547
+
1537
1548
ksClient, err := knotclient.NewSignedClient(f.Knot, secret, s.config.Core.Dev)
1538
1549
if err != nil {
1539
1550
log.Printf("failed to create signed client for %s: %s", f.Knot, err)
···
1542
1553
}
1543
1554
1544
1555
// Merge the pull request
1545
-
resp, err := ksClient.Merge([]byte(pull.LatestPatch()), f.OwnerDid(), f.RepoName, pull.TargetBranch, pull.Title, pull.Body, ident.Handle.String(), email.Address)
1556
+
resp, err := ksClient.Merge([]byte(patch), f.OwnerDid(), f.RepoName, pull.TargetBranch, pull.Title, pullBody, ident.Handle.String(), email.Address)
1546
1557
if err != nil {
1547
1558
log.Printf("failed to merge pull request: %s", err)
1548
1559
s.pages.Notice(w, "pull-merge-error", "Failed to merge pull request. Try again later.")
+5
patchutil/patchutil.go
+5
patchutil/patchutil.go
+265
patchutil/patchutil_test.go
+265
patchutil/patchutil_test.go
···
322
322
})
323
323
}
324
324
}
325
+
326
+
func TestAddCommmitFooters(t *testing.T) {
327
+
tests := []struct {
328
+
name string
329
+
input string
330
+
footers string
331
+
expected string
332
+
}{
333
+
{
334
+
name: "Single patch",
335
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
336
+
From: Author <author@example.com>
337
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
338
+
Subject: [PATCH] Example patch
339
+
340
+
more message body
341
+
342
+
---
343
+
file.txt | 2 +-
344
+
1 file changed, 1 insertions(+), 1 deletions(-)
345
+
346
+
diff --git a/file.txt b/file.txt
347
+
index 123456..789012 100644
348
+
--- a/file.txt
349
+
+++ b/file.txt
350
+
@@ -1 +1 @@
351
+
-old content
352
+
+new content
353
+
--
354
+
2.48.1`,
355
+
footers: `Pull-Id: Author <author@example.com>
356
+
Merge-Request: 123`,
357
+
expected: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
358
+
From: Author <author@example.com>
359
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
360
+
Subject: [PATCH] Example patch
361
+
362
+
more message body
363
+
364
+
365
+
Pull-Id: Author <author@example.com>
366
+
Merge-Request: 123
367
+
---
368
+
file.txt | 2 +-
369
+
1 file changed, 1 insertions(+), 1 deletions(-)
370
+
371
+
diff --git a/file.txt b/file.txt
372
+
index 123456..789012 100644
373
+
--- a/file.txt
374
+
+++ b/file.txt
375
+
@@ -1 +1 @@
376
+
-old content
377
+
+new content
378
+
--
379
+
2.48.1`,
380
+
},
381
+
{
382
+
name: "Two patches with --no-stat",
383
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
384
+
From: Author <author@example.com>
385
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
386
+
Subject: [PATCH 1/2] First patch
387
+
388
+
more message body
389
+
390
+
---
391
+
file.txt | 2 +-
392
+
1 file changed, 1 insertions(+), 1 deletions(-)
393
+
394
+
diff --git a/file1.txt b/file1.txt
395
+
index 123456..789012 100644
396
+
--- a/file1.txt
397
+
+++ b/file1.txt
398
+
@@ -1 +1 @@
399
+
-old content
400
+
+new content
401
+
--
402
+
2.48.1
403
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
404
+
From: Author <author@example.com>
405
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
406
+
Subject: [PATCH 2/2] Second patch
407
+
408
+
more message body
409
+
410
+
---
411
+
file.txt | 2 +-
412
+
1 file changed, 1 insertions(+), 1 deletions(-)
413
+
414
+
diff --git a/file2.txt b/file2.txt
415
+
index abcdef..ghijkl 100644
416
+
--- a/file2.txt
417
+
+++ b/file2.txt
418
+
@@ -1 +1 @@
419
+
-foo bar
420
+
+baz qux
421
+
--
422
+
2.48.1`,
423
+
footers: `Pull-Id: Author <author@example.com>
424
+
Merge-Request: 123`,
425
+
expected: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
426
+
From: Author <author@example.com>
427
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
428
+
Subject: [PATCH 1/2] First patch
429
+
430
+
more message body
431
+
432
+
433
+
Pull-Id: Author <author@example.com>
434
+
Merge-Request: 123
435
+
---
436
+
file.txt | 2 +-
437
+
1 file changed, 1 insertions(+), 1 deletions(-)
438
+
439
+
diff --git a/file1.txt b/file1.txt
440
+
index 123456..789012 100644
441
+
--- a/file1.txt
442
+
+++ b/file1.txt
443
+
@@ -1 +1 @@
444
+
-old content
445
+
+new content
446
+
--
447
+
2.48.1
448
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
449
+
From: Author <author@example.com>
450
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
451
+
Subject: [PATCH 2/2] Second patch
452
+
453
+
more message body
454
+
455
+
456
+
Pull-Id: Author <author@example.com>
457
+
Merge-Request: 123
458
+
---
459
+
file.txt | 2 +-
460
+
1 file changed, 1 insertions(+), 1 deletions(-)
461
+
462
+
diff --git a/file2.txt b/file2.txt
463
+
index abcdef..ghijkl 100644
464
+
--- a/file2.txt
465
+
+++ b/file2.txt
466
+
@@ -1 +1 @@
467
+
-foo bar
468
+
+baz qux
469
+
--
470
+
2.48.1`,
471
+
},
472
+
{
473
+
name: "Single patch with no stat",
474
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
475
+
From: Author <author@example.com>
476
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
477
+
Subject: [PATCH] Example patch
478
+
479
+
diff --git a/file.txt b/file.txt
480
+
index 123456..789012 100644
481
+
--- a/file.txt
482
+
+++ b/file.txt
483
+
@@ -1 +1 @@
484
+
-old content
485
+
+new content
486
+
--
487
+
2.48.1`,
488
+
footers: `Pull-Id: Author <author@example.com>
489
+
Merge-Request: 123`,
490
+
expected: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
491
+
From: Author <author@example.com>
492
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
493
+
Subject: [PATCH] Example patch
494
+
495
+
Pull-Id: Author <author@example.com>
496
+
Merge-Request: 123
497
+
498
+
diff --git a/file.txt b/file.txt
499
+
index 123456..789012 100644
500
+
--- a/file.txt
501
+
+++ b/file.txt
502
+
@@ -1 +1 @@
503
+
-old content
504
+
+new content
505
+
--
506
+
2.48.1`,
507
+
},
508
+
{
509
+
name: "Two patches with no stat",
510
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
511
+
From: Author <author@example.com>
512
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
513
+
Subject: [PATCH 1/2] First patch
514
+
515
+
with long message body
516
+
517
+
diff --git a/file1.txt b/file1.txt
518
+
index 123456..789012 100644
519
+
--- a/file1.txt
520
+
+++ b/file1.txt
521
+
@@ -1 +1 @@
522
+
-old content
523
+
+new content
524
+
--
525
+
2.48.1
526
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
527
+
From: Author <author@example.com>
528
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
529
+
Subject: [PATCH 2/2] Second patch
530
+
531
+
diff --git a/file2.txt b/file2.txt
532
+
index abcdef..ghijkl 100644
533
+
--- a/file2.txt
534
+
+++ b/file2.txt
535
+
@@ -1 +1 @@
536
+
-foo bar
537
+
+baz qux
538
+
--
539
+
2.48.1`,
540
+
footers: `Pull-Id: Author <author@example.com>
541
+
Merge-Request: 123`,
542
+
expected: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
543
+
From: Author <author@example.com>
544
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
545
+
Subject: [PATCH 1/2] First patch
546
+
547
+
with long message body
548
+
549
+
Pull-Id: Author <author@example.com>
550
+
Merge-Request: 123
551
+
552
+
diff --git a/file1.txt b/file1.txt
553
+
index 123456..789012 100644
554
+
--- a/file1.txt
555
+
+++ b/file1.txt
556
+
@@ -1 +1 @@
557
+
-old content
558
+
+new content
559
+
--
560
+
2.48.1
561
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
562
+
From: Author <author@example.com>
563
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
564
+
Subject: [PATCH 2/2] Second patch
565
+
566
+
Pull-Id: Author <author@example.com>
567
+
Merge-Request: 123
568
+
569
+
diff --git a/file2.txt b/file2.txt
570
+
index abcdef..ghijkl 100644
571
+
--- a/file2.txt
572
+
+++ b/file2.txt
573
+
@@ -1 +1 @@
574
+
-foo bar
575
+
+baz qux
576
+
--
577
+
2.48.1`,
578
+
},
579
+
}
580
+
581
+
for _, tt := range tests {
582
+
t.Run(tt.name, func(t *testing.T) {
583
+
result := AddCommitFooters(tt.input, tt.footers)
584
+
if result != tt.expected {
585
+
t.Errorf("Got:\n========\n%v\n========\nExpected:\n========\n%v\n========\n", result, tt.expected)
586
+
}
587
+
})
588
+
}
589
+
}