diff --git a/testdata/script/branch_comment_add.txt b/testdata/script/branch_comment_add.txt new file mode 100644 index 000000000..e07135fb7 --- /dev/null +++ b/testdata/script/branch_comment_add.txt @@ -0,0 +1,37 @@ +# Post an inline comment immediately with 'branch comment add'. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add handler.go +gs bc -m 'Add handler' feature1 +gs branch submit --fill +stderr 'Created #' + +# post an inline comment immediately +gs branch comment add handler.go:5 -m 'This needs a context parameter.' +stderr 'Posted comment' + +-- repo/handler.go -- +package main + +import "fmt" + +func handle() { + fmt.Println("handling") +} diff --git a/testdata/script/branch_comment_edit_staged.txt b/testdata/script/branch_comment_edit_staged.txt new file mode 100644 index 000000000..9b9b85928 --- /dev/null +++ b/testdata/script/branch_comment_edit_staged.txt @@ -0,0 +1,43 @@ +# Edit a staged comment before submission. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add main.go +gs bc -m 'Add main' feature1 +gs branch submit --fill +stderr 'Created #' + +# stage a comment +gs branch comment stage main.go:3 -m 'Original comment.' +stderr 'Staged comment sc-1' + +# edit the staged comment with -m +gs branch comment edit sc-1 -m 'Updated comment.' +stderr 'Updated staged comment sc-1' + +# verify the edit took effect by listing staged +gs branch comment list --staged +stderr 'Updated comment' + +-- repo/main.go -- +package main + +func main() { + println("hello") +} diff --git a/testdata/script/branch_comment_list.txt b/testdata/script/branch_comment_list.txt new file mode 100644 index 000000000..047c6ee81 --- /dev/null +++ b/testdata/script/branch_comment_list.txt @@ -0,0 +1,46 @@ +# List comments on a change request. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add main.go +gs bc -m 'Add main' feature1 +gs branch submit --fill +stderr 'Created #' + +# add an inline comment so there is something to list +gs branch comment add main.go:3 -m 'Consider using a constant.' +stderr 'Posted comment' + +# list should show the comment +gs branch comment list +stderr 'Comments:' +stderr 'main.go:3' +stderr 'Consider using a constant' + +# list on a branch with no CR should say so +gs bc -m 'Another branch' feature2 +gs branch comment list +stderr 'No change request' + +-- repo/main.go -- +package main + +func main() { + println("hello") +} diff --git a/testdata/script/branch_comment_list_json.txt b/testdata/script/branch_comment_list_json.txt new file mode 100644 index 000000000..aa894d0e6 --- /dev/null +++ b/testdata/script/branch_comment_list_json.txt @@ -0,0 +1,63 @@ +# List comments on a change request with --json output. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add main.go +gs bc -m 'Add main' feature1 +gs branch submit --fill +stderr 'Created #' + +# add an inline comment so there is something to list +gs branch comment add main.go:3 -m 'Consider using a constant here because it would make the code much more maintainable and readable.' +stderr 'Posted comment' + +# --json should output NDJSON to stdout with forge comment +gs branch comment list --json +stdout '"kind":"forge"' +stdout '"body":"Consider using a constant here because it would make the code much more maintainable and readable."' +stdout '"path":"main.go"' +stdout '"line":3' +stdout '"status":"open"' + +# text mode shows the full body without truncation +gs branch comment list +stderr 'Consider using a constant here because it would make the code much more maintainable and readable.' + +# stage a comment +gs branch comment stage main.go:5 -m 'Add error handling here.' +stderr 'Staged comment' + +# --staged --json should include only staged comments +gs branch comment list --staged --json +cmpenvJSON stdout $WORK/golden/staged_only.json + +# --json without --staged includes both staged and forge +gs branch comment list --json +stdout '"kind":"staged"' +stdout '"kind":"forge"' + +-- repo/main.go -- +package main + +func main() { + println("hello") +} + +-- golden/staged_only.json -- +{"kind":"staged","id":"sc-1","path":"main.go","line":5,"body":"Add error handling here."} diff --git a/testdata/script/branch_comment_resolve.txt b/testdata/script/branch_comment_resolve.txt new file mode 100644 index 000000000..a0e5dbae4 --- /dev/null +++ b/testdata/script/branch_comment_resolve.txt @@ -0,0 +1,39 @@ +# Resolve and unresolve a review thread. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add util.go +gs bc -m 'Add util' feature1 +gs branch submit --fill +stderr 'Created #' + +# post an inline comment to create a thread +gs branch comment add util.go:3 -m 'Rename this function.' +stderr 'Posted comment' + +# get the thread ID from the list output +gs branch comment list +stderr 'thread-' + +-- repo/util.go -- +package main + +func doStuff() { + // stuff +} diff --git a/testdata/script/branch_comment_stage_submit.txt b/testdata/script/branch_comment_stage_submit.txt new file mode 100644 index 000000000..9b91ac240 --- /dev/null +++ b/testdata/script/branch_comment_stage_submit.txt @@ -0,0 +1,58 @@ +# Stage inline comments and submit them as a review. + +as 'Test ' +at '2024-04-05T16:40:32Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +# set up a fake GitHub remote +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# create a branch with a file and submit it +git add feature.go +gs bc -m 'Add feature' feature1 +gs branch submit --fill +stderr 'Created #' + +# stage a comment on the file +gs branch comment stage feature.go:3 -m 'Consider renaming this function.' +stderr 'Staged comment sc-1 on feature.go:3' + +# stage another comment +gs branch comment stage feature.go:7 -m 'Add error handling here.' +stderr 'Staged comment sc-2 on feature.go:7' + +# list staged comments +gs branch comment list --staged +stderr 'sc-1' +stderr 'feature.go:3' +stderr 'sc-2' +stderr 'feature.go:7' + +# submit staged comments as a review +gs branch comment submit-staged +stderr 'Submitted 2 comment' + +# staged comments should be cleared after submit +gs branch comment list --staged +stderr 'No staged comments' + +-- repo/feature.go -- +package main + +func doWork() { + // does some work +} + +func handleRequest() { + // handles a request +}