-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters