Skip to content

Commit

Permalink
Release v0.7.1 (#449)
Browse files Browse the repository at this point in the history
Backport #436 and #448 to v0.7.x release series.
  • Loading branch information
abhinav authored Oct 26, 2024
2 parents 94b52d8 + 69baab9 commit a77ab2c
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .changes/v0.7.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## <a name="v0.7.1">v0.7.1</a> - 2024-10-26
### Fixed
- branch submit: Fix bad log statement in --dry-run mode.
- branch submit: Fix bug when importing externally created PRs, where the first comment in the PR would be hijacked as the navigation comment.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).

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

## <a name="v0.7.0">v0.7.0</a> - 2024-10-02

This release contains significant changes to internal state management to prevent corruption.
Expand Down
3 changes: 2 additions & 1 deletion branch_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -406,7 +407,7 @@ func (cmd *branchSubmitCmd) run(
updates = append(updates, "set base to "+branch.Base)
}
if cmd.Draft != nil && pull.Draft != *cmd.Draft {
updates = append(updates, "set draft to "+fmt.Sprint(cmd.Draft))
updates = append(updates, "set draft to "+strconv.FormatBool(*cmd.Draft))
}

if len(updates) == 0 {
Expand Down
7 changes: 6 additions & 1 deletion internal/forge/github/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ func (f *Repository) ListChangeComments(
}

for _, node := range q.Node.PullRequest.Comments.Nodes {
match := true
for _, filter := range filters {
if !filter(node) {
continue
match = false
break
}
}
if !match {
continue
}

item := &forge.ListChangeCommentItem{
ID: &PRComment{
Expand Down
148 changes: 142 additions & 6 deletions internal/forge/github/comment_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,151 @@
package github

import "testing"
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"regexp"
"testing"
"time"

"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/gs/internal/forge"
"go.abhg.dev/gs/internal/logtest"
"go.abhg.dev/testing/stub"
)

// SetListChangeCommentsPageSize changes the page size
// used for listing change comments.
//
// It restores the old value after the test finishes.
func SetListChangeCommentsPageSize(t testing.TB, pageSize int) {
old := _listChangeCommentsPageSize
_listChangeCommentsPageSize = pageSize
t.Cleanup(func() {
_listChangeCommentsPageSize = old
})
t.Cleanup(stub.Value(&_listChangeCommentsPageSize, pageSize))
}

func TestListChangeComments(t *testing.T) {
type commentRes struct {
ID string `json:"id"`
Body string `json:"body"`
URL string `json:"url"`

ViewerCanUpdate bool `json:"viewerCanUpdate"`
ViewerDidAuthor bool `json:"viewerDidAuthor"`

CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

tests := []struct {
name string
give []commentRes
opts *forge.ListChangeCommentsOptions

wantBodies []string
}{
{
name: "NoFilter",
give: []commentRes{
{
ID: "abc",
Body: "hello",
URL: "https://example.com/comment/abc",
},
{
ID: "def",
Body: "world",
URL: "https://example.com/comment/def",
},
},
wantBodies: []string{"hello", "world"},
},
{
name: "BodyMatchesAll",
give: []commentRes{
{
ID: "abc",
Body: "hello",
URL: "https://example.com/comment/abc",
},
{
ID: "def",
Body: "world",
URL: "https://example.com/comment/def",
},
},
opts: &forge.ListChangeCommentsOptions{
BodyMatchesAll: []*regexp.Regexp{
regexp.MustCompile(`d$`),
},
},
wantBodies: []string{"world"},
},
{
name: "CanUpdate",
give: []commentRes{
{
ID: "abc",
Body: "hello",
URL: "https://example.com/comment/abc",
ViewerCanUpdate: true,
},
{
ID: "def",
Body: "world",
URL: "https://example.com/comment/def",
ViewerCanUpdate: false,
},
},
opts: &forge.ListChangeCommentsOptions{
CanUpdate: true,
},
wantBodies: []string{"hello"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
response := map[string]any{
"data": map[string]any{
"node": map[string]any{
"comments": map[string]any{
"pageInfo": map[string]any{
"hasNextPage": false,
},
"nodes": tt.give,
},
},
},
}

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
assert.NoError(t, enc.Encode(response))
}))
defer srv.Close()

repo, err := newRepository(
context.Background(), new(Forge),
"owner", "repo",
logtest.New(t),
githubv4.NewEnterpriseClient(srv.URL, nil),
"repoID",
)
require.NoError(t, err)

prID := PR{Number: 1, GQLID: "prID"}

ctx := context.Background()
var bodies []string
for comment, err := range repo.ListChangeComments(ctx, &prID, tt.opts) {
require.NoError(t, err)
bodies = append(bodies, comment.Body)
}

assert.Equal(t, tt.wantBodies, bodies)
})
}
}
5 changes: 5 additions & 0 deletions testdata/script/stack_submit_update_leave_draft.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ gs stack submit --dry-run
cmpenv stderr $WORK/golden/submit-dry-run.txt
! stderr 'draft' # draft status should not be changed

# dry-run: verify --dry-run *would* change draft status
gs stack submit --no-draft --dry-run
stderr 'WOULD update'
stderr 'set draft to false'

shamhub dump changes
cmpenvJSON stdout $WORK/golden/start.json

Expand Down

0 comments on commit a77ab2c

Please sign in to comment.