repos / git-pr

a self-hosted git collaboration server
git clone https://github.com/picosh/git-pr.git

commit
967d908
parent
618a67c
author
Eric Bower
date
2024-06-24 10:42:22 -0400 EDT
chore: move fns around
2 files changed,  +63, -62
M cli.go
M cli.go
+0, -62
 1@@ -4,7 +4,6 @@ import (
 2 	"fmt"
 3 	"io"
 4 	"strconv"
 5-	"strings"
 6 	"text/tabwriter"
 7 	"time"
 8 
 9@@ -23,67 +22,6 @@ func getPrID(str string) (int64, error) {
10 	return prID, err
11 }
12 
13-type Ranger struct {
14-	Left  int
15-	Right int
16-}
17-
18-func parseRange(rnge string, sliceLen int) (*Ranger, error) {
19-	items := strings.Split(rnge, ":")
20-	left := 0
21-	var err error
22-	if items[0] != "" {
23-		left, err = strconv.Atoi(items[0])
24-		if err != nil {
25-			return nil, fmt.Errorf("first value before `:` must provide number")
26-		}
27-	}
28-
29-	if left < 0 {
30-		return nil, fmt.Errorf("first value must be >= 0")
31-	}
32-
33-	if left >= sliceLen {
34-		return nil, fmt.Errorf("first value must be less than number of patches")
35-	}
36-
37-	if len(items) == 1 {
38-		return &Ranger{
39-			Left:  left,
40-			Right: left,
41-		}, nil
42-	}
43-
44-	if items[1] == "" {
45-		return &Ranger{Left: left, Right: sliceLen - 1}, nil
46-	}
47-
48-	right, err := strconv.Atoi(items[1])
49-	if err != nil {
50-		return nil, fmt.Errorf("second value after `:` must provide number")
51-	}
52-
53-	if left > right {
54-		return nil, fmt.Errorf("second value must be greater than first value")
55-	}
56-
57-	if right >= sliceLen {
58-		return nil, fmt.Errorf("second value must be less than number of patches")
59-	}
60-
61-	return &Ranger{
62-		Left:  left,
63-		Right: right,
64-	}, nil
65-}
66-
67-func filterPatches(ranger *Ranger, patches []*Patch) []*Patch {
68-	if ranger.Left == ranger.Right {
69-		return []*Patch{patches[ranger.Left]}
70-	}
71-	return patches[ranger.Left:ranger.Right]
72-}
73-
74 func NewCli(sesh ssh.Session, be *Backend, pr GitPatchRequest) *cli.App {
75 	desc := `Patch requests (PR) are the simplest way to submit, review, and accept changes to your git repository.
76 Here's how it works:
M util.go
+63, -0
 1@@ -4,8 +4,10 @@ import (
 2 	"bufio"
 3 	"bytes"
 4 	"errors"
 5+	"fmt"
 6 	"io"
 7 	"os"
 8+	"strconv"
 9 	"strings"
10 
11 	"github.com/charmbracelet/ssh"
12@@ -48,6 +50,67 @@ func getAuthorizedKeys(path string) ([]ssh.PublicKey, error) {
13 	return keys, nil
14 }
15 
16+type Ranger struct {
17+	Left  int
18+	Right int
19+}
20+
21+func parseRange(rnge string, sliceLen int) (*Ranger, error) {
22+	items := strings.Split(rnge, ":")
23+	left := 0
24+	var err error
25+	if items[0] != "" {
26+		left, err = strconv.Atoi(items[0])
27+		if err != nil {
28+			return nil, fmt.Errorf("first value before `:` must provide number")
29+		}
30+	}
31+
32+	if left < 0 {
33+		return nil, fmt.Errorf("first value must be >= 0")
34+	}
35+
36+	if left >= sliceLen {
37+		return nil, fmt.Errorf("first value must be less than number of patches")
38+	}
39+
40+	if len(items) == 1 {
41+		return &Ranger{
42+			Left:  left,
43+			Right: left,
44+		}, nil
45+	}
46+
47+	if items[1] == "" {
48+		return &Ranger{Left: left, Right: sliceLen - 1}, nil
49+	}
50+
51+	right, err := strconv.Atoi(items[1])
52+	if err != nil {
53+		return nil, fmt.Errorf("second value after `:` must provide number")
54+	}
55+
56+	if left > right {
57+		return nil, fmt.Errorf("second value must be greater than first value")
58+	}
59+
60+	if right >= sliceLen {
61+		return nil, fmt.Errorf("second value must be less than number of patches")
62+	}
63+
64+	return &Ranger{
65+		Left:  left,
66+		Right: right,
67+	}, nil
68+}
69+
70+func filterPatches(ranger *Ranger, patches []*Patch) []*Patch {
71+	if ranger.Left == ranger.Right {
72+		return []*Patch{patches[ranger.Left]}
73+	}
74+	return patches[ranger.Left:ranger.Right]
75+}
76+
77 /* func gitServiceCommands(sesh ssh.Session, be *Backend, cmd, repoName string) error {
78 	name := utils.SanitizeRepo(repoName)
79 	// git bare repositories should end in ".git"