Skip to content

Commit 3e81780

Browse files
committed
Address PR comments
1 parent 0658622 commit 3e81780

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

git/git.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"io"
78
"net/url"
89
"os"
910
"os/exec"
@@ -12,7 +13,6 @@ import (
1213
"strings"
1314

1415
"github.com/cli/cli/internal/run"
15-
"github.com/cli/cli/pkg/iostreams"
1616
)
1717

1818
// ErrNotOnAnyBranch indicates that the user is in detached HEAD state
@@ -163,12 +163,10 @@ func CommitBody(sha string) (string, error) {
163163
}
164164

165165
// Push publishes a git ref to a remote and sets up upstream configuration
166-
func Push(remote string, ref string) error {
166+
func Push(remote string, ref string, cmdOut, cmdErr io.Writer) error {
167167
pushCmd := GitCommand("push", "--set-upstream", remote, ref)
168-
regexp := regexp.MustCompile("^remote:.*$")
169-
filterErr := iostreams.NewRegexFilterWriter(os.Stderr, regexp, "")
170-
pushCmd.Stdout = os.Stdout
171-
pushCmd.Stderr = filterErr
168+
pushCmd.Stdout = cmdOut
169+
pushCmd.Stderr = cmdErr
172170
return run.PrepareCmd(pushCmd).Run()
173171
}
174172

pkg/cmd/pr/create/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"errors"
55
"fmt"
66
"net/http"
7+
"os"
8+
"regexp"
79
"strings"
810
"time"
911

@@ -428,7 +430,10 @@ func createRun(opts *CreateOptions) error {
428430
pushTries := 0
429431
maxPushTries := 3
430432
for {
431-
if err := git.Push(headRemote.Name, fmt.Sprintf("HEAD:%s", headBranch)); err != nil {
433+
regexp := regexp.MustCompile("^remote: (|Create a pull request for '.*' on GitHub by visiting:.*|.*https://github.com/.*/pull/new/.*)$")
434+
cmdErr := NewRegexWriter(os.Stderr, regexp, "")
435+
cmdOut := os.Stdout
436+
if err := git.Push(headRemote.Name, fmt.Sprintf("HEAD:%s", headBranch), cmdOut, cmdErr); err != nil {
432437
if didForkRepo && pushTries < maxPushTries {
433438
pushTries++
434439
// first wait 2 seconds after forking, then 4s, then 6s
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package iostreams
1+
package create
22

33
import (
44
"bufio"
@@ -7,17 +7,17 @@ import (
77
"regexp"
88
)
99

10-
func NewRegexFilterWriter(out io.Writer, regexp *regexp.Regexp, repl string) io.Writer {
11-
return &RegexFilterWriter{out: out, regexp: *regexp, repl: repl}
10+
func NewRegexWriter(out io.Writer, regexp *regexp.Regexp, repl string) io.Writer {
11+
return &RegexWriter{out: out, regexp: *regexp, repl: repl}
1212
}
1313

14-
type RegexFilterWriter struct {
14+
type RegexWriter struct {
1515
out io.Writer
1616
regexp regexp.Regexp
1717
repl string
1818
}
1919

20-
func (s RegexFilterWriter) Write(data []byte) (int, error) {
20+
func (s RegexWriter) Write(data []byte) (int, error) {
2121
filtered := []byte{}
2222
repl := []byte(s.repl)
2323
scanner := bufio.NewScanner(bytes.NewReader(data))
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package iostreams
1+
package create
22

33
import (
44
"bytes"
@@ -108,26 +108,26 @@ func Test_Write(t *testing.T) {
108108
input: input{
109109
in: heredoc.Doc(`
110110
output: some information
111-
remote:
112-
remote: Create a pull request for 'regex' on GitHub by visiting:
111+
remote:
112+
remote: Create a pull request for 'regex' on GitHub by visiting:
113113
remote: https://github.com/owner/repo/pull/new/regex
114-
remote:
114+
remote:
115115
output: more information
116116
`),
117-
regexp: regexp.MustCompile("^remote.*$"),
117+
regexp: regexp.MustCompile("^remote: (|Create a pull request for '.*' on GitHub by visiting:.*|.*https://github.com/.*/pull/new/.*)$"),
118118
repl: "",
119119
},
120120
output: output{
121121
wantsErr: false,
122122
out: "output: some information\noutput: more information\n",
123-
length: 189,
123+
length: 192,
124124
},
125125
},
126126
}
127127

128128
for _, tt := range tests {
129129
out := &bytes.Buffer{}
130-
writer := NewRegexFilterWriter(out, tt.input.regexp, tt.input.repl)
130+
writer := NewRegexWriter(out, tt.input.regexp, tt.input.repl)
131131
t.Run(tt.name, func(t *testing.T) {
132132
length, err := writer.Write([]byte(tt.input.in))
133133

0 commit comments

Comments
 (0)