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

Add support for SPDX style headers #79

Merged
merged 2 commits into from
Jul 27, 2021
Merged

Add support for SPDX style headers #79

merged 2 commits into from
Jul 27, 2021

Conversation

willnorris
Copy link
Collaborator

This PR implements the changes described in #77 (comment). This contains two commits, which might be easier to review individually. The first is just a refactor and slight cleanup of existing code with no change in behavior. These changes make it easier to add SPDX support as well as begin to decouple certain logic to make testing simpler. The second commit actually adds support for SPDX headers as discussed in #77.

Closes #77

willnorris and others added 2 commits July 26, 2021 19:38
Move the logic for selecting a license template based on user input into
a standalone func (fetchTemplate), and add test cases for all code
paths.

Delay parsing predefined license templates. This allows the new
fetchTemplate method to modify these templates before returning in the
future (to add SPDX license information).  Add tests to ensure that
these templates must always parse properly.

Rename copyrightData type to licenseData, since we will soon begin to
add more than just copyright data here (SPDX ID).

Rename prefix func to executeTemplate, since this better describes what
the function is doing.

These are all refactoring and cleanup changes; no behavioral changes.
This adds a new "-s" flag that will append an SPDX-License-Identifier
line to license headers.  If "-s=only" is specified, then only the SPDX
identifier will be used.

This also changes the "-l" flag to use SPDX identifiers, with mappings
to support the legacy "apache", "mit", and "mpl" values.  Together with
the "-s" flag, this allows SPDX headers for any arbitrary license type
to be added to files.

Co-authored-by: Bob Callaway <[email protected]>
@google-cla
Copy link

google-cla bot commented Jul 27, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@willnorris
Copy link
Collaborator Author

@bobcallaway, see the comment from @google-cla above. Because I listed you as a co-author on one of the commits, you'll need to explicitly consent to submitting this change, even though you've already signed the CLA.

@willnorris
Copy link
Collaborator Author

cc @mco-gh for review

fmt.Fprintln(os.Stderr, helpText)
flag.PrintDefaults()
}
flag.Var(&skipExtensionFlags, "skip", "To skip files to check/add the header file, for example: -skip rb -skip go")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these two flag.Var lines go in the var block above where the other flags are defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, custom flag parsing using flag.Var can't be done at initialization time in a var block. Same for the other *Var funcs, flag.StringVar, flag.IntVar, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, makes sense

@bobcallaway
Copy link
Contributor

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented Jul 27, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Copy link
Contributor

@mco-gh mco-gh left a comment

Choose a reason for hiding this comment

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

thanks Will!

@mco-gh mco-gh merged commit 8746277 into google:master Jul 27, 2021
@mco-gh
Copy link
Contributor

mco-gh commented Jul 27, 2021 via email

@willnorris
Copy link
Collaborator Author

My next PR will be to migrate CI over to GitHub Actions, setup better linting, etc :)

@willnorris willnorris deleted the spdx branch July 27, 2021 19:26
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.

3 participants