Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gh cache delete --all] Add --succeed-on-no-caches flag to return exit code 0 #10327

Merged
merged 12 commits into from
Feb 19, 2025

Conversation

iamazeem
Copy link
Contributor

Fixes #9897

@iamazeem iamazeem requested a review from a team as a code owner January 29, 2025 09:56
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Jan 29, 2025
Copy link
Contributor

@jtmcg jtmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @iamazeem! I've left a few comments throughout the code that I think we'll need to address before we ship this.

Additionally, I'd like to see some tests added to TestDeleteRun to cover these new code paths.

Copy link
Contributor

@jtmcg jtmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there 👍

I still think we're missing unit tests for TestDeleteRun. The tests you've added for NewCmdDelete don't actually test the internals of the command, as they are intercepted by the runF function.

I've gone ahead and opened a PR against your branch to demonstrate what I'm looking for. Notably, one of the tests I wrote is failing, which I think actually caught a case I hadn't considered before trying to write the tests 🥳 (Note: I did not fix the failure, yet, and figured that should be addressed here once that PR merges).

Let me know if you have any questions! And thanks again for all the work you've been putting into the cli lately 🙌

@iamazeem iamazeem requested a review from jtmcg February 6, 2025 07:43
@iamazeem
Copy link
Contributor Author

@jtmcg: Updated. Ready for review. Thanks!

Copy link
Member

@williammartin williammartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current Behaviour

➜  test-repo git:(feature) gh cache delete --all
X No caches to delete
➜  test-repo git:(feature) echo $?
1

Acceptance Criteria

Given I have no caches
When I run gh cache delete --all --succeed-on-no-caches
Then it exits 0

➜  test-repo git:(feature) ~/workspace/cli/bin/gh cache delete --all --succeed-on-no-caches
✓ No caches to delete
➜  test-repo git:(feature) echo $?
0

When I run gh cache delete <cache-id> --succeed-on-no-caches
Then I get an error that --succeed-on-no-caches can only be used in conjunction with --all

➜  test-repo git:(feature) ~/workspace/cli/bin/gh cache delete --succeed-on-no-caches
--succeed-on-no-caches must be used in conjunction with --all

Usage:  gh cache delete [<cache-id> | <cache-key> | --all] [flags]

Flags:
  -a, --all                          Delete all caches
      --succeed-on-no-caches --all   Return exit code 0 if no caches found. Must be used in conjunction with --all

LGTM thanks!

@williammartin
Copy link
Member

williammartin commented Feb 18, 2025

@jtmcg please re-review your requested changes.

@jtmcg
Copy link
Contributor

jtmcg commented Feb 18, 2025

@jtmcg please re-review your requested changes.

Damn, I had reviewed and had forgotten to push "submit review", so I had 2 comments in pending... It's a pretty straight-forward change, then we'll be good to go!

@iamazeem iamazeem requested a review from jtmcg February 19, 2025 05:25
@iamazeem
Copy link
Contributor Author

iamazeem commented Feb 19, 2025

@jtmcg: Updated PR for the non-TTY case also. Please review. Thanks!

Tests

$ go clean -testcache && go test ./pkg/cmd/cache/delete/...
ok  	github.com/cli/cli/v2/pkg/cmd/cache/delete	0.005s


# TTY
$ bin/gh cache delete --repo iamazeem/test --succeed-on-no-caches --all
✓ No caches to delete
$ echo $?
0


# non-TTY
$ bin/gh cache delete --repo iamazeem/test --succeed-on-no-caches --all | cat

Copy link
Contributor

@jtmcg jtmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@jtmcg jtmcg merged commit 5aa36de into cli:trunk Feb 19, 2025
9 checks passed
@iamazeem iamazeem deleted the 9897-gh-cache-delete-exit-code branch February 19, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add additional exit codes for gh cache delete --all
4 participants