aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/bug/bug_comment.go2
-rw-r--r--commands/bug/bug_comment_add.go2
-rw-r--r--commands/bug/bug_comment_test.go1
-rw-r--r--commands/bug/bug_label.go2
-rw-r--r--commands/bug/bug_label_new.go4
-rw-r--r--commands/bug/bug_label_rm.go4
-rw-r--r--commands/bug/bug_select.go2
-rw-r--r--commands/bug/bug_show.go4
-rw-r--r--commands/bug/bug_status.go2
-rw-r--r--commands/bug/bug_status_close.go2
-rw-r--r--commands/bug/bug_status_open.go2
-rw-r--r--commands/bug/bug_test.go82
-rw-r--r--commands/bug/bug_title.go2
-rw-r--r--commands/bug/bug_title_edit.go2
-rw-r--r--commands/bug/completion.go4
-rw-r--r--commands/cmdtest/regex.go62
-rw-r--r--commands/cmdtest/regex_test.go25
-rw-r--r--go.mod6
-rw-r--r--go.sum12
19 files changed, 172 insertions, 50 deletions
diff --git a/commands/bug/bug_comment.go b/commands/bug/bug_comment.go
index 5cb8ff17..b037f688 100644
--- a/commands/bug/bug_comment.go
+++ b/commands/bug/bug_comment.go
@@ -26,7 +26,7 @@ func newBugCommentCommand(env *execenv.Env) *cobra.Command {
}
func runBugComment(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_comment_add.go b/commands/bug/bug_comment_add.go
index 152a1893..132de233 100644
--- a/commands/bug/bug_comment_add.go
+++ b/commands/bug/bug_comment_add.go
@@ -41,7 +41,7 @@ func newBugCommentNewCommand(env *execenv.Env) *cobra.Command {
}
func runBugCommentNew(env *execenv.Env, opts bugCommentNewOptions, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_comment_test.go b/commands/bug/bug_comment_test.go
index ecc1c5f6..add48b21 100644
--- a/commands/bug/bug_comment_test.go
+++ b/commands/bug/bug_comment_test.go
@@ -140,7 +140,6 @@ func requireCommentsEqual(t *testing.T, golden string, env *execenv.Env) {
comments = normalizeParsedComments(t, comments)
if *cmdtest.Update {
- t.Log("Got here")
for i, comment := range comments {
fileName := fmt.Sprintf(goldenFilePattern, golden, i)
require.NoError(t, os.WriteFile(fileName, []byte(comment.message), 0644))
diff --git a/commands/bug/bug_label.go b/commands/bug/bug_label.go
index 554496e3..ec076922 100644
--- a/commands/bug/bug_label.go
+++ b/commands/bug/bug_label.go
@@ -24,7 +24,7 @@ func newBugLabelCommand(env *execenv.Env) *cobra.Command {
}
func runBugLabel(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_label_new.go b/commands/bug/bug_label_new.go
index 1e1f2d4f..9fff851c 100644
--- a/commands/bug/bug_label_new.go
+++ b/commands/bug/bug_label_new.go
@@ -22,12 +22,12 @@ func newBugLabelNewCommand(env *execenv.Env) *cobra.Command {
}
func runBugLabelNew(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, cleanArgs, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
- added := args
+ added := cleanArgs
changes, _, err := b.ChangeLabels(text.CleanupOneLineArray(added), nil)
diff --git a/commands/bug/bug_label_rm.go b/commands/bug/bug_label_rm.go
index 6dda007c..d389830f 100644
--- a/commands/bug/bug_label_rm.go
+++ b/commands/bug/bug_label_rm.go
@@ -22,12 +22,12 @@ func newBugLabelRmCommand(env *execenv.Env) *cobra.Command {
}
func runBugLabelRm(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, cleanArgs, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
- removed := args
+ removed := cleanArgs
changes, _, err := b.ChangeLabels(nil, text.CleanupOneLineArray(removed))
diff --git a/commands/bug/bug_select.go b/commands/bug/bug_select.go
index 652c61ea..c93cd7b1 100644
--- a/commands/bug/bug_select.go
+++ b/commands/bug/bug_select.go
@@ -44,7 +44,7 @@ The complementary command is "git bug deselect" performing the opposite operatio
func runBugSelect(env *execenv.Env, args []string) error {
if len(args) == 0 {
- return errors.New("You must provide a bug id")
+ return errors.New("a bug id must be provided")
}
prefix := args[0]
diff --git a/commands/bug/bug_show.go b/commands/bug/bug_show.go
index 9a03c9a3..ef20df2a 100644
--- a/commands/bug/bug_show.go
+++ b/commands/bug/bug_show.go
@@ -47,7 +47,7 @@ func newBugShowCommand(env *execenv.Env) *cobra.Command {
}
func runBugShow(env *execenv.Env, opts bugShowOptions, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
@@ -91,7 +91,7 @@ func runBugShow(env *execenv.Env, opts bugShowOptions, args []string) error {
case "title":
env.Out.Printf("%s\n", snap.Title)
default:
- return fmt.Errorf("\nUnsupported field: %s\n", opts.fields)
+ return fmt.Errorf("unsupported field: %s", opts.fields)
}
return nil
diff --git a/commands/bug/bug_status.go b/commands/bug/bug_status.go
index 59bef3fd..c8542240 100644
--- a/commands/bug/bug_status.go
+++ b/commands/bug/bug_status.go
@@ -24,7 +24,7 @@ func newBugStatusCommand(env *execenv.Env) *cobra.Command {
}
func runBugStatus(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_status_close.go b/commands/bug/bug_status_close.go
index 1d06007b..7a8ae4de 100644
--- a/commands/bug/bug_status_close.go
+++ b/commands/bug/bug_status_close.go
@@ -21,7 +21,7 @@ func newBugStatusCloseCommand(env *execenv.Env) *cobra.Command {
}
func runBugStatusClose(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_status_open.go b/commands/bug/bug_status_open.go
index e99d2db0..0c0c02f0 100644
--- a/commands/bug/bug_status_open.go
+++ b/commands/bug/bug_status_open.go
@@ -21,7 +21,7 @@ func newBugStatusOpenCommand(env *execenv.Env) *cobra.Command {
}
func runBugStatusOpen(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_test.go b/commands/bug/bug_test.go
index 6b0aa4e0..c13e8db7 100644
--- a/commands/bug/bug_test.go
+++ b/commands/bug/bug_test.go
@@ -1,13 +1,12 @@
package bugcmd
import (
- "encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/commands/bug/testenv"
- "github.com/MichaelMure/git-bug/commands/cmdjson"
+ . "github.com/MichaelMure/git-bug/commands/cmdtest"
)
func Test_repairQuery(t *testing.T) {
@@ -47,24 +46,69 @@ func Test_repairQuery(t *testing.T) {
}
func TestBug_Format(t *testing.T) {
- const expOrgMode = `^#+TODO: OPEN | CLOSED
-[*] OPEN [0-9a-f]{7} \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\] John Doe: this is a bug title ::
-[*]{2} Last Edited: \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\]
-[*]{2} Actors:
-: [0-9a-f]{7} John Doe
-[*]{2} Participants:
-: [0-9a-f]{7} John Doe
-$`
+ const expOrgMode = `#+TODO: OPEN | CLOSED
+* OPEN ` + ExpHumanId + ` [` + ExpOrgModeDate + `] John Doe: this is a bug title ::
+** Last Edited: [` + ExpOrgModeDate + `]
+** Actors:
+: ` + ExpHumanId + ` John Doe
+** Participants:
+: ` + ExpHumanId + ` John Doe
+`
+
+ const expJson = `[
+ {
+ "id": "` + ExpId + `",
+ "human_id": "` + ExpHumanId + `",
+ "create_time": {
+ "timestamp": ` + ExpTimestamp + `,
+ "time": "` + ExpISO8601 + `",
+ "lamport": 2
+ },
+ "edit_time": {
+ "timestamp": ` + ExpTimestamp + `,
+ "time": "` + ExpISO8601 + `",
+ "lamport": 2
+ },
+ "status": "open",
+ "labels": null,
+ "title": "this is a bug title",
+ "actors": [
+ {
+ "id": "` + ExpId + `",
+ "human_id": "` + ExpHumanId + `",
+ "name": "John Doe",
+ "login": ""
+ }
+ ],
+ "participants": [
+ {
+ "id": "` + ExpId + `",
+ "human_id": "` + ExpHumanId + `",
+ "name": "John Doe",
+ "login": ""
+ }
+ ],
+ "author": {
+ "id": "` + ExpId + `",
+ "human_id": "` + ExpHumanId + `",
+ "name": "John Doe",
+ "login": ""
+ },
+ "comments": 1,
+ "metadata": {}
+ }
+]
+`
cases := []struct {
format string
exp string
}{
- {"default", "^[0-9a-f]{7}\topen\tthis is a bug title John Doe \n$"},
- {"plain", "^[0-9a-f]{7}\topen\tthis is a bug title\n$"},
- {"id", "^[0-9a-f]{64}\n$"},
+ {"default", ExpHumanId + "\topen\tthis is a bug title John Doe \n"},
+ {"plain", ExpHumanId + "\topen\tthis is a bug title\n"},
+ {"id", ExpId + "\n"},
{"org-mode", expOrgMode},
- {"json", ".*"},
+ {"json", expJson},
}
for _, testcase := range cases {
@@ -79,15 +123,7 @@ $`
}
require.NoError(t, runBug(env, opts, []string{}))
-
- switch testcase.format {
- case "json":
- var bugs []cmdjson.BugExcerpt
- require.NoError(t, json.Unmarshal(env.Out.Bytes(), &bugs))
- require.Len(t, bugs, 1)
- default:
- require.Regexp(t, testcase.exp, env.Out.String())
- }
+ require.Regexp(t, MakeExpectedRegex(testcase.exp), env.Out.String())
})
}
}
diff --git a/commands/bug/bug_title.go b/commands/bug/bug_title.go
index 47603410..af959fb7 100644
--- a/commands/bug/bug_title.go
+++ b/commands/bug/bug_title.go
@@ -23,7 +23,7 @@ func newBugTitleCommand(env *execenv.Env) *cobra.Command {
}
func runBugTitle(env *execenv.Env, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/bug_title_edit.go b/commands/bug/bug_title_edit.go
index fc60824f..2d6bafca 100644
--- a/commands/bug/bug_title_edit.go
+++ b/commands/bug/bug_title_edit.go
@@ -38,7 +38,7 @@ func newBugTitleEditCommand(env *execenv.Env) *cobra.Command {
}
func runBugTitleEdit(env *execenv.Env, opts bugTitleEditOptions, args []string) error {
- b, args, err := ResolveSelected(env.Backend, args)
+ b, _, err := ResolveSelected(env.Backend, args)
if err != nil {
return err
}
diff --git a/commands/bug/completion.go b/commands/bug/completion.go
index 4754f97d..62bf658a 100644
--- a/commands/bug/completion.go
+++ b/commands/bug/completion.go
@@ -50,7 +50,7 @@ func BugAndLabelsCompletion(env *execenv.Env, addOrRemove bool) completion.Valid
_ = env.Backend.Close()
}()
- b, args, err := ResolveSelected(env.Backend, args)
+ b, cleanArgs, err := ResolveSelected(env.Backend, args)
if _select.IsErrNoValidId(err) {
// we need a bug first to complete labels
return bugWithBackend(env.Backend, toComplete)
@@ -62,7 +62,7 @@ func BugAndLabelsCompletion(env *execenv.Env, addOrRemove bool) completion.Valid
snap := b.Snapshot()
seenLabels := map[bug.Label]bool{}
- for _, label := range args {
+ for _, label := range cleanArgs {
seenLabels[bug.Label(label)] = addOrRemove
}
diff --git a/commands/cmdtest/regex.go b/commands/cmdtest/regex.go
new file mode 100644
index 00000000..0b9cb672
--- /dev/null
+++ b/commands/cmdtest/regex.go
@@ -0,0 +1,62 @@
+package cmdtest
+
+import (
+ "regexp"
+ "strings"
+)
+
+const ExpId = "\x07id\x07"
+const ExpHumanId = "\x07human-id\x07"
+const ExpTimestamp = "\x07timestamp\x07"
+const ExpISO8601 = "\x07iso8601\x07"
+
+const ExpOrgModeDate = "\x07org-mode-date\x07"
+
+// MakeExpectedRegex transform a raw string of an expected output into a regex suitable for testing.
+// Some markers like ExpId are available to substitute the appropriate regex for element that can vary randomly.
+func MakeExpectedRegex(input string) string {
+ var substitutes = map[string]string{
+ ExpId: `[0-9a-f]{64}`,
+ ExpHumanId: `[0-9a-f]{7}`,
+ ExpTimestamp: `[0-9]{7,10}`,
+ ExpISO8601: `\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?`,
+ ExpOrgModeDate: `\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d`,
+ }
+
+ escaped := []rune(regexp.QuoteMeta(input))
+
+ var result strings.Builder
+ var inSubstitute bool
+ var substitute strings.Builder
+
+ result.WriteString("^")
+
+ for i := 0; i < len(escaped); i++ {
+ r := escaped[i]
+ if !inSubstitute && r == '\x07' {
+ substitute.Reset()
+ substitute.WriteRune(r)
+ inSubstitute = true
+ continue
+ }
+ if inSubstitute && r == '\x07' {
+ substitute.WriteRune(r)
+ sub, ok := substitutes[substitute.String()]
+ if !ok {
+ panic("unknown substitute: " + substitute.String())
+ }
+ result.WriteString(sub)
+ inSubstitute = false
+ continue
+ }
+ if inSubstitute {
+ substitute.WriteRune(r)
+ } else {
+ result.WriteRune(r)
+ }
+ }
+
+ result.WriteString("$")
+
+ return result.String()
+}
diff --git a/commands/cmdtest/regex_test.go b/commands/cmdtest/regex_test.go
new file mode 100644
index 00000000..7f2e75fa
--- /dev/null
+++ b/commands/cmdtest/regex_test.go
@@ -0,0 +1,25 @@
+package cmdtest
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestMakeExpectedRegex(t *testing.T) {
+ cases := []struct {
+ sub string
+ text string
+ }{
+ {ExpId, "d96dc877077a571414168c946eb013035888715b561e75682cfae9ef785e3227"},
+ {ExpHumanId, "d96dc87"},
+ {ExpTimestamp, "1674368486"},
+ {ExpISO8601, "2023-01-22T07:21:26+01:00"},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.sub, func(t *testing.T) {
+ require.Regexp(t, MakeExpectedRegex(tc.text), tc.text)
+ })
+ }
+}
diff --git a/go.mod b/go.mod
index 0008ef92..f321cafc 100644
--- a/go.mod
+++ b/go.mod
@@ -28,9 +28,9 @@ require (
github.com/stretchr/testify v1.8.1
github.com/vbauerster/mpb/v8 v8.1.4
github.com/vektah/gqlparser/v2 v2.5.1
- github.com/xanzy/go-gitlab v0.77.0
+ github.com/xanzy/go-gitlab v0.78.0
golang.org/x/crypto v0.5.0
- golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c
+ golang.org/x/oauth2 v0.3.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.4.0
golang.org/x/text v0.6.0
@@ -115,7 +115,7 @@ require (
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/term v0.4.0
- golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
+ golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.4.0 // indirect
golang.org/x/vuln v0.0.0-20220908155419-5537ad2271a7
google.golang.org/appengine v1.6.7 // indirect
diff --git a/go.sum b/go.sum
index 6c735e9e..cdbe38a5 100644
--- a/go.sum
+++ b/go.sum
@@ -312,8 +312,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
-github.com/xanzy/go-gitlab v0.77.0 h1:UrbGlxkWVCbkpa6Fk6cM8ARh+rLACWemkJnsawT7t98=
-github.com/xanzy/go-gitlab v0.77.0/go.mod h1:d/a0vswScO7Agg1CZNz15Ic6SSvBG9vfw8egL99t4kA=
+github.com/xanzy/go-gitlab v0.78.0 h1:8jUHfQVAprG04Av5g0PxVd3CNsZ5hCbojIax7Hba1mE=
+github.com/xanzy/go-gitlab v0.78.0/go.mod h1:DlByVTSXhPsJMYL6+cm8e8fTJjeBmhrXdC/yvkKKt6M=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
@@ -352,8 +352,8 @@ golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfS
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
-golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c h1:q3gFqPqH7NVofKo3c3yETAP//pPI+G5mvB7qqj1Y5kY=
-golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg=
+golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8=
+golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -405,8 +405,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
-golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 h1:ftMN5LMiBFjbzleLqtoBZk7KdJwhuybIU+FckUHgoyQ=
-golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
+golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=