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

🐛 fix copyright info when has not a owner set #1749

Merged
merged 1 commit into from Oct 30, 2020

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Oct 28, 2020

Description
Ensure that the copyright will be set when the owner is empty with the year only.

Motivation
Closes: #1620

Local Test

$ cat main.go 
/*
Copyright 2020.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 28, 2020
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 28, 2020
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 28, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 28, 2020
@camilamacedo86 camilamacedo86 changed the title 🐛 fix copyright info when has not owner set WIP: 🐛 fix copyright info when has not owner set Oct 28, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 28, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 28, 2020
@camilamacedo86 camilamacedo86 changed the title WIP: 🐛 fix copyright info when has not owner set 🐛 fix copyright info when has not owner set Oct 28, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 28, 2020
@camilamacedo86 camilamacedo86 changed the title 🐛 fix copyright info when has not owner set 🐛 fix copyright info when has not a owner set Oct 28, 2020
@Adirio
Copy link
Contributor

Adirio commented Oct 29, 2020

I must say I don't like this new approach, as you are templating outside of the template itself. I prefered the other approach you had and by adding the dashes (-) I suggested the result would be the same but SetTemplateDefaults is left for setting defaults and the template is used for templating:

const none = `/*
{{ if .Owner -}}
Copyright {{ .Year }} {{ .Owner }}.
{{- else -}}
Copyright {{ .Year }}.
{{- end }}
*/`

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Oct 29, 2020

Hi @Adirio,

Regards #1749 (comment)
I prefer as it is done because the code shows more understandable. The need to {{- is not implicit. However, both solutions are valid and I do not see a reason to block the fix because it is done in one way or another.

@Adirio
Copy link
Contributor

Adirio commented Oct 29, 2020

Hi @camilamacedo86:

The usage of - is part of Go's template expecification, you can find the relevant documentation here. This pattern is used in more files over the scaffolds, it basically removes the preceding ({{-) or following (-}}) whitespaces, including new-lines.

With the approach you suggest, you are using the SetTemplateDefaults function to process part of the template, when that method is only meant to set defaults. Additionally, defaults are set at the start and templating is done at the end, in the middle some fields, for example Author may change. In that case, as you templated the copyright before, the author change would not be reflected into the scaffolded file, which would have the initial Author even if I modified it. As another tiny detail, the previous approach ({{- else -}}) requires less modifications to the current behavior (8 loc modified vs 36).

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 30, 2020
@camilamacedo86
Copy link
Member Author

Hi @Adirio,

Done as you suggested.

Copy link
Contributor

@Adirio Adirio left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Adirio, camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

License comments would leave two lines blanks if not specify author
3 participants