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

expose labels Application Creation Option to cli #271

Merged
merged 11 commits into from
Apr 7, 2022

Conversation

noam-codefresh
Copy link
Collaborator

also - extract git commit author information from token (for github/gitlab/gitea). fallback to using global gitconfig data in azure devops.

@noam-codefresh noam-codefresh self-assigned this Apr 6, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #271 (38f64a4) into main (0b05d00) will decrease coverage by 0.51%.
The diff coverage is 65.16%.

@@            Coverage Diff             @@
##             main     #271      +/-   ##
==========================================
- Coverage   61.67%   61.15%   -0.52%     
==========================================
  Files          17       17              
  Lines        2894     2984      +90     
==========================================
+ Hits         1785     1825      +40     
- Misses       1016     1060      +44     
- Partials       93       99       +6     
Impacted Files Coverage Δ
cmd/commands/repo.go 61.64% <0.00%> (ø)
pkg/application/application.go 61.98% <0.00%> (-0.19%) ⬇️
pkg/git/provider.go 68.42% <ø> (-31.58%) ⬇️
cmd/commands/project.go 48.32% <20.00%> (-0.63%) ⬇️
pkg/git/provider_github.go 68.57% <40.90%> (-10.28%) ⬇️
pkg/git/provider_gitlab.go 61.33% <54.54%> (-7.09%) ⬇️
pkg/git/provider_gitea.go 61.81% <61.53%> (-8.78%) ⬇️
pkg/git/provider_ado.go 61.66% <70.00%> (-3.86%) ⬇️
pkg/git/repository.go 81.50% <92.85%> (+0.78%) ⬆️
cmd/commands/app.go 44.90% <100.00%> (+0.14%) ⬆️
... and 7 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@@ -114,6 +114,7 @@ func AddFlags(cmd *cobra.Command) *CreateOptions {
cmd.Flags().StringVar(&opts.DestNamespace, "dest-namespace", "", "K8s target namespace (overrides the namespace specified in the kustomization.yaml)")
cmd.Flags().StringVar(&opts.InstallationMode, "installation-mode", InstallationModeNormal, "One of: normal|flat. "+
"If flat, will commit the application manifests (after running kustomize build), otherwise will commit the kustomization.yaml")
cmd.Flags().StringToStringVar(&opts.Labels, "labels", nil, "Optional labels that will be set on the Application resource. (e.g. \"{{ placeholder }}=my-org\"")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand the example here, the (e.g. \"{{ placeholder }}=my-org\" part. Which probably means no one will understand it. We need to think of a better way to explain or to just drop the explanation here and leave it for the docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, you are right. i'll add a special md file to document how to use labels in project create and then in app create.

@@ -63,9 +64,11 @@ type (
url string
Copy link
Contributor

Choose a reason for hiding this comment

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

lets separate the public and private props with one blank line, just so it's easier to understand.

var h plumbing.Hash

cfg, err := r.ConfigScoped(config.SystemScope)
author, err := r.getAuthor(ctx, opts.Provider)
Copy link
Contributor

Choose a reason for hiding this comment

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

passing opts.Provider here does nothing since you already have your provider instance on opts.provider

func (r *repo) getAuthor(ctx context.Context, providerType string) (*object.Signature, error) {
username, email, err := r.provider.GetAuthor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get commiter data. Error: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

commiter -> committer

Copy link
Contributor

Choose a reason for hiding this comment

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

Usually you should not do: fmt.Errorf("something. Error: %w") you just do fmt.Errorf("something: %w", err).

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we fail to commit if we don't get the author from the provider? Does it make sense the a provider will not return an error but will have an empty username/email?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

currently, github/gitlab/gitea should all return valid username/email from the token (or fail with an error).
but in ado, it just returns "", "", nil, and then the user will get the message about missing information in git config file, because this will be the only way they can get it to work.

}

if username == "" || email == "" {
return nil, fmt.Errorf("failed to get author data. Please make sure your gitconfig contains a name and an email")
Copy link
Contributor

Choose a reason for hiding this comment

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

"failed to get author data" -> "missing required author information in git config, make sure your git config contains a 'user.name' and 'user.email'"


if cfg.User.Name == "" || cfg.User.Email == "" {
return nil, fmt.Errorf("failed to commit. Please make sure your gitconfig contains a name and an email")
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt.Errorf("failed to get author information: %w", err)

@noam-codefresh noam-codefresh merged commit ca1b7a6 into argoproj-labs:main Apr 7, 2022
@noam-codefresh noam-codefresh deleted the labels_flag branch April 7, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants