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

prow: size plugin #3847

Merged
merged 1 commit into from
Aug 17, 2017
Merged

prow: size plugin #3847

merged 1 commit into from
Aug 17, 2017

Conversation

nlandolfi
Copy link
Contributor

Implement the size munger as a prow plugin.

Closes #3794, which also contains more context.

/area prow

@nlandolfi nlandolfi requested a review from spxtr as a code owner August 1, 2017 22:17
@k8s-ci-robot k8s-ci-robot added area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 1, 2017
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 1, 2017
@nlandolfi
Copy link
Contributor Author

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 handlePR function, which I will be adding shortly. But was curious to get early feedback since it's starting to get a bit large...

@crimsonfaith91
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 2, 2017
// 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

}

// IOError is related to reading or writing bytes.
type IOError struct {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}

// Check g.FileNames

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,101 @@
/*
Copy link
Contributor

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)

// Ignore parseErrors, best effort despite invalid lines in config.
g, _, err := NewGenFilesGroup(gc, owner, repo, sha)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

count += change.Additions + change.Deletions
}

labels, err := gc.GetIssueLabels(owner, repo, num)
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@spxtr
Copy link
Contributor

spxtr commented Aug 4, 2017

/lint

Copy link
Contributor

@k8s-ci-robot k8s-ci-robot left a 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.

limitations under the License.
*/

package size
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

if err := gc.AddLabel(owner, repo, num, newLabel); err != nil {
return fmt.Errorf("AddLabel error: %v", err)
Copy link
Contributor

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.

Copy link
Contributor

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.

limitations under the License.
*/

package size
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


changes, err := gc.GetPullRequestChanges(owner, repo, num)
if err != nil {
return fmt.Errorf("GetPullRequestChanges error: %v", err)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k

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)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k

limitations under the License.
*/

package size
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


package size

// One of a discrete buckets.
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unexport this.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k

var bs []byte
bs, err = gc.GetFile(owner, repo, genConfigFile, sha)
if err != nil {
err = &IOError{err: fmt.Errorf("GetFile error: %v", err)}
Copy link
Contributor

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.

Copy link
Contributor Author

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

return nil
}

// Use Match to determine whether a file, given here by its full path
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k done.

@nlandolfi
Copy link
Contributor Author

@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 :) !

}

decoded, err := base64.StdEncoding.DecodeString(res.Content)

Copy link
Contributor

Choose a reason for hiding this comment

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

Kill this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

return g, nil
default:
err = fmt.Errorf("GetFile error: %v", err)
return
Copy link
Contributor

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.

Copy link
Contributor Author

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.

"k8s.io/test-infra/prow/github"
)

const genConfigFile = ".generated_files"
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.

Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link
Contributor

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/

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

*?

Copy link
Contributor Author

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

Copy link
Contributor

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.


changes, err := gc.GetPullRequestChanges(owner, repo, num)
if err != nil {
return fmt.Errorf("GetPullRequestChanges error: %v", err)
Copy link
Contributor

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},
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

}

if err := gc.AddLabel(owner, repo, num, newLabel); err != nil {
return fmt.Errorf("AddLabel error: %v", err)
Copy link
Contributor

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 ?

@0xmichalis
Copy link
Contributor

You also need to bump hook and squash the commits (big change but I am not sure how to bucket it more efficiently).

@nlandolfi
Copy link
Contributor Author

done!

repoPaths = append(repoPaths, fs[1])
default:
err = &ParseError{line: l}
return
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

//
// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra whitespace

Copy link
Contributor Author

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.

case *github.FileNotFound:
return g, nil
default:
return nil, fmt.Errorf("GetFile error: %v", err)
Copy link
Contributor

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

@0xmichalis 0xmichalis changed the title [WIP] prow: size plugin prow: size plugin Aug 11, 2017
@0xmichalis
Copy link
Contributor

Had a couple of minor comments but this is
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 11, 2017
@nlandolfi
Copy link
Contributor Author

let me know if there is anything else on my end!

@0xmichalis 0xmichalis merged commit e9040c9 into kubernetes:master Aug 17, 2017
@0xmichalis
Copy link
Contributor

@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.

@spxtr
Copy link
Contributor

spxtr commented Aug 17, 2017

#4105 (comment)

@BenTheElder
Copy link
Member

@Kargakis spxtr enabled the plugin for test-infra in #4100 😄

@spxtr
Copy link
Contributor

spxtr commented Aug 18, 2017

Still need to disable the munger and enable the plugin across all of kubernetes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/prow Issues or PRs related to prow 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants