Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

feat(cmd/issue/update): add --public and --confidential flags #396

Merged
merged 1 commit into from
Dec 23, 2020
Merged

feat(cmd/issue/update): add --public and --confidential flags #396

merged 1 commit into from
Dec 23, 2020

Conversation

maxice8
Copy link
Collaborator

@maxice8 maxice8 commented Dec 23, 2020

Description

they allow making an issue public or confidential, as documented by
GitLab here1 and in their API2 (see confidential field)

Related Issue

Resolves #395

How Has This Been Tested?
Tested against the usecase presented in #395

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)

Copy link
Owner

@profclems profclems left a comment

Choose a reason for hiding this comment

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

Thanks @maxice8

commands/issue/update/issue_update.go Outdated Show resolved Hide resolved
commands/issue/update/issue_update.go Outdated Show resolved Hide resolved
@maxice8
Copy link
Collaborator Author

maxice8 commented Dec 23, 2020

Is there some documentation on how to add flags ? In agl I just have --confidential which is a string that can take {yes|no}, same with --discussion={locked|unlocked}

@profclems
Copy link
Owner

In agl I just have --confidential which is a string that can take {yes|no}, same with --discussion={locked|unlocked}

Cobra doesn't have any built-in function to restrict flag values so you would have to validate it yourself.
Have a look at this issue spf13/cobra#1006

@profclems profclems added cmd: issue Related to issues management enhancement New feature or request labels Dec 23, 2020
@maxice8
Copy link
Collaborator Author

maxice8 commented Dec 23, 2020

In agl I just have --confidential which is a string that can take {yes|no}, same with --discussion={locked|unlocked}

Cobra doesn't have any built-in function to restrict flag values so you would have to validate it yourself.
Have a look at this issue spf13/cobra#1006

Yes, in agl I just check with switch case for the correct values and never allow them to be passed wrongly, here I decided to let one override the other.

If one passes --confidential and --public then we err on the side of safety and --confidential will override --public

This is expressed in the code by the logic for the flag that can override being later so the condition for --public can set l.Confidentiality = gitlab.Bool(false) but it won't matter because the logic for --confidential will trigger later and l.Confidentiality = gitlab.Bool(true)


What I actually mean is there a guideline on new flags ? Should we have different --public and --confidential flags that act on the same attribute of a GitLab object ?

@profclems
Copy link
Owner

What I actually mean is there a guideline on new flags ? Should we have different --public and --confidential flags that act on the same attribute of a GitLab object ?

You can but you should throw an error when both flags are specified. You can do this check

if cmd.Flags().Changed("confidential") && cmd.Flags().Changed("public") {
	return &cmdutil.FlagError{Err: errors.New("specify either of --public or --confidential")}
}

Sorry, I think I approved this too soon. This check should be added instead of having one override the other. This should be safe.

@maxice8
Copy link
Collaborator Author

maxice8 commented Dec 23, 2020

image

they allow making an issue public or confidential, as documented by
GitLab here[1] and in their API[2] (see confidential field)

[1]: https://docs.gitlab.com/ee/user/project/issues/confidential_issues.html
[2]: https://docs.gitlab.com/ee/api/issues.html#edit-issue
@profclems profclems merged commit 4d2b2c0 into profclems:trunk Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cmd: issue Related to issues management enhancement New feature or request size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow making an issue confidential/public
2 participants