feat: add recover option to issue create command
Description
This MR introduces a -recover
flag as discussed in #472 (closed). The intent is to save the glab issue create [OPTIONS]
into a file if the creation fails.
If the file exists, we try to load the contents into the issue options and attempt to create the issue again.
Related Issues
Related to Friendlier recovery when issue/mr create fails (#472 - closed)
How has this been tested?
The easiest way to test locally is to force a failure before creating the issue with the API:
-
Return an error early in commands/issue/create/issue_create.go#L362:
return errors.New("fail on purpose")
-
Build the binary with the deliberate error running
make
-
Use a test project, I'm using https://gitlab.com/jaime/glab-cli-tests for my tests. Check it out locally and
cd
into the location -
Once in the test location, use the
glab
binary that you built, e.g./Users/jaime/dev/gitlab/cli/bin/glab
-
Attempt to create an issue using the
-recover
flag and verify it failsglab issue create -t "My issue" -d "Using recover function" --recover - Creating issue in jaime/glab-cli-tests Failed to create issue. Created recover file: /Users/jaime/.config/glab-cli/recover/jaime/glab-cli-tests/issue.json
-
Verify the file exists and contains the correct details
cat /Users/jaime/.config/glab-cli/recover/jaime/glab-cli-tests/issue.json {"title":"My issue","description":"Using recover function","issue_link_type":"relates_to","milestone_flag":""}
-
Undo the first step by removing the error in commands/issue/create/issue_create.go#L362
-
Compile the binary again using
make
-
Try to create the issue again with the
-recover
flagglab issue create -t "My issue" -d "Using recover function" --recover Recovered create options from file - Creating issue in jaime/glab-cli-tests #9 My issue (less than a minute ago) https://gitlab.com/jaime/glab-cli-tests/-/issues/9
-
Voila! Issue created and the recover file should have been removed
cat /Users/jaime/.config/glab-cli/recover/jaime/glab-cli-tests/issue.json cat: /Users/jaime/.config/glab-cli/recover/jaime/glab-cli-tests/issue.json: No such file or directory
Screenshots (if appropriate):
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms)
Closes #472 (closed)