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

Prompt: avoid resetting PR/issue metadata #2472

Merged
merged 6 commits into from
Dec 3, 2020

Conversation

cristiand391
Copy link
Contributor

@cristiand391 cristiand391 commented Nov 24, 2020

Fixes #2369
Fixes #2475

The current implementation of MetadataSurvey resets metadata provided by flags if no option is selected (press Enter without selecting anything) and when the user adds metadata in the prompt.
This happens because Survey doesn't return an error if you pass an empty slice of questions to it, so this check pass and state metadata fields are assigned to nil after that.

This PR contains the following changes:

  • Check if mqs is empty before sending it to survey
  • If mqs isn't empty, fill values with the values of state, that way it'll preserve metadata passed by flags.
  • Set state.MetadataResult to nil

This is needed because MetadataSurvey sets state.MetadataResult to the selected options here, but if the user doesn't select anything or adds metadata then AddMetadataToIssueParams fails the get the IDs. By setting it to nil it'll be properly filled here.

Demo:

gh-metadata

@cristiand391 cristiand391 changed the title Prompt: avoid resetting PR/issue metadata if no option is selected Prompt: avoid resetting PR/issue metadata Nov 25, 2020
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you for the fix; and good catch!

I noticed that there were not tests for this piece of logic. I do not fault you for not adding one, because it looks like making a test for this method is pretty hard. I will try to take over from this point. 🙇

}

state.MetadataResult = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

At first I wasn't clear why you did this, but then I tested it out and noticed that it fails in AddMetadataToIssueParams without this line.

I'm not convinced of this workaround, though, because it clears the cache of what was just fetched from the server and causes a whole bunch of records to be fetched again. I realize that fixing this properly is non-trivial, and I don't require that you add it to your PR. I'm currently exploring alternatives.

For metadata types chosen in interactive flow, we fetch all records from
the API in order to be able to display a multi-select interface.

For metadata defined via command-line flags, we resolve records that can
be looked up directly, avoiding fetching the entirety of expensive
datasets (e.g. all members of an organization) if we can.

The new approach ensures efficient fetching when interactive flow is
combined with values from flags.
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I've pushed changes to resolve the metadata fetching conflict and to make MetadataSurvey easier to test, so we at least have some coverage around the interactive flow.

@mislav mislav merged commit f415245 into cli:trunk Dec 3, 2020
@cristiand391 cristiand391 deleted the preserve-metadata-state branch December 3, 2020 19:42
Copy link

@chenguru860530 chenguru860530 left a comment

Choose a reason for hiding this comment

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

api/queries_repo.go

@chenguru860530
Copy link

api/queries_repo.go

Copy link

@pes2020kk pes2020kk left a comment

Choose a reason for hiding this comment

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

ios

kobk372 pushed a commit to kobk372/cli that referenced this pull request Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants