diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 5aacc36f247..549c0483f4a 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -73,7 +73,6 @@ func main() { flag.StringVar(&opts.Images.ShellImage, "shell-image", "", "The container image containing a shell") flag.StringVar(&opts.Images.ShellImageWin, "shell-image-win", "", "The container image containing a windows shell") flag.StringVar(&opts.Images.GsutilImage, "gsutil-image", "", "The container image containing gsutil") - flag.StringVar(&opts.Images.PRImage, "pr-image", "", "The container image containing our PR binary.") flag.StringVar(&opts.Images.ImageDigestExporterImage, "imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.") flag.StringVar(&opts.Images.WorkingDirInitImage, "workingdirinit-image", "", "The container image containing our working dir init binary.") diff --git a/cmd/pullrequest-init/README.md b/cmd/pullrequest-init/README.md deleted file mode 100644 index 5699ba1ead4..00000000000 --- a/cmd/pullrequest-init/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# pullrequest-init - -pullrequest-init fetches pull request data from the given URL and places it in -the provided path. - -This binary outputs a generic pull request object into a set of generic files, as well as -provider specific payloads. - -Currently supported providers: - -* GitHub - -## Generic pull request payload - -For information about the payloads written to disk, see the [resource documentation](../../docs/resources.md#pull-request-resource). diff --git a/cmd/pullrequest-init/example/README.md b/cmd/pullrequest-init/example/README.md deleted file mode 100644 index 5ef8da5e8c6..00000000000 --- a/cmd/pullrequest-init/example/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# pullrequest-init examples - -This directory serves as an example of the pull request payloads you can expect -from the pull request pipeline resource. - -See -https://github.com/tektoncd/pipeline/blob/main/docs/resources.md#pull-request-resource -for more documentation. diff --git a/cmd/pullrequest-init/example/base.json b/cmd/pullrequest-init/example/base.json deleted file mode 100644 index 5cc296a0f37..00000000000 --- a/cmd/pullrequest-init/example/base.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "Ref": "master", - "Sha": "723b9a9d560bdf4dc8fc6f697d53f662d3454ac8", - "Repo": { - "ID": "146641150", - "Namespace": "tektoncd", - "Name": "pipeline", - "FullName": "tektoncd/pipeline", - "Perm": { - "Pull": false, - "Push": false, - "Admin": false - }, - "Branch": "master", - "Private": false, - "Clone": "https://github.com/tektoncd/pipeline.git", - "CloneSSH": "git@github.com:tektoncd/pipeline.git", - "Link": "https://github.com/tektoncd/pipeline", - "Created": "2018-08-29T18:21:55Z", - "Updated": "2019-12-04T17:26:42Z" - } -} diff --git a/cmd/pullrequest-init/example/comments/505233618.json b/cmd/pullrequest-init/example/comments/505233618.json deleted file mode 100644 index 8d6029ac332..00000000000 --- a/cmd/pullrequest-init/example/comments/505233618.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505233618, - "Body": "/retest", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505233618", - "Created": "2019-06-25T00:48:38Z", - "Updated": "2019-06-25T00:48:38Z" -} diff --git a/cmd/pullrequest-init/example/comments/505476017.json b/cmd/pullrequest-init/example/comments/505476017.json deleted file mode 100644 index 3c40fd58ec8..00000000000 --- a/cmd/pullrequest-init/example/comments/505476017.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505476017, - "Body": "> Looks good to me, question though : right now it's up to the user to write github status or not right (with this PR) ? Do we envision some \"automation\" around that ?\r\n\r\nYup! Great question, I'd love to source more ideas around this. The straight-forward answer would be to provide a runner binary that would wrap test execution and transform status codes and stdout/stderr to the pull request object.\r\n\r\nIs there any work being done around passing state between TaskRuns (e.g. for conditional execution or something similar)?", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505476017", - "Created": "2019-06-25T14:40:57Z", - "Updated": "2019-06-25T14:40:57Z" -} diff --git a/cmd/pullrequest-init/example/comments/505482755.json b/cmd/pullrequest-init/example/comments/505482755.json deleted file mode 100644 index 781789bb41f..00000000000 --- a/cmd/pullrequest-init/example/comments/505482755.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505482755, - "Body": "@wlynch yeah we need to think about that, as I think I remember talking about notification as a first-class citizen in Tekton maybe ? (and most likely write on a design docs).\r\n\r\n> Is there any work being done around passing state between TaskRuns (e.g. for conditional execution or something similar)?\r\n\r\n@dibyom ^^ :angel: ", - "Author": { - "Login": "vdemeester", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/6508?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505482755", - "Created": "2019-06-25T14:56:09Z", - "Updated": "2019-06-25T14:56:09Z" -} diff --git a/cmd/pullrequest-init/example/comments/505529049.json b/cmd/pullrequest-init/example/comments/505529049.json deleted file mode 100644 index 8ceb38871cc..00000000000 --- a/cmd/pullrequest-init/example/comments/505529049.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505529049, - "Body": "@wlynch yes, the condition container will have access to some read only metadata. Right now, this is just the pipeline run including the status fields. We could expose this to task runs as well? Or do you need to write additional metadata that needs to be exposed?", - "Author": { - "Login": "dibyom", - "Name": "", - "Email": "", - "Avatar": "https://avatars2.githubusercontent.com/u/3316877?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505529049", - "Created": "2019-06-25T16:50:26Z", - "Updated": "2019-06-25T16:50:26Z" -} diff --git a/cmd/pullrequest-init/example/comments/505616303.json b/cmd/pullrequest-init/example/comments/505616303.json deleted file mode 100644 index d64635b0123..00000000000 --- a/cmd/pullrequest-init/example/comments/505616303.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505616303, - "Body": "@dibyom Don't need to write more data, but it would be useful to expose it to TaskRuns to have a binary look for this information and automatically prep PR output as a response. Can you link me to that data and how TaskRuns can access it?", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505616303", - "Created": "2019-06-25T20:47:32Z", - "Updated": "2019-06-25T20:47:32Z" -} diff --git a/cmd/pullrequest-init/example/comments/505676294.json b/cmd/pullrequest-init/example/comments/505676294.json deleted file mode 100644 index 2b3bedb6ea0..00000000000 --- a/cmd/pullrequest-init/example/comments/505676294.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505676294, - "Body": "> @wlynch yeah we need to think about that, as I think I remember talking about notification as a first-class citizen in Tekton maybe ? (and most likely write on a design docs).\r\n> \r\n> >\r\n\r\nYeah, I think the automated use-cases for this would fit into something around either \"notification\" or \"conditional execution\".\r\n\r\nWith the conditional execution approach, a pipeline would have a Task that runs on either success or failure and writes the status to Github/Gitlab.", - "Author": { - "Login": "dlorenc", - "Name": "", - "Email": "", - "Avatar": "https://avatars1.githubusercontent.com/u/1714486?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505676294", - "Created": "2019-06-26T01:02:26Z", - "Updated": "2019-06-26T01:02:26Z" -} diff --git a/cmd/pullrequest-init/example/comments/505798994.json b/cmd/pullrequest-init/example/comments/505798994.json deleted file mode 100644 index 41bc5cf66f0..00000000000 --- a/cmd/pullrequest-init/example/comments/505798994.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505798994, - "Body": "> Yeah, I think the automated use-cases for this would fit into something around either \"notification\" or \"conditional execution\".\r\n\r\nThis could be implemented with the CloudEventPipelineResource as well. \r\nThe setup would be:\r\n- each task that needs to publish test results to the PR has an output resource of type cloudevent, which is sent to a dedicated tekton listener. The TaskRun, including status, is sent as body of the cloudevent.\r\n- an event binding is defined that accepts TaskRun completion events, and triggers a GitHub PR update Task(Run)\r\n- The GitHub PR update taskrun uses the PullRequest resource as input and output, and the metadata in the TaskRun (passed as parameter to the Task) to update GitHub\r\n\r\nThe advantages of using a separate Task/TaskRun are:\r\n- The status of the original Task is not affected by the outcome of the PR update\r\n- It doesn't require conditional execution\r\n- The Task that updates GitHub PRs can be as isolated as we want from the Task that runs the tests, which should make it easier to avoid leaking the GitHub token in logs.", - "Author": { - "Login": "afrittoli", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/2205608?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505798994", - "Created": "2019-06-26T09:33:55Z", - "Updated": "2019-06-26T09:33:55Z" -} diff --git a/cmd/pullrequest-init/example/comments/505890656.json b/cmd/pullrequest-init/example/comments/505890656.json deleted file mode 100644 index 331958271d9..00000000000 --- a/cmd/pullrequest-init/example/comments/505890656.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505890656, - "Body": "/retest", - "Author": { - "Login": "afrittoli", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/2205608?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505890656", - "Created": "2019-06-26T14:06:11Z", - "Updated": "2019-06-26T14:06:11Z" -} diff --git a/cmd/pullrequest-init/example/comments/505923534.json b/cmd/pullrequest-init/example/comments/505923534.json deleted file mode 100644 index 09c0b16f52b..00000000000 --- a/cmd/pullrequest-init/example/comments/505923534.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 505923534, - "Body": "> @dibyom Don't need to write more data, but it would be useful to expose it to TaskRuns to have a binary look for this information and automatically prep PR output as a response. Can you link me to that data and how TaskRuns can access it?\r\n\r\nWIP but its a file (`pr-metadata.json`) in `/workspace` for condition containers ([sample](https://gist.github.com/dibyom/95031ac458455ca2b0c25206b7420f24))\r\n\r\nIts exposed to conditional pods at the moment and not regular taskruns. I opened https://github.com/tektoncd/pipeline/issues/1016 to track that.", - "Author": { - "Login": "dibyom", - "Name": "", - "Email": "", - "Avatar": "https://avatars2.githubusercontent.com/u/3316877?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-505923534", - "Created": "2019-06-26T15:22:42Z", - "Updated": "2019-06-26T15:22:42Z" -} diff --git a/cmd/pullrequest-init/example/comments/506032472.json b/cmd/pullrequest-init/example/comments/506032472.json deleted file mode 100644 index 0780d7c8ae9..00000000000 --- a/cmd/pullrequest-init/example/comments/506032472.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 506032472, - "Body": "/assign @imjasonh", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-506032472", - "Created": "2019-06-26T20:28:38Z", - "Updated": "2019-06-26T20:28:38Z" -} diff --git a/cmd/pullrequest-init/example/comments/506082430.json b/cmd/pullrequest-init/example/comments/506082430.json deleted file mode 100644 index 6ec5d491a11..00000000000 --- a/cmd/pullrequest-init/example/comments/506082430.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 506082430, - "Body": "/lgtm", - "Author": { - "Login": "dlorenc", - "Name": "", - "Email": "", - "Avatar": "https://avatars1.githubusercontent.com/u/1714486?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-506082430", - "Created": "2019-06-26T23:36:10Z", - "Updated": "2019-06-26T23:36:10Z" -} diff --git a/cmd/pullrequest-init/example/comments/506082465.json b/cmd/pullrequest-init/example/comments/506082465.json deleted file mode 100644 index 7ecf3732ad3..00000000000 --- a/cmd/pullrequest-init/example/comments/506082465.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 506082465, - "Body": "/approve", - "Author": { - "Login": "dlorenc", - "Name": "", - "Email": "", - "Avatar": "https://avatars1.githubusercontent.com/u/1714486?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-506082465", - "Created": "2019-06-26T23:36:18Z", - "Updated": "2019-06-26T23:36:18Z" -} diff --git a/cmd/pullrequest-init/example/comments/507732301.json b/cmd/pullrequest-init/example/comments/507732301.json deleted file mode 100644 index a58b050e91b..00000000000 --- a/cmd/pullrequest-init/example/comments/507732301.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 507732301, - "Body": "/retest", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-507732301", - "Created": "2019-07-02T15:40:32Z", - "Updated": "2019-07-02T15:40:32Z" -} diff --git a/cmd/pullrequest-init/example/comments/507763725.json b/cmd/pullrequest-init/example/comments/507763725.json deleted file mode 100644 index 2007f70d3ac..00000000000 --- a/cmd/pullrequest-init/example/comments/507763725.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 507763725, - "Body": "> There is a binary checked in `cmd/pullrequest-init/pullrequest-init`. Is that intentional?\r\n\r\nGood catch! Removed.", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-507763725", - "Created": "2019-07-02T17:03:47Z", - "Updated": "2019-07-02T17:03:47Z" -} diff --git a/cmd/pullrequest-init/example/comments/508007084.json b/cmd/pullrequest-init/example/comments/508007084.json deleted file mode 100644 index 675ae5d2f7a..00000000000 --- a/cmd/pullrequest-init/example/comments/508007084.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ID": 508007084, - "Body": "[APPROVALNOTIFIER] This PR is **APPROVED**\n\nThis pull-request has been approved by: *afrittoli*, *dlorenc*, *vdemeester*, *wlynch*\n\nThe full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands).\n\nThe pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)\n\n
\nNeeds approval from an approver in each of these files:\n\n- ~~[OWNERS](https://github.com/tektoncd/pipeline/blob/main/OWNERS)~~ [dlorenc,vdemeester]\n\nApprovers can indicate their approval by writing `/approve` in a comment\nApprovers can cancel approval by writing `/approve cancel` in a comment\n
\n", - "Author": { - "Login": "tekton-robot", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/48335577?v=4", - "Link": "", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Link": "https://github.com/tektoncd/pipeline/pull/995#issuecomment-508007084", - "Created": "2019-07-03T09:01:16Z", - "Updated": "2019-07-03T09:01:16Z" -} diff --git a/cmd/pullrequest-init/example/head.json b/cmd/pullrequest-init/example/head.json deleted file mode 100644 index e85b0f79aa1..00000000000 --- a/cmd/pullrequest-init/example/head.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "Ref": "pr", - "Sha": "2a8ec1793553186cf2a027a89ae58a2e690509f3", - "Repo": { - "ID": "184178909", - "Namespace": "wlynch", - "Name": "pipeline", - "FullName": "wlynch/pipeline", - "Perm": { - "Pull": false, - "Push": false, - "Admin": false - }, - "Branch": "master", - "Private": false, - "Clone": "https://github.com/wlynch/pipeline.git", - "CloneSSH": "git@github.com:wlynch/pipeline.git", - "Link": "https://github.com/wlynch/pipeline", - "Created": "2019-04-30T02:40:49Z", - "Updated": "2019-11-22T18:44:26Z" - } -} diff --git a/cmd/pullrequest-init/example/labels/approved b/cmd/pullrequest-init/example/labels/approved deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cmd/pullrequest-init/example/labels/cla%3A+yes b/cmd/pullrequest-init/example/labels/cla%3A+yes deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cmd/pullrequest-init/example/labels/lgtm b/cmd/pullrequest-init/example/labels/lgtm deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cmd/pullrequest-init/example/labels/size%2FL b/cmd/pullrequest-init/example/labels/size%2FL deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cmd/pullrequest-init/example/pr.json b/cmd/pullrequest-init/example/pr.json deleted file mode 100644 index 491d6446a89..00000000000 --- a/cmd/pullrequest-init/example/pr.json +++ /dev/null @@ -1,141 +0,0 @@ -{ - "Number": 995, - "Title": "Add GitHub status updates to Pull Request CRD.", - "Body": "This adds support for the GitHub Status API\r\n(https://developer.github.com/v3/repos/statuses/).\r\n\r\nThis accompanies #778 and #895 to complete initial Pull Request support\r\nsupport for GitHub OAuth.\r\n\r\n\r\n\r\n# Changes\r\n\r\nAdds GitHub status fetching and updates to Pull Request CRD.\r\n\r\n# Submitter Checklist\r\n\r\nThese are the criteria that every PR should meet, please check them off as you\r\nreview them:\r\n\r\n- [x] Includes [tests](https://github.com/tektoncd/community/blob/main/standards.md#principles) (if functionality changed/added)\r\n- [x] Includes [docs](https://github.com/tektoncd/community/blob/main/standards.md#principles) (if user facing)\r\n- [x] Commit messages follow [commit message best practices](https://github.com/tektoncd/community/blob/main/standards.md#commit-messages)\r\n\r\n_See [the contribution guide](https://github.com/tektoncd/pipeline/blob/main/CONTRIBUTING.md)\r\nfor more details._\r\n\r\n# Release Notes\r\n\r\n\r\n\r\n```\r\nAdds GitHub status fetching and updates to Pull Request CRD.\r\n```\r\n", - "Labels": [ - { - "ID": 0, - "URL": "https://api.github.com/repos/tektoncd/pipeline/labels/approved", - "Name": "approved", - "Description": "Indicates a PR has been approved by an approver from all required OWNERS files.", - "Color": "abea59" - }, - { - "ID": 0, - "URL": "https://api.github.com/repos/tektoncd/pipeline/labels/cla:%20yes", - "Name": "cla: yes", - "Description": "Trying to make the CLA bot happy with ppl from different companies work on one commit", - "Color": "0c6a89" - }, - { - "ID": 0, - "URL": "https://api.github.com/repos/tektoncd/pipeline/labels/lgtm", - "Name": "lgtm", - "Description": "Indicates that a PR is ready to be merged.", - "Color": "6aed75" - }, - { - "ID": 0, - "URL": "https://api.github.com/repos/tektoncd/pipeline/labels/size/L", - "Name": "size/L", - "Description": "Denotes a PR that changes 100-499 lines, ignoring generated files.", - "Color": "ee9900" - } - ], - "Sha": "2a8ec1793553186cf2a027a89ae58a2e690509f3", - "Ref": "refs/pull/995/head", - "Source": "pr", - "Target": "master", - "Base": { - "Ref": "master", - "Sha": "723b9a9d560bdf4dc8fc6f697d53f662d3454ac8", - "Repo": { - "ID": "146641150", - "Namespace": "tektoncd", - "Name": "pipeline", - "FullName": "tektoncd/pipeline", - "Perm": { - "Pull": false, - "Push": false, - "Admin": false - }, - "Branch": "master", - "Private": false, - "Clone": "https://github.com/tektoncd/pipeline.git", - "CloneSSH": "git@github.com:tektoncd/pipeline.git", - "Link": "https://github.com/tektoncd/pipeline", - "Created": "2018-08-29T18:21:55Z", - "Updated": "2019-12-04T17:26:42Z" - } - }, - "Head": { - "Ref": "pr", - "Sha": "2a8ec1793553186cf2a027a89ae58a2e690509f3", - "Repo": { - "ID": "184178909", - "Namespace": "wlynch", - "Name": "pipeline", - "FullName": "wlynch/pipeline", - "Perm": { - "Pull": false, - "Push": false, - "Admin": false - }, - "Branch": "master", - "Private": false, - "Clone": "https://github.com/wlynch/pipeline.git", - "CloneSSH": "git@github.com:wlynch/pipeline.git", - "Link": "https://github.com/wlynch/pipeline", - "Created": "2019-04-30T02:40:49Z", - "Updated": "2019-11-22T18:44:26Z" - } - }, - "Fork": "wlynch/pipeline", - "Link": "https://github.com/tektoncd/pipeline/pull/995.diff", - "State": "closed", - "Closed": true, - "Draft": false, - "Merged": true, - "Mergeable": false, - "Rebaseable": false, - "MergeableState": "", - "MergeSha": "260c2277fe8ec80b4adc54ccbbfce9bb135f2499", - "Author": { - "Login": "wlynch", - "Name": "", - "Email": "", - "Avatar": "https://avatars3.githubusercontent.com/u/1844673?v=4", - "Link": "https://github.com/wlynch", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - "Assignees": [ - { - "Login": "vdemeester", - "Name": "", - "Email": "", - "Avatar": "https://avatars0.githubusercontent.com/u/6508?v=4", - "Link": "https://github.com/vdemeester", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - { - "Login": "ImJasonH", - "Name": "", - "Email": "", - "Avatar": "https://avatars1.githubusercontent.com/u/210737?v=4", - "Link": "https://github.com/ImJasonH", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - }, - { - "Login": "dlorenc", - "Name": "", - "Email": "", - "Avatar": "https://avatars1.githubusercontent.com/u/1714486?v=4", - "Link": "https://github.com/dlorenc", - "Created": "0001-01-01T00:00:00Z", - "Updated": "0001-01-01T00:00:00Z" - } - ], - "Milestone": { - "Number": 0, - "ID": 0, - "Title": "", - "Description": "", - "Link": "", - "State": "" - }, - "Created": "2019-06-20T15:42:17Z", - "Updated": "2019-07-03T09:02:49Z" -} diff --git a/cmd/pullrequest-init/example/status/cla%2Fgoogle.json b/cmd/pullrequest-init/example/status/cla%2Fgoogle.json deleted file mode 100644 index c39f6f96bb8..00000000000 --- a/cmd/pullrequest-init/example/status/cla%2Fgoogle.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "success", - "Label": "cla/google", - "Desc": "All necessary CLAs are signed", - "Target": "" -} diff --git a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-build-tests.json b/cmd/pullrequest-init/example/status/pull-tekton-pipeline-build-tests.json deleted file mode 100644 index 556ee5c2722..00000000000 --- a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-build-tests.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "pending", - "Label": "pull-tekton-pipeline-build-tests", - "Desc": "Job triggered.", - "Target": "https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_pipeline/995/pull-tekton-pipeline-build-tests/1146102490727452672/" -} diff --git a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-go-coverage.json b/cmd/pullrequest-init/example/status/pull-tekton-pipeline-go-coverage.json deleted file mode 100644 index c6889215429..00000000000 --- a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-go-coverage.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "pending", - "Label": "pull-tekton-pipeline-go-coverage", - "Desc": "Job triggered.", - "Target": "https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_pipeline/995/pull-tekton-pipeline-go-coverage/1146102490727452675/" -} diff --git a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-integration-tests.json b/cmd/pullrequest-init/example/status/pull-tekton-pipeline-integration-tests.json deleted file mode 100644 index 2a7b9d077d4..00000000000 --- a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-integration-tests.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "pending", - "Label": "pull-tekton-pipeline-integration-tests", - "Desc": "Job triggered.", - "Target": "https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_pipeline/995/pull-tekton-pipeline-integration-tests/1146102490727452674/" -} diff --git a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-unit-tests.json b/cmd/pullrequest-init/example/status/pull-tekton-pipeline-unit-tests.json deleted file mode 100644 index 796bcfd91b0..00000000000 --- a/cmd/pullrequest-init/example/status/pull-tekton-pipeline-unit-tests.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "pending", - "Label": "pull-tekton-pipeline-unit-tests", - "Desc": "Job triggered.", - "Target": "https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_pipeline/995/pull-tekton-pipeline-unit-tests/1146102490727452673/" -} diff --git a/cmd/pullrequest-init/example/status/tide.json b/cmd/pullrequest-init/example/status/tide.json deleted file mode 100644 index 7543d84f7fb..00000000000 --- a/cmd/pullrequest-init/example/status/tide.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "State": "pending", - "Label": "tide", - "Desc": "Not mergeable. Needs lgtm label.", - "Target": "https://prow.tekton.dev/tide" -} diff --git a/cmd/pullrequest-init/kodata/LICENSE b/cmd/pullrequest-init/kodata/LICENSE deleted file mode 120000 index 5853aaea53b..00000000000 --- a/cmd/pullrequest-init/kodata/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../../LICENSE \ No newline at end of file diff --git a/cmd/pullrequest-init/kodata/third_party b/cmd/pullrequest-init/kodata/third_party deleted file mode 120000 index 6bfa480c09a..00000000000 --- a/cmd/pullrequest-init/kodata/third_party +++ /dev/null @@ -1 +0,0 @@ -../../../third_party \ No newline at end of file diff --git a/cmd/pullrequest-init/main.go b/cmd/pullrequest-init/main.go deleted file mode 100644 index e40501e6823..00000000000 --- a/cmd/pullrequest-init/main.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package main - -import ( - "context" - "flag" - "fmt" - "os" - - "github.com/tektoncd/pipeline/pkg/pullrequest" - "go.uber.org/zap" -) - -var ( - prURL = flag.String("url", "", "The url of the pull request to initialize.") - path = flag.String("path", "", "Path of directory under which PR will be copied") - mode = flag.String("mode", "download", "Whether to operate in download or upload mode") - provider = flag.String("provider", "", "The SCM provider to use. Optional") - skipTLSVerify = flag.Bool("insecure-skip-tls-verify", false, "Enable skipping TLS certificate verification in the git client. Defaults to false") - disableStrictJSONComments = flag.Bool("disable-strict-json-comments", false, "Disable strict json parsing for comment files with .json extension") -) - -func main() { - flag.Parse() - prod, _ := zap.NewProduction() - logger := prod.Sugar() - logger = logger.With( - zap.String("resource_type", "pullrequest"), - zap.String("mode", *mode)) - defer func() { - _ = logger.Sync() - }() - ctx := context.Background() - - token := os.Getenv("AUTH_TOKEN") - client, err := pullrequest.NewSCMHandler(logger, *prURL, *provider, token, *skipTLSVerify) - if err != nil { - logger.Fatalf("error creating GitHub client: %v", err) - } - - switch *mode { - case "download": - logger.Info("RUNNING DOWNLOAD!") - pr, err := client.Download(ctx) - if err != nil { - fmt.Println(err) - logger.Fatal(err) - } - if err := pullrequest.ToDisk(pr, *path); err != nil { - logger.Fatal(err) - } - - case "upload": - logger.Info("RUNNING UPLOAD!") - r, err := pullrequest.FromDisk(*path, *disableStrictJSONComments) - if err != nil { - logger.Fatal(err) - } - if err := client.Upload(ctx, r); err != nil { - logger.Fatal(err) - } - } -} diff --git a/config/controller.yaml b/config/controller.yaml index f020c16a936..f32860b55b4 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -70,7 +70,6 @@ spec: "-nop-image", "ko://github.com/tektoncd/pipeline/cmd/nop", "-sidecarlogresults-image", "ko://github.com/tektoncd/pipeline/cmd/sidecarlogresults", "-imagedigest-exporter-image", "ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter", - "-pr-image", "ko://github.com/tektoncd/pipeline/cmd/pullrequest-init", "-workingdirinit-image", "ko://github.com/tektoncd/pipeline/cmd/workingdirinit", # This is gcr.io/google.com/cloudsdktool/cloud-sdk:302.0.0-slim diff --git a/docs/install.md b/docs/install.md index 214caeca0b7..753320eed57 100644 --- a/docs/install.md +++ b/docs/install.md @@ -721,12 +721,6 @@ which results in: "sha256": "59b5304bcfdd9834150a2701720cf66e3ebe6d6e4d361ae1612d9430089591f8" } }, - { - "name": "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init", - "digest": { - "sha256": "4992491b2714a73c0a84553030e6056e6495b3d9d5cc6b20cf7bc8c51be779bb" - } - }, { "name": "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook", "digest": { @@ -768,8 +762,6 @@ list of image references with their digest as part of the `args`: "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop:v0.28.1@sha256:59b5304bcfdd9834150a2701720cf66e3ebe6d6e4d361ae1612d9430089591f8", "-imagedigest-exporter-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter:v0.28.1@sha256:e4d77b5b8902270f37812f85feb70d57d6d0e1fed2f3b46f86baf534f19cd9c0", - "-pr-image", - "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init:v0.28.1@sha256:4992491b2714a73c0a84553030e6056e6495b3d9d5cc6b20cf7bc8c51be779bb", ``` Similarly, you can verify the rest of the images which were published as part of the Tekton Pipelines release: @@ -779,7 +771,6 @@ gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter -gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook ``` diff --git a/pkg/apis/pipeline/images.go b/pkg/apis/pipeline/images.go index 68e7a9cd813..f489e9441a8 100644 --- a/pkg/apis/pipeline/images.go +++ b/pkg/apis/pipeline/images.go @@ -38,8 +38,6 @@ type Images struct { ShellImageWin string // GsutilImage is the container image containing gsutil. GsutilImage string - // PRImage is the container image that we use to implement the PR source step. - PRImage string // ImageDigestExporterImage is the container image containing our image digest exporter binary. ImageDigestExporterImage string // WorkingDirInitImage is the container image containing our working dir init binary. @@ -61,7 +59,6 @@ func (i Images) Validate() error { {i.ShellImage, "shell-image"}, {i.ShellImageWin, "shell-image-win"}, {i.GsutilImage, "gsutil-image"}, - {i.PRImage, "pr-image"}, {i.ImageDigestExporterImage, "imagedigest-exporter-image"}, {i.WorkingDirInitImage, "workingdirinit-image"}, } { diff --git a/pkg/apis/pipeline/images_test.go b/pkg/apis/pipeline/images_test.go index 0f942cfb417..2cff4555ec2 100644 --- a/pkg/apis/pipeline/images_test.go +++ b/pkg/apis/pipeline/images_test.go @@ -15,7 +15,6 @@ func TestValidate(t *testing.T) { ShellImage: "set", ShellImageWin: "set", GsutilImage: "set", - PRImage: "set", ImageDigestExporterImage: "set", WorkingDirInitImage: "set", } @@ -31,10 +30,9 @@ func TestValidate(t *testing.T) { ShellImage: "", // unset! ShellImageWin: "set", GsutilImage: "set", - PRImage: "", // unset! ImageDigestExporterImage: "set", } - wantErr := "found unset image flags: [git-image pr-image shell-image workingdirinit-image]" + wantErr := "found unset image flags: [git-image shell-image workingdirinit-image]" if err := invalid.Validate(); err == nil { t.Error("invalid Images expected error, got nil") } else if err.Error() != wantErr { diff --git a/pkg/apis/resource/resource.go b/pkg/apis/resource/resource.go index 19bcc43c280..d9038dd29f7 100644 --- a/pkg/apis/resource/resource.go +++ b/pkg/apis/resource/resource.go @@ -24,7 +24,6 @@ import ( resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/git" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/pullrequest" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" ) @@ -39,8 +38,6 @@ func FromType(name string, r *resourcev1alpha1.PipelineResource, images pipeline return image.NewResource(name, r) case resourcev1alpha1.PipelineResourceTypeStorage: return storage.NewResource(name, images, r) - case resourcev1alpha1.PipelineResourceTypePullRequest: - return pullrequest.NewResource(name, images.PRImage, r) } return nil, fmt.Errorf("%s is an invalid or unimplemented PipelineResource", r.Spec.Type) } diff --git a/pkg/artifacts/artifact_storage_test.go b/pkg/artifacts/artifact_storage_test.go index 435bb1c7127..238423747c2 100644 --- a/pkg/artifacts/artifact_storage_test.go +++ b/pkg/artifacts/artifact_storage_test.go @@ -43,7 +43,6 @@ var ( GitImage: "override-with-git:latest", ShellImage: "busybox", GsutilImage: "gcr.io/google.com/cloudsdktool/cloud-sdk", - PRImage: "override-with-pr:latest", ImageDigestExporterImage: "override-with-imagedigest-exporter-image:latest", } pipelinerun = &v1beta1.PipelineRun{ diff --git a/pkg/pullrequest/README.md b/pkg/pullrequest/README.md deleted file mode 100644 index d085a89eed4..00000000000 --- a/pkg/pullrequest/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# PullRequest Resource E2E Tests - -This directory contains E2E tests for the Pull Request resource. The E2E test -can run in a variety of modes, talking to both fake and real SCM providers. - -## Fake SCM - -In the Fake SCM mode, all requests are redirected to a local HTTP server that -intercepts the request and feeds back fake data. `testdata/scm` contains this -data, which was derived from making actual requests to the GitHub API. This data -should be kept as close as possible to the upstream API response. - -The fake server can be configured to look for authentication tokens in the -request. By default if a token is not provided via an environment variable, one -will be set arbitrarily. Providing a valid token is not required for the Fake -SCM mode. - -In order for the fake SCM proxy to successfully intercept requests, URLs must -use `http`. - -## Real SCM - -```sh -$ go test . -proxy false -``` - -In the Real SCM mode, the E2E test will communicate with real SCM providers. In -order to support uploads, a valid authentication token must be provided. - -The test will first look for an SCM-specific auth code, or default back to the -standard `AUTH_TOKEN` environment variable if one is not present. Currently the -valid SCM-specific auth codes are: - -- `GITHUB_TOKEN` diff --git a/pkg/pullrequest/api.go b/pkg/pullrequest/api.go deleted file mode 100644 index a70ea3bd42a..00000000000 --- a/pkg/pullrequest/api.go +++ /dev/null @@ -1,319 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package pullrequest - -import ( - "context" - "fmt" - "io" - "strconv" - - "github.com/hashicorp/go-multierror" - "github.com/jenkins-x/go-scm/scm" - "go.uber.org/zap" -) - -// Handler handles interactions with the GitHub API. -type Handler struct { - client *scm.Client - - repo string - prNum int - - logger *zap.SugaredLogger -} - -// NewHandler initializes a new handler for interacting with SCM -// resources. -func NewHandler(logger *zap.SugaredLogger, client *scm.Client, repo string, pr int) *Handler { - return &Handler{ - logger: logger, - client: client, - repo: repo, - prNum: pr, - } -} - -// Download fetches and stores the desired pull request. -func (h *Handler) Download(ctx context.Context) (*Resource, error) { - // Pull Request - h.logger.Info("finding pr") - pr, _, err := h.client.PullRequests.Find(ctx, h.repo, h.prNum) - if err != nil { - return nil, fmt.Errorf("finding pr %d: %w", h.prNum, err) - } - - // Statuses - h.logger.Info("finding combined status") - status, out, err := h.client.Repositories.ListStatus(ctx, h.repo, pr.Sha, &scm.ListOptions{}) - if err != nil { - body, _ := io.ReadAll(out.Body) - defer out.Body.Close() - h.logger.Warnf("%v: %s", err, string(body)) - return nil, fmt.Errorf("finding combined status for pr %d: %w", h.prNum, err) - } - - // Comments - // TODO: Pagination. - h.logger.Info("finding comments: %v", h) - comments, _, err := h.client.PullRequests.ListComments(ctx, h.repo, h.prNum, &scm.ListOptions{}) - if err != nil { - return nil, fmt.Errorf("finding comments for pr %d: %w", h.prNum, err) - } - h.logger.Info("found comments: %v", comments) - - labels, _, err := h.client.PullRequests.ListLabels(ctx, h.repo, h.prNum, &scm.ListOptions{}) - if err != nil { - return nil, fmt.Errorf("finding labels for pr %d: %w", h.prNum, err) - } - pr.Labels = labels - - r := &Resource{ - PR: pr, - Statuses: status, - Comments: comments, - } - populateManifest(r) - return r, nil -} - -func populateManifest(r *Resource) { - labels := make(Manifest) - for _, l := range r.PR.Labels { - labels[l.Name] = true - } - - comments := make(Manifest) - for _, c := range r.Comments { - comments[strconv.Itoa(c.ID)] = true - } - - r.Manifests = map[string]Manifest{ - "labels": labels, - "comments": comments, - } -} - -// Upload takes files stored on the filesystem and uploads new changes to -// GitHub. -func (h *Handler) Upload(ctx context.Context, r *Resource) error { - h.logger.Infof("Syncing resource: %+v", r) - - var merr error - - if err := h.uploadLabels(ctx, r.Manifests["labels"], r.PR.Labels); err != nil { - merr = multierror.Append(merr, err) - } - - if err := h.uploadStatuses(ctx, r.Statuses, r.PR.Sha); err != nil { - merr = multierror.Append(merr, err) - } - - if err := h.uploadComments(ctx, r.Manifests["comments"], r.Comments); err != nil { - merr = multierror.Append(merr, err) - } - - return merr -} - -func (h *Handler) uploadLabels(ctx context.Context, manifest Manifest, raw []*scm.Label) error { - // Convert requested labels to a map. This ensures that there are no - // duplicates and makes it easier to query which labels are being requested. - labels := make(map[string]bool) - for _, l := range raw { - labels[l.Name] = true - } - - // Fetch current labels associated to the PR. We'll need to keep track of - // which labels are new and should not be modified. - currentLabels, _, err := h.client.PullRequests.ListLabels(ctx, h.repo, h.prNum, &scm.ListOptions{}) - if err != nil { - return fmt.Errorf("listing labels for pr %d: %w", h.prNum, err) - } - current := make(map[string]bool) - for _, l := range currentLabels { - current[l.Name] = true - } - h.logger.Debugf("Current labels: %v", current) - - var merr error - - // Create new labels that are missing from the PR. - create := []string{} - for l := range labels { - if !current[l] { - create = append(create, l) - } - } - h.logger.Debugf("Creating labels %v for PR %d", create, h.prNum) - for _, l := range create { - if _, err := h.client.PullRequests.AddLabel(ctx, h.repo, h.prNum, l); err != nil { - merr = multierror.Append(merr, fmt.Errorf("adding label %s: %w", l, err)) - } - } - - // Remove labels that no longer exist in the workspace and were present in - // the manifest. - for l := range current { - if !labels[l] && manifest[l] { - h.logger.Debugf("Removing label %s for PR %d", l, h.prNum) - if _, err := h.client.PullRequests.DeleteLabel(ctx, h.repo, h.prNum, l); err != nil { - merr = multierror.Append(merr, fmt.Errorf("finding pr %d: %w", h.prNum, err)) - } - } - } - - return merr -} - -func (h *Handler) uploadComments(ctx context.Context, manifest Manifest, comments []*scm.Comment) error { - h.logger.Infof("Setting comments for PR %d to: %v", h.prNum, comments) - - // Sort comments into whether they are new or existing comments (based on - // whether there is an ID defined). - existingComments := map[int]*scm.Comment{} - newComments := []*scm.Comment{} - for _, c := range comments { - if c.ID != 0 { - existingComments[c.ID] = c - } else { - newComments = append(newComments, c) - } - } - - var merr error - if err := h.maybeDeleteComments(ctx, manifest, existingComments); err != nil { - merr = multierror.Append(merr, fmt.Errorf("deleting comments %v: %w", existingComments, err)) - } - - if err := h.createNewComments(ctx, newComments); err != nil { - merr = multierror.Append(merr, fmt.Errorf("creating comments %v: %s", newComments, err)) - } - - return merr -} - -// maybeDeleteComments deletes a comment iif it no longer exists in the remote -// SCM and exists in the manifest (therefore was present during resource -// initialization). -func (h *Handler) maybeDeleteComments(ctx context.Context, manifest Manifest, comments map[int]*scm.Comment) error { - currentComments, _, err := h.client.PullRequests.ListComments(ctx, h.repo, h.prNum, &scm.ListOptions{}) - if err != nil { - return err - } - - var merr error - for _, ec := range currentComments { - if _, ok := comments[ec.ID]; ok { - // Comment already exists. Carry on - continue - } - - // Current comment does not exist in the current resource. - - // Check if we were aware of the comment when the resource was - // initialized. - if _, ok := manifest[strconv.Itoa(ec.ID)]; !ok { - // Comment did not exist when resource created, so this was created - // recently. To not modify this comment. - h.logger.Debugf("Not tracking comment %d. Skipping.", ec.ID) - continue - } - - // Comment existed beforehand, user intentionally deleted. Remove from - // upstream source. - h.logger.Infof("Deleting comment %d for PR %d", ec.ID, h.prNum) - if _, err := h.client.PullRequests.DeleteComment(ctx, h.repo, h.prNum, ec.ID); err != nil { - merr = multierror.Append(merr, fmt.Errorf("deleting comment %d: %w", ec.ID, err)) - continue - } - } - return merr -} - -func (h *Handler) createNewComments(ctx context.Context, comments []*scm.Comment) error { - var merr error - for _, dc := range comments { - c := &scm.CommentInput{ - Body: dc.Body, - } - h.logger.Infof("Creating comment %s for PR %d", c.Body, h.prNum) - if _, _, err := h.client.PullRequests.CreateComment(ctx, h.repo, h.prNum, c); err != nil { - merr = multierror.Append(merr, fmt.Errorf("creating comment %v: %w", c, err)) - } - } - return merr -} - -func validateStatuses(statuses []*scm.Status) error { - var merr error - for _, s := range statuses { - if s.Label == "" { - merr = multierror.Append(merr, fmt.Errorf("invalid status: \"Label\" should not be empty: %v", *s)) - } - if s.State.String() == scm.StateUnknown.String() { - merr = multierror.Append(merr, fmt.Errorf("invalid status: \"State\" is empty or has invalid value: %v", *s)) - } - } - return merr -} - -func (h *Handler) uploadStatuses(ctx context.Context, statuses []*scm.Status, sha string) error { - if statuses == nil { - h.logger.Info("Skipping statuses, nothing to set.") - return nil - } - - if err := validateStatuses(statuses); err != nil { - return err - } - - h.logger.Infof("Looking for existing status on %s", sha) - cs, _, err := h.client.Repositories.ListStatus(ctx, h.repo, sha, &scm.ListOptions{}) - if err != nil { - return err - } - - // Index the statuses so we can avoid sending them if they already exist. - csMap := map[string]scm.State{} - for _, s := range cs { - csMap[s.Label] = s.State - } - - var merr error - - for _, s := range statuses { - if csMap[s.Label] == s.State { - h.logger.Infof("Skipping setting %s because it already matches", s.Label) - continue - } - - si := &scm.StatusInput{ - Label: s.Label, - State: s.State, - Desc: s.Desc, - Target: s.Target, - } - h.logger.Infof("Creating status %s on %s", si.Label, sha) - if _, _, err := h.client.Repositories.CreateStatus(ctx, h.repo, sha, si); err != nil { - merr = multierror.Append(merr, fmt.Errorf("creating status %q: %w", si.Label, err)) - continue - } - } - - return merr -} diff --git a/pkg/pullrequest/api_test.go b/pkg/pullrequest/api_test.go deleted file mode 100644 index c55e9dd8747..00000000000 --- a/pkg/pullrequest/api_test.go +++ /dev/null @@ -1,370 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package pullrequest - -import ( - "context" - "testing" - - "github.com/hashicorp/go-multierror" - "github.com/jenkins-x/go-scm/scm" - "github.com/jenkins-x/go-scm/scm/driver/fake" - "github.com/tektoncd/pipeline/test/diff" - - "github.com/google/go-cmp/cmp" - "go.uber.org/zap" - "go.uber.org/zap/zaptest" -) - -const ( - repo = "foo/bar" - prNum = 1 -) - -func defaultResource() *Resource { - pr := &scm.PullRequest{ - Number: 123, - Sha: "sha1", - Head: scm.PullRequestBranch{ - Ref: "refs/heads/branch1", - Sha: "sha1", - Repo: scm.Repository{Name: "repo1"}, - }, - Base: scm.PullRequestBranch{ - Ref: "refs/heads/branch1", - Sha: "sha2", - Repo: scm.Repository{Name: "repo1"}, - }, - Labels: []*scm.Label{}, - } - r := &Resource{ - PR: pr, - Comments: []*scm.Comment{ - { - ID: 1, - Body: "testing", - }, - { - ID: 2, - Body: "abc123", - }, - }, - Statuses: []*scm.Status{ - { - Label: "Tekton", - State: scm.StateSuccess, - Desc: "Test all the things!", - Target: "https://tekton.dev", - }, - }, - } - populateManifest(r) - return r -} - -func newHandler(t *testing.T) (*Handler, *fake.Data) { - t.Helper() - logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())).Sugar() - client, data := fake.NewDefault() - - r := defaultResource() - data.PullRequests[prNum] = r.PR - data.IssueComments[prNum] = r.Comments - data.PullRequestComments[prNum] = r.Comments - data.Statuses[r.PR.Sha] = r.Statuses - - return NewHandler(logger, client, repo, prNum), data -} - -func TestDownload(t *testing.T) { - ctx := context.Background() - h, data := newHandler(t) - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - pr := data.PullRequests[prNum] - want := &Resource{ - PR: pr, - Comments: data.IssueComments[prNum], - Statuses: data.Statuses[pr.Sha], - } - populateManifest(want) - - if d := cmp.Diff(want, got); d != "" { - t.Errorf("Get PullRequest: %s", diff.PrintWantGot(d)) - } -} - -func TestUploadFromDisk(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - dir := t.TempDir() - r, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - if err := ToDisk(r, dir); err != nil { - t.Fatal(err) - } - - r, err = FromDisk(dir, false) - if err != nil { - t.Fatal(err) - } - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } -} - -func TestUpload_NewComment(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - c := &scm.Comment{Body: "hello world!"} - r.Comments = append(r.Comments, c) - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - c.Author = scm.User{Login: "k8s-ci-robot"} - - // Only compare comments since the resource manifest will change between - // downloads. - if d := cmp.Diff(r.Comments, got.Comments); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_DeleteComment(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - r.Comments = r.Comments[1:] - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - if d := cmp.Diff(r.Comments, got.Comments); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_ManifestComment(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - - // Create a new comment out of band of the resource. The upload should not - // affect this. - if _, _, err := h.client.PullRequests.CreateComment(ctx, h.repo, h.prNum, &scm.CommentInput{ - Body: "hello world!", - }); err != nil { - t.Fatal(err) - } - - r.Comments = []*scm.Comment{} - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - r.Comments = []*scm.Comment{{ - Body: "hello world!", - Author: scm.User{Login: "k8s-ci-robot"}, - }} - - if d := cmp.Diff(r.Comments, got.Comments); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_NewStatus(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - s := &scm.Status{ - Label: "CI", - State: scm.StateFailure, - } - r.Statuses = append(r.Statuses, s) - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - if d := cmp.Diff(r, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_UpdateStatus(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - r.Statuses[0].State = scm.StateCanceled - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - if d := cmp.Diff(r, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_Invalid_Status(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - r.Statuses = []*scm.Status{ - { - Label: "Tekton", - Desc: "Status with empty State field", - Target: "https://tekton.dev", - }, - { - State: scm.StateSuccess, - Desc: "Status without label", - Target: "https://tekton.dev", - }, - } - - expectedErrors := []string{ - "invalid status: \"State\" is empty or has invalid value: {unknown Tekton Status with empty State field https://tekton.dev }", - "invalid status: \"Label\" should not be empty: {success Status without label https://tekton.dev }", - } - err := h.Upload(ctx, r) - if err == nil { - t.Fatal("expected errors, got nil") - } - merr, ok := err.(*multierror.Error) - if !ok { - t.Fatalf("expected error of type multierror, got %#v", merr) - } - if len(merr.Errors) != 2 { - t.Fatalf("expected 2 errors, got %d", len(merr.Errors)) - } - for i, err := range merr.Errors { - if d := cmp.Diff(expectedErrors[i], err.Error()); d != "" { - t.Errorf("Upload status error diff %s", diff.PrintWantGot(d)) - } - } -} - -func TestUpload_NewLabel(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - r.PR.Labels = append(r.PR.Labels, &scm.Label{Name: "z"}) - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - if d := cmp.Diff(r.PR, got.PR); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_DeleteLabel(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - r.PR.Labels = []*scm.Label{} - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - - if d := cmp.Diff(r.PR, got.PR); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} - -func TestUpload_ManifestLabel(t *testing.T) { - ctx := context.Background() - h, _ := newHandler(t) - - r := defaultResource() - - // Create a new label out of band of the resource. The upload should not - // affect this. - if _, err := h.client.PullRequests.AddLabel(ctx, h.repo, h.prNum, "z"); err != nil { - t.Fatal(err) - } - - if err := h.Upload(ctx, r); err != nil { - t.Fatal(err) - } - - got, err := h.Download(ctx) - if err != nil { - t.Fatal(err) - } - r.PR.Labels = append(r.PR.Labels, &scm.Label{Name: "z"}) - - if d := cmp.Diff(r.PR, got.PR); d != "" { - t.Errorf(diff.PrintWantGot(d)) - } -} diff --git a/pkg/pullrequest/disk.go b/pkg/pullrequest/disk.go deleted file mode 100644 index 62ea974c794..00000000000 --- a/pkg/pullrequest/disk.go +++ /dev/null @@ -1,351 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package pullrequest - -import ( - "encoding/gob" - "encoding/json" - "fmt" - "net/url" - "os" - "path/filepath" - "strconv" - "strings" - - "github.com/jenkins-x/go-scm/scm" -) - -// This file contains functions used to write a PR to disk. The representation is as follows: - -// /workspace/ -// /workspace// -// /workspace//pr.json -// /workspace//labels/ -// /workspace//labels/