Skip to content

feat: add recover option to issue create command

Jaime Martinez requested to merge 472-recover-mr-issue into main

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:

  1. Return an error early in commands/issue/create/issue_create.go#L362:

    return errors.New("fail on purpose")
  2. Build the binary with the deliberate error running make

  3. 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

  4. Once in the test location, use the glab binary that you built, e.g. /Users/jaime/dev/gitlab/cli/bin/glab

  5. Attempt to create an issue using the -recover flag and verify it fails

    glab 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
  6. 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":""}
  7. Undo the first step by removing the error in commands/issue/create/issue_create.go#L362

  8. Compile the binary again using make

  9. Try to create the issue again with the -recover flag

    glab 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
  10. 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)

Edited by Jaime Martinez

Merge request reports