-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
prow: size plugin #3847
prow: size plugin #3847
Conversation
Hi @nlandolfi. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
At this stage, the PR contains the main logic. It has a few TODOs in places, some where I'd be curious for feedback. It lacks test cases for the |
/ok-to-test |
prow/plugins/size/gen_files_group.go
Outdated
// Use load to read a generated files config file, and populate g with the commands. | ||
// "paths-from-repo" commands are aggregated into repoPaths. It is the caller's | ||
// responsiblity to fetch these and load them via g.loadPaths. | ||
func (g *GenFilesGroup) load(r io.Reader) (repoPaths []string, parseErrs []*ParseError, err *IOError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just return one error
. Users of the library can do a type assertion if they care what kind of error it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so should it be a list of []error? The catch is that if there is a parse error...and we continue parsing despite it, we could run into another parse error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err: a slice of errors, i.e., []error
prow/plugins/size/gen_files_group.go
Outdated
} | ||
|
||
// IOError is related to reading or writing bytes. | ||
type IOError struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably unnecessary. We can just assume that if it's not a ParseError
then it's something to worry about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// Check g.FileNames | ||
|
||
if got, want := len(g.FileNames), len(c.want.FileNames); got != want { | ||
t.Logf("g.FileNames: got %v, want %v", g.FileNames, c.want.FileNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the extra log line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
|
||
// Check g.FileNames | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra newlines here and the others as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
prow/plugins/size/pr.go
Outdated
@@ -0,0 +1,101 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the contents of both this file and "plugin.go" into one file called "size.go".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
prow/plugins/size/pr.go
Outdated
) | ||
|
||
// Ignore parseErrors, best effort despite invalid lines in config. | ||
g, _, err := NewGenFilesGroup(gc, owner, repo, sha) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the logger's Warning
method to indicate something that's probably wrong but not on Prow's side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of returning the error, or in addition to returning it?
prow/plugins/size/pr.go
Outdated
count += change.Additions + change.Deletions | ||
} | ||
|
||
labels, err := gc.GetIssueLabels(owner, repo, num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these contained in the PullRequestEvent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do not appear to be contained here. even tho the structure is massive
@@ -0,0 +1,5 @@ | |||
# first 30 lines of kubernetes/docs/.generated_docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In go it's normal to call this folder testdata
instead of test-fixtures
. Various go tools are smart about that name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/lint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spxtr: 14 warnings.
In response to this:
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
prow/plugins/size/plugin.go
Outdated
limitations under the License. | ||
*/ | ||
|
||
package size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: should have a package comment, unless it's in another file for this package. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
prow/plugins/size/pr.go
Outdated
} | ||
|
||
if err := gc.AddLabel(owner, repo, num, newLabel); err != nil { | ||
return fmt.Errorf("AddLabel error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint errors: error strings should not be capitalized or end with punctuation or a newline. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore this.
prow/plugins/size/pr.go
Outdated
limitations under the License. | ||
*/ | ||
|
||
package size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: should have a package comment, unless it's in another file for this package. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
prow/plugins/size/pr.go
Outdated
|
||
changes, err := gc.GetPullRequestChanges(owner, repo, num) | ||
if err != nil { | ||
return fmt.Errorf("GetPullRequestChanges error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint errors: error strings should not be capitalized or end with punctuation or a newline. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
prow/plugins/size/pr.go
Outdated
labels, err := gc.GetIssueLabels(owner, repo, num) | ||
if err != nil { | ||
// TODO(nlandolfi): should probably continue anyway, to at least try to add label? | ||
return fmt.Errorf("GetIssueLabels error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint errors: error strings should not be capitalized or end with punctuation or a newline. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
prow/plugins/size/size.go
Outdated
limitations under the License. | ||
*/ | ||
|
||
package size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: should have a package comment, unless it's in another file for this package. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
prow/plugins/size/size.go
Outdated
|
||
package size | ||
|
||
// One of a discrete buckets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: comment on exported type Size should be of the form "Size ..." (with optional leading article). More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexport this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
limitations under the License. | ||
*/ | ||
|
||
package size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: should have a package comment, unless it's in another file for this package. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
prow/plugins/size/gen_files_group.go
Outdated
var bs []byte | ||
bs, err = gc.GetFile(owner, repo, genConfigFile, sha) | ||
if err != nil { | ||
err = &IOError{err: fmt.Errorf("GetFile error: %v", err)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint errors: error strings should not be capitalized or end with punctuation or a newline. More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plan to kill this error type anyway
prow/plugins/size/gen_files_group.go
Outdated
return nil | ||
} | ||
|
||
// Use Match to determine whether a file, given here by its full path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: comment on exported method GenFilesGroup.Match should be of the form "Match ...". More info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k done.
@Kargakis joe mentioned you might be able to take a look at this while he was away -- if so that would be great, if you don't have time no worries :) ! |
prow/github/client.go
Outdated
} | ||
|
||
decoded, err := base64.StdEncoding.DecodeString(res.Content) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kill this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
prow/plugins/size/gen_files_group.go
Outdated
return g, nil | ||
default: | ||
err = fmt.Errorf("GetFile error: %v", err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely a personal taste, but I think it's better to always use return arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya i actually agree will rework this.
prow/plugins/size/gen_files_group.go
Outdated
"k8s.io/test-infra/prow/github" | ||
) | ||
|
||
const genConfigFile = ".generated_files" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this file come from? Can you add a comment explaining its utility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to also include an example of this file's content - you already have one in the unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i'll take some of the language from the issue I wrote describing the file spec cause it'd be nice to have that near the code i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
src: `# Files that should be ignored by tools which do not want to consider generated | ||
# code. | ||
# | ||
# https://github.com/kubernetes/contrib/blob/master/mungegithub/mungers/size.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link is dead now. s/contrib/test-infra/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k should we file an issue about it in kubernetes/kubernetes here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can even just open a pr for kubernetes/kubernetes if it needs to be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing it in kubernetes is fine but a separate issue. This is just a unit test.
prow/plugins/size/size.go
Outdated
|
||
changes, err := gc.GetPullRequestChanges(owner, repo, num) | ||
if err != nil { | ||
return fmt.Errorf("GetPullRequestChanges error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot get PR changes for size plugin: %v
{path: "generated.txt", match: true}, | ||
{path: "/any/old/path/generated.txt", match: true}, | ||
{path: "/everywhere/generated.txt", match: true}, | ||
{path: "/and/nowhere/generated.txt", match: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a case where a filename does not match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call
|
||
labels, err := gc.GetIssueLabels(owner, repo, num) | ||
if err != nil { | ||
le.Warnf("while retrieving labels, error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that if you get an error here, you don't get to run any of the following code so you might as well return here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i add the label later around line 114 -- maybe should add the label first then remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddLabell will never be reached because if you get an error here, labels
is nil and hasLabel
stays false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, not sure why I thought it like that :) - actually AddLabel is run, yeah this is fine.
prow/plugins/size/size.go
Outdated
} | ||
|
||
if err := gc.AddLabel(owner, repo, num, newLabel); err != nil { | ||
return fmt.Errorf("AddLabel error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot add label in %s/%s PR #%d: %v ?
You also need to bump hook and squash the commits (big change but I am not sure how to bucket it more efficiently). |
done! |
prow/plugins/size/gen_files_group.go
Outdated
repoPaths = append(repoPaths, fs[1]) | ||
default: | ||
err = &ParseError{line: l} | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the return arguments here, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
"k8s.io/test-infra/prow/github" | ||
) | ||
|
||
// The ".generated_files" config lives in the repo's root. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
prow/plugins/size/gen_files_group.go
Outdated
// | ||
// The statement's `key` specifies the type of the corresponding value: | ||
// - "path": exact path to a single file | ||
// - "file-name": exact leaf file name, regardless of path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah some were tabs some were spaces, went to all spaces for this list.
prow/plugins/size/gen_files_group.go
Outdated
case *github.FileNotFound: | ||
return g, nil | ||
default: | ||
return nil, fmt.Errorf("GetFile error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could not get .generated_files: %v
Had a couple of minor comments but this is |
let me know if there is anything else on my end! |
@nlandolfi can you open an issue to replace the munger with the new plugin in the existing configs in test-infra? As far as the old code is concerned, I wouldn't kill it yet but I would open a separate issue for it, too. |
Still need to disable the munger and enable the plugin across all of kubernetes. |
Implement the size munger as a prow plugin.
Closes #3794, which also contains more context.
/area prow