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

Detect go files as generated according to official rules #4821

Conversation

ernestas2k
Copy link
Contributor

@ernestas2k ernestas2k commented Mar 12, 2020

Use officially accepted rules to detect golang generated files https://golang.org/s/generatedcode

Description

The rule dictates that a line matching ^// Code generated .* DO NOT EDIT\.$ can be anywhere in golang file.
I currently use github.com/deepmap/oapi-codegen that generates the following (valid according to the rules) file:

// Package api provides primitives to interact the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen DO NOT EDIT.
package api

// Error defines model for Error.
type Error struct {
...

Sample file for test taken from: https://github.com/deepmap/oapi-codegen/blob/master/examples/petstore-expanded/echo/api/petstore-types.gen.go
The project license (apache 2.0) https://github.com/deepmap/oapi-codegen/blob/master/LICENSE

Would be good to get such files ignored automatically by github when reviewing PRs.

This issue was raised and solved multiple times but wasn't merged.
Refs #3800 #2724

Checklist:

  • I am adding new or changing current functionality
    • I have added or updated the tests for the new or changed functionality.

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

Thanks for improving this!

lib/linguist/generated.rb Outdated Show resolved Hide resolved
lib/linguist/generated.rb Outdated Show resolved Hide resolved
@ernestas2k ernestas2k force-pushed the detect_go_files_as_generated_according_to_official_rules branch from 6a7e41a to 361bbc9 Compare March 14, 2020 12:58
Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @ernestas2k!

@lildude
Copy link
Member

lildude commented Mar 16, 2020

@ernestas2k Can you please add a note to the original post linking to the source of the sample file and the license it is covered by. Thanks.

@ernestas2k
Copy link
Contributor Author

ernestas2k commented Mar 16, 2020

@ernestas2k Can you please add a note to the original post linking to the source of the sample file and the license it is covered by. Thanks.

The sample file is generated (using the mentioned tool) and located in private repo of mine. Should I find public sample file instead? Like this one https://github.com/deepmap/oapi-codegen/blob/master/examples/petstore-expanded/echo/api/petstore-server.gen.go ?

@lildude
Copy link
Member

lildude commented Mar 16, 2020

@ernestas2k yes please. We need to be able to verify sources in case there are any licensing issues in future.

@pchaigno
Copy link
Contributor

@lildude Isn't posting here in a pull request the same as adding it to a public repository under a permissive license? I mean, it's literally what people are doing by posting here.

@lildude
Copy link
Member

lildude commented Mar 16, 2020

@pchaigno sort of. If the file isn't from a source with a verifiable open license, and the author isn't deemed "authoritative" at some point in the future by the owner of the code, it potentially opens GitHub up to legal battles.

I know this isn't the case now, but it's best and easier to be consistent across the board.

@lildude
Copy link
Member

lildude commented Mar 17, 2020

@ernestas2k if you're quick, I might just be able to squeeze this into the linguist release I'm currently testing.

@ernestas2k
Copy link
Contributor Author

@lildude ok just a moment

@ernestas2k ernestas2k force-pushed the detect_go_files_as_generated_according_to_official_rules branch from 361bbc9 to 9f13b06 Compare March 17, 2020 11:38
@ernestas2k
Copy link
Contributor Author

ernestas2k commented Mar 17, 2020

@lildude updated the PR code and the original post, let me know if any more changes would be valuable.

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

Thanks @ernestas2k 🙇

@lildude lildude merged commit f5125ea into github-linguist:master Mar 17, 2020
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants