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 PullRequestResource functionality for updating labels and comments. #895

Merged
merged 1 commit into from
Jun 19, 2019

Conversation

wlynch
Copy link
Member

@wlynch wlynch commented May 22, 2019

Changes

Add PullRequestResource functionality for updating labels and comments.

Missing from this change:

  • Statuses, since this might involve more discussion on the set of statuses
    that we want to support.
  • Updating from changes to the raw payloads. Unclear how we want to
    handle these at the moment. Punting on this for now.

First step for supporting #778.

This takes over initial work done by @dlorenc in #779

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

Release Notes

Includes label and comment support for GitHub Pull Request CRD.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that 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 here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 22, 2019
@wlynch
Copy link
Member Author

wlynch commented May 22, 2019

/assign @dlorenc

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

This is looking great!! I am so excited to have this and be able to start using it for our own CI :D :D :D 🤞

  • I love the fake github that you use to test the github image! I'd also like to see some unit test coverage here too if possible (the tests you've currently got are a kind of "integration test" in my opinion since they test the functionality as a whole)
  • I think you need to update resource_types.go as well https://github.com/tektoncd/pipeline/blob/ffbb67959dec0abb0f07b1d456398a99531d89f8/pkg/apis/pipeline/v1alpha1/resource_types.go
  • I'm a bit confused about why we're including labels - I thought we were going to leave them out of scope for now based on the design doc (and cuz systems like bitbucket don't have them?) - np tho if we decided otherwise, I know folks like @vdemeester have really been wanting some automation around labels in our own workflows, so maybe thats important enough that we included it even if bitbucket doesn't support it?

Before we merge this can you also include:

/meow space

cmd/pullrequest-init/README.md Show resolved Hide resolved
cmd/pullrequest-init/fake_github.go Show resolved Hide resolved
}

func (g *FakeGitHub) getPullRequest(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(mux.Vars(r)["number"], 10, 64)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what mux.Vars all about? I tried looking at the docs for the function but I still don't quite understand what's happening here :(

Copy link
Member Author

Choose a reason for hiding this comment

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

It's how you extract path variables with mux. See https://www.gorillatoolkit.org/pkg/mux

cmd/pullrequest-init/fake_github.go Show resolved Hide resolved
// NewGitHubHandler initializes a new handler for interacting with GitHub
// resources.
func NewGitHubHandler(ctx context.Context, logger *zap.SugaredLogger, rawURL string) (*GitHubHandler, error) {
token := strings.TrimSpace(os.Getenv("GITHUBOAUTHTOKEN"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm where does GITHUBOAUTHTOKEN come from? maybe it could be mentioned in the README? (what will be setting this?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's passed in as an environment variable from the generated Container spec. Added a note in the README.

Name string `json:"name"`
Type PipelineResourceType `json:"type"`
URL string `json:"url"`
GithubOauthToken string `json:"githubOauthToken"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the plan to support more than just oauth token based auth? (disclaimer: i dont know what im talking about 😅 )

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I would like to support GitHub Apps at some point in the future. TBD how we're going to do this (I need to read more about how k8s secret management and access works).

}

// GetParams returns the resource params
func (s PullRequestResource) GetParams() []Param { return []Param{} }
Copy link
Collaborator

Choose a reason for hiding this comment

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

im confused about why GetParams exists when every instance of this interface returns an empty list 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know the answer to this one. =\

Let's raise an issue to see if there was a reason for this?

Copy link
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Member

Choose a reason for hiding this comment

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

yep, @wlynch did you create an issue already ?

Copy link
Member Author

Choose a reason for hiding this comment

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

pkg/apis/pipeline/v1alpha1/pull_request_resource.go Outdated Show resolved Hide resolved
evs := []corev1.EnvVar{}
for _, sec := range s.Secrets {
switch {
case strings.EqualFold(sec.FieldName, "githubOauthToken"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are secrets only added if they have this particular name? (maybe im misunderstanding!)

Copy link
Member Author

Choose a reason for hiding this comment

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

The thought was to pull the value of the token from any (secret name, secret key). We use the FieldName to denote which secret should be used for this so that you can define your k8s with whatever name/key you want and set it in the ResourceSpec with the specified name.

No idea if this is the right way to go about doing this. If there is a better way somewhere else let me know!

Added this to the documentation.

@tekton-robot
Copy link
Collaborator

@bobcatfish: cat image

In response to this:

This is looking great!! I am so excited to have this and be able to start using it for our own CI :D :D :D 🤞

Before we merge this can you also include:

/meow space

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.

@bobcatfish
Copy link
Collaborator

(p.s. sorry this took me 9 days to get to, should have faster turnaround now :D!)

@bobcatfish
Copy link
Collaborator

image

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Looking good, just a few questions

// NewGitHubHandler initializes a new handler for interacting with GitHub
// resources.
func NewGitHubHandler(ctx context.Context, logger *zap.SugaredLogger, rawURL string) (*GitHubHandler, error) {
token := strings.TrimSpace(os.Getenv("GITHUBTOKEN"))
Copy link
Member

Choose a reason for hiding this comment

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

Might be good for a follow-up/enhancement and not as part of this PR but, shouldn't we support using secrets for that instead 👼

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. We're loosely using secrets here, but I'm sure there's better practices that we could be following. If you have any examples I can reference, please send them my way!

t.Errorf("Raw PR path: want [%s], got [%s]", rawCommentPath, gotPR.Comments[0].Raw)
}

// Upload
Copy link
Member

Choose a reason for hiding this comment

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

I originally wanted to do this, but I found that the easiest way to test Upload was to call Download, modify the result of download, then upload. Since a lot of the setup (i.e. populating the fake GitHub server) ends up being duplicative, it seemed simpler to test them together.

The setup for upload could be "hard-coded" file(s) instead of doing Download right ? (that said it might be as long of a setup as calling Download 😅 )

t.Fatal(err)
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("PR Diff: %s", diff)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we are using -got +wanted: %s elsewhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it's -want +got, but done.


switch *mode {
case "download":
logger.Info("RUNNING DOWNLOAD!")
Copy link
Member

Choose a reason for hiding this comment

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

🙀 😝

logger.Fatal(err)
}
case "upload":
logger.Info("RUNNING UPLOAD!")
Copy link
Member

Choose a reason for hiding this comment

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

🙀 😜

- A `Task`'s output can be your application container image which can be then
deployed in a cluster.
- A `Task`'s output can be a jar file to be uploaded to a storage bucket.
- A `Task`'s input could be a GitHub source which contains your application
Copy link
Member

Choose a reason for hiding this comment

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

nit: extra spaces 😅 (sorry 🙇‍♂️)

}

// GetParams returns the resource params
func (s PullRequestResource) GetParams() []Param { return []Param{} }
Copy link
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Looking great! Looks like from my perspective there are 2 main remaining issues:

  1. Secrets - @vdemeester has some feedback here and I am just generally confused about when we want to use secrets vs. service accounts but you can probably just ignore me and listen to whatever he has to say
  2. Unit test coverage for the binary itself. It looks like I cant reply to your original comment @wlynch cuz it was on code that is changed so here are my thoughts:

This brings up the common debate of individual unit vs integration style tests. The argument for the integration style with an in-memory fake is to write tests closer to the perspective of the user.

I think both styles of tests are super useful, but relying only on integration tests for coverage i think loses one of the biggest strengths of unit tests: they force us to design our code well.

when you have to write unit tests for individual functions, you have to think more about the signatures.

if the unit tests you end up writing are ugly and hard to deal with, there's a good chance that there is something that can be improved or cleaned up in the abstraction you've created through the functions themselves

These arguably have the same coverage as individual unit tests, and are less brittle to changes for how we structure Upload/Downloads (e.g. with fine-grained unit tests we will need to modify tests for any refactoring work vs with coarse integration style unit tests we do not so long as the Upload/Download interface does not change).

I actually think having to change the tests when you change the code is an advantage. when code changes but tests dont change its hard to know if the changes are doing what they were intended to: unit tests come as close as you can get to providing a "proof" that your changes are going in as expected.

like you said i think it's valuable to have tests a level or two up (integration and end to end) to give you that reassurance that the user facing functionality is working, so i wouldnt say dont write the integration tests, but i am saying still write the unit tests :D

I am now going to shame{less/ful}ly plug my own talk on this very topic: Testing CRDs <-- high recommend the sources slide, particularly "integrated tests are a scam" :D

/meow


Adding the Pull Request resource as an output of a Task will update the source
control system with any changes made to the pull request resource during the
pipeline.
Copy link
Collaborator

Choose a reason for hiding this comment

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

aaaamazing 🎉

control system with any changes made to the pull request resource during the
pipeline.

See [types.go](cmd/pullrequest-init/types.go) for the full payload spec.
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm we usually don't link to source code like this for the spec 🤔 maybe we could link to generated go-docs? (i dont see any other cmd info at https://godoc.org/github.com/tektoncd/pipeline tho 🤔 )

in most of our other docs we duplicate this information which i personally think is worth it even if it can be out of date, cuz its way easier to read, e.g. https://github.com/tektoncd/pipeline/blob/master/docs/tasks.md#syntax

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with sample payload.

Copy link
Collaborator

Choose a reason for hiding this comment

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

tfw the person goes along with your request and you feel you have maybe gone too far XD

jk jk I think this is probably good to have :D

secrets:
- fieldName: githubToken
secretName: github-secrets
secretKey: token
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm do we have any idea where we draw the line between when we use the service account attached to the task and when we want ppl to specify secrets @vdemeester @wlynch ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is something I want to look into more, particularly when we start looking at GitHub Apps. For now this is probably fine. But a good target for a follow up change.

Copy link
Member

Choose a reason for hiding this comment

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

agreeing with @wlynch we can do a follow-up 👼

- Manifest indicates that resource should be fetched using a source
manifest file.
- If `artifactType` is set to `Manifest`, `location` should point to a
source manifest file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm was all this whitespace changing intentionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The standard Google mdformat did this. =\

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah kk 😅 I'm sure @mattmoor-sockpuppet will have something to say about it XD

URL string `json:"url"`
GithubOauthToken string `json:"githubOauthToken"`
//Secrets holds a struct to indicate a field name and corresponding secret name to populate it
Secrets []SecretParam `json:"secrets"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

i have a feeling that Type is being used to inspect PipelineResources without having to use introspection to see specifically what type of resource it is (e.g. if you have a list of PipelineResources ) - but looking for usages might help clear that up (unless it isnt used?)

Name i think is the name of the resource, like wizzbang-git in this example

(or if im totally wrong then i have no idea what they are either)

@tektoncd tektoncd deleted a comment from tekton-robot Jun 5, 2019
@bobcatfish
Copy link
Collaborator

/meow

@tekton-robot
Copy link
Collaborator

@bobcatfish: cat image

In response to this:

/meow

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.

@bobcatfish
Copy link
Collaborator

Amaaaazing thanks for trying this out @afrittoli and for the insightful feedback!!! (And the cool demo today!)

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that 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 here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit labels Jun 19, 2019
Missing from this change:
* Statuses, since this might involve more discussion on the set of statuses
  that we want to support.
* Updating from changes to the raw payloads. Unclear how we want to
  handle these at the moment. Punting on this for now.

First step for supporting tektoncd#778.

Co-authored-by: Dan Lorenc <lorenc.d@gmail.com>
Co-authored-by: Billy Lynch <wlynch@google.com>
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

looking great! after the commits get squashed i am happy to approve + merge!

🎉🎉🎉

(and then very excited to start using it... haha :D)

want := []*github.IssueComment{comment2, comment3}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("-want +got: %v", diff)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice unit tests!! 😎

@bobcatfish bobcatfish added cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit and removed cla: no labels Jun 19, 2019
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@bobcatfish
Copy link
Collaborator

Manually resolved CLA issue, the commit is co-authored by @dlorenc and @wlynch both from Google

@bobcatfish
Copy link
Collaborator

/approve
/lgtm
/meow space

@tekton-robot
Copy link
Collaborator

@bobcatfish: cat image

In response to this:

/approve
/lgtm
/meow space

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.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 19, 2019
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bobcatfish, wlynch

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 19, 2019
@tekton-robot tekton-robot merged commit 98000b4 into tektoncd:master Jun 19, 2019
@bobcatfish
Copy link
Collaborator

wooooot

🎉

wlynch added a commit to wlynch/pipeline that referenced this pull request Jun 20, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies tektoncd#778 and tektoncd#895 to complete initial Pull Request support
support for GitHub OAuth.
wlynch added a commit to wlynch/pipeline that referenced this pull request Jun 20, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies tektoncd#778 and tektoncd#895 to complete initial Pull Request support
support for GitHub OAuth.
wlynch added a commit to wlynch/pipeline that referenced this pull request Jun 20, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies tektoncd#778 and tektoncd#895 to complete initial Pull Request support
support for GitHub OAuth.
wlynch added a commit to wlynch/pipeline that referenced this pull request Jul 2, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies tektoncd#778 and tektoncd#895 to complete initial Pull Request support
support for GitHub OAuth.
wlynch added a commit to wlynch/pipeline that referenced this pull request Jul 2, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies tektoncd#778 and tektoncd#895 to complete initial Pull Request support
support for GitHub OAuth.
tekton-robot pushed a commit that referenced this pull request Jul 3, 2019
This adds support for the GitHub Status API
(https://developer.github.com/v3/repos/statuses/).

This accompanies #778 and #895 to complete initial Pull Request support
support for GitHub OAuth.
@vdemeester vdemeester mentioned this pull request Jul 9, 2019
3 tasks
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants