Skip to content

Commit a77ab2c

Browse files
authored
Release v0.7.1 (#449)
Backport #436 and #448 to v0.7.x release series.
2 parents 94b52d8 + 69baab9 commit a77ab2c

File tree

6 files changed

+164
-8
lines changed

6 files changed

+164
-8
lines changed

.changes/v0.7.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## <a name="v0.7.1">v0.7.1</a> - 2024-10-26
2+
### Fixed
3+
- branch submit: Fix bad log statement in --dry-run mode.
4+
- branch submit: Fix bug when importing externally created PRs, where the first comment in the PR would be hijacked as the navigation comment.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
66
and is generated by [Changie](https://github.com/miniscruff/changie).
77

8+
## <a name="v0.7.1">v0.7.1</a> - 2024-10-26
9+
### Fixed
10+
- branch submit: Fix bad log statement in --dry-run mode.
11+
- branch submit: Fix bug when importing externally created PRs, where the first comment in the PR would be hijacked as the navigation comment.
12+
813
## <a name="v0.7.0">v0.7.0</a> - 2024-10-02
914

1015
This release contains significant changes to internal state management to prevent corruption.

branch_submit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"slices"
8+
"strconv"
89
"strings"
910
"time"
1011

@@ -406,7 +407,7 @@ func (cmd *branchSubmitCmd) run(
406407
updates = append(updates, "set base to "+branch.Base)
407408
}
408409
if cmd.Draft != nil && pull.Draft != *cmd.Draft {
409-
updates = append(updates, "set draft to "+fmt.Sprint(cmd.Draft))
410+
updates = append(updates, "set draft to "+strconv.FormatBool(*cmd.Draft))
410411
}
411412

412413
if len(updates) == 0 {

internal/forge/github/comment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,16 @@ func (f *Repository) ListChangeComments(
205205
}
206206

207207
for _, node := range q.Node.PullRequest.Comments.Nodes {
208+
match := true
208209
for _, filter := range filters {
209210
if !filter(node) {
210-
continue
211+
match = false
212+
break
211213
}
212214
}
215+
if !match {
216+
continue
217+
}
213218

214219
item := &forge.ListChangeCommentItem{
215220
ID: &PRComment{

internal/forge/github/comment_test.go

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,151 @@
11
package github
22

3-
import "testing"
3+
import (
4+
"context"
5+
"encoding/json"
6+
"net/http"
7+
"net/http/httptest"
8+
"regexp"
9+
"testing"
10+
"time"
11+
12+
"github.com/shurcooL/githubv4"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
"go.abhg.dev/gs/internal/forge"
16+
"go.abhg.dev/gs/internal/logtest"
17+
"go.abhg.dev/testing/stub"
18+
)
419

520
// SetListChangeCommentsPageSize changes the page size
621
// used for listing change comments.
722
//
823
// It restores the old value after the test finishes.
924
func SetListChangeCommentsPageSize(t testing.TB, pageSize int) {
10-
old := _listChangeCommentsPageSize
11-
_listChangeCommentsPageSize = pageSize
12-
t.Cleanup(func() {
13-
_listChangeCommentsPageSize = old
14-
})
25+
t.Cleanup(stub.Value(&_listChangeCommentsPageSize, pageSize))
26+
}
27+
28+
func TestListChangeComments(t *testing.T) {
29+
type commentRes struct {
30+
ID string `json:"id"`
31+
Body string `json:"body"`
32+
URL string `json:"url"`
33+
34+
ViewerCanUpdate bool `json:"viewerCanUpdate"`
35+
ViewerDidAuthor bool `json:"viewerDidAuthor"`
36+
37+
CreatedAt time.Time `json:"createdAt"`
38+
UpdatedAt time.Time `json:"updatedAt"`
39+
}
40+
41+
tests := []struct {
42+
name string
43+
give []commentRes
44+
opts *forge.ListChangeCommentsOptions
45+
46+
wantBodies []string
47+
}{
48+
{
49+
name: "NoFilter",
50+
give: []commentRes{
51+
{
52+
ID: "abc",
53+
Body: "hello",
54+
URL: "https://example.com/comment/abc",
55+
},
56+
{
57+
ID: "def",
58+
Body: "world",
59+
URL: "https://example.com/comment/def",
60+
},
61+
},
62+
wantBodies: []string{"hello", "world"},
63+
},
64+
{
65+
name: "BodyMatchesAll",
66+
give: []commentRes{
67+
{
68+
ID: "abc",
69+
Body: "hello",
70+
URL: "https://example.com/comment/abc",
71+
},
72+
{
73+
ID: "def",
74+
Body: "world",
75+
URL: "https://example.com/comment/def",
76+
},
77+
},
78+
opts: &forge.ListChangeCommentsOptions{
79+
BodyMatchesAll: []*regexp.Regexp{
80+
regexp.MustCompile(`d$`),
81+
},
82+
},
83+
wantBodies: []string{"world"},
84+
},
85+
{
86+
name: "CanUpdate",
87+
give: []commentRes{
88+
{
89+
ID: "abc",
90+
Body: "hello",
91+
URL: "https://example.com/comment/abc",
92+
ViewerCanUpdate: true,
93+
},
94+
{
95+
ID: "def",
96+
Body: "world",
97+
URL: "https://example.com/comment/def",
98+
ViewerCanUpdate: false,
99+
},
100+
},
101+
opts: &forge.ListChangeCommentsOptions{
102+
CanUpdate: true,
103+
},
104+
wantBodies: []string{"hello"},
105+
},
106+
}
107+
108+
for _, tt := range tests {
109+
t.Run(tt.name, func(t *testing.T) {
110+
response := map[string]any{
111+
"data": map[string]any{
112+
"node": map[string]any{
113+
"comments": map[string]any{
114+
"pageInfo": map[string]any{
115+
"hasNextPage": false,
116+
},
117+
"nodes": tt.give,
118+
},
119+
},
120+
},
121+
}
122+
123+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
124+
enc := json.NewEncoder(w)
125+
enc.SetIndent("", " ")
126+
assert.NoError(t, enc.Encode(response))
127+
}))
128+
defer srv.Close()
129+
130+
repo, err := newRepository(
131+
context.Background(), new(Forge),
132+
"owner", "repo",
133+
logtest.New(t),
134+
githubv4.NewEnterpriseClient(srv.URL, nil),
135+
"repoID",
136+
)
137+
require.NoError(t, err)
138+
139+
prID := PR{Number: 1, GQLID: "prID"}
140+
141+
ctx := context.Background()
142+
var bodies []string
143+
for comment, err := range repo.ListChangeComments(ctx, &prID, tt.opts) {
144+
require.NoError(t, err)
145+
bodies = append(bodies, comment.Body)
146+
}
147+
148+
assert.Equal(t, tt.wantBodies, bodies)
149+
})
150+
}
15151
}

testdata/script/stack_submit_update_leave_draft.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ gs stack submit --dry-run
4141
cmpenv stderr $WORK/golden/submit-dry-run.txt
4242
! stderr 'draft' # draft status should not be changed
4343

44+
# dry-run: verify --dry-run *would* change draft status
45+
gs stack submit --no-draft --dry-run
46+
stderr 'WOULD update'
47+
stderr 'set draft to false'
48+
4449
shamhub dump changes
4550
cmpenvJSON stdout $WORK/golden/start.json
4651

0 commit comments

Comments
 (0)