Skip to content

Commit

Permalink
Remove PullRequest Resources
Browse files Browse the repository at this point in the history
This commit removes the PullRequest Resources support.
This PR removes `github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/pullrequest`
and docs for PullRequest resources.

Removal of `pipelineResources`, as in tektoncd#5967 has been broken up into removal
of each resources packages for the `small PR` code standard.
  • Loading branch information
JeromeJu committed Jan 27, 2023
1 parent 04ce5da commit 3dd6180
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 696 deletions.
126 changes: 0 additions & 126 deletions docs/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ For example:
- [Optional Resources](#optional-resources)
- [Resource types](#resource-types)
- [Git Resource](#git-resource)
- [Pull Request Resource](#pull-request-resource)
- [Image Resource](#image-resource)
- [Storage Resource](#storage-resource)
- [GCS Storage Resource](#gcs-storage-resource)
Expand Down Expand Up @@ -455,131 +454,6 @@ spec:

Note: `httpProxy`, `httpsProxy`, and `noProxy` are all optional but no validation done if all three are specified.

### Pull Request Resource

The `pullRequest` resource represents a pull request event from a source control
system.

Adding the Pull Request resource as an input to a `Task` will populate the
workspace with a set of files containing generic pull request related metadata
such as base/head commit, comments, and labels.

The payloads will also contain links to raw service-specific payloads where
appropriate.

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.

Example file structure:

```shell
/workspace/
/workspace/<resource>/
/workspace/<resource>/labels/
/workspace/<resource>/labels/<label>
/workspace/<resource>/status/
/workspace/<resource>/status/<status>
/workspace/<resource>/comments/
/workspace/<resource>/comments/<comment>
/workspace/<resource>/head.json
/workspace/<resource>/base.json
/workspace/<resource>/pr.json
```

More details:

Labels are empty files, named after the desired label string.

Statuses describe pull request statuses. It is represented as a set of json
files.

References (head and base) describe Git references. They are represented as a
set of json files.

Comments describe a pull request comment. They are represented as a set of json
files. Add a file or modify the `Body` field in an existing json comment file to
interact with the PR. Files with json extension will be parsed as such.
The content of any comments file(s) with other/no extensions will be treated as
body field of the comment.

Other pull request information can be found in `pr.json`. This is a read-only
resource. Users should use other subresources (labels, comments, etc) to
interact with the PR.

For an example of the output this resource provides, see
[`example`](../cmd/pullrequest-init/example).

To create a pull request resource using the `PipelineResource` CRD:

```yaml
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: wizzbang-pr
namespace: default
spec:
type: pullRequest
params:
- name: url
value: https://github.com/wizzbangcorp/wizzbang/pulls/1
secrets:
- fieldName: authToken
secretName: github-secrets
secretKey: token
---
apiVersion: v1
kind: Secret
metadata:
name: github-secrets
type: Opaque
data:
token: github_personal_access_token_secret # in base64 encoded form
```

Params that can be added are the following:

1. `url`: represents the location of the pull request to fetch.
1. `provider`: represents the SCM provider to use. This will be "guessed" based
on the url if not set. Valid values are `github` or `gitlab` today.
1. `insecure-skip-tls-verify`: represents whether to skip verification of certificates
from the git server. Valid values are `"true"` or `"false"`, the default being
`"false"`.

#### Statuses

The following status codes are available to use for the Pull Request resource:
https://godoc.org/github.com/jenkins-x/go-scm/scm#State

#### Pull Request

The `pullRequest` resource will look for GitHub or GitLab OAuth authentication
tokens in spec secrets with a field name called `authToken`.

URLs should be of the form: https://github.com/tektoncd/pipeline/pull/1

#### Self hosted / Enterprise instances

The PullRequest resource works with self hosted or enterprise GitHub/GitLab
instances. Simply provide the pull request URL and set the `provider` parameter.
If you need to skip certificate validation set the `insecure-skip-tls-verify`
parameter to `"true"`.

```yaml
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: wizzbang-pr
namespace: default
spec:
type: pullRequest
params:
- name: url
value: https://github.example.com/wizzbangcorp/wizzbang/pulls/1
- name: provider
value: github
```

### Image Resource

An `image` resource represents an image that lives in a remote repository. It is
Expand Down
10 changes: 0 additions & 10 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ variable via `resources.inputs.<resourceName>.<variableName>` or
| `httpsProxy` | The value of the resource's `httpsProxy` parameter. |
| `noProxy` | The value of the resource's `noProxy` parameter. |

#### Variables for the `PullRequest` type

| Variable | Description |
| -------- | ----------- |
| `name` | The name of the resource. |
| `type` | Type value of `"pullRequest"`.|
| `url` | The URL of the pull request. |
| `provider` | Provider value, either `"github"` or `"gitlab"`. |
| `insecure-skip-tls-verify` | The value of the resource's `insecure-skip-tls-verify` parameter, either `"true"` or `"false"`. |

#### Variables for the `Image` type

| Variable | Description |
Expand Down
35 changes: 0 additions & 35 deletions examples/v1beta1/taskruns/pullrequest.yaml

This file was deleted.

50 changes: 0 additions & 50 deletions examples/v1beta1/taskruns/pullrequest_input_copystep_output.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/apis/pipeline/v1beta1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ const (

// PipelineResourceTypeImage indicates that this source is a docker Image.
PipelineResourceTypeImage PipelineResourceType = resource.PipelineResourceTypeImage

// PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request.
PipelineResourceTypePullRequest PipelineResourceType = resource.PipelineResourceTypePullRequest
)

// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
5 changes: 1 addition & 4 deletions pkg/apis/resource/v1alpha1/pipeline_resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ const (
// PipelineResourceTypeImage indicates that this source is a docker Image.
PipelineResourceTypeImage PipelineResourceType = "image"

// PipelineResourceTypePullRequest indicates that this source is a SCM Pull Request.
PipelineResourceTypePullRequest PipelineResourceType = "pullRequest"

// PipelineResourceTypeGCS is the subtype for the GCSResources, which is backed by a GCS blob/directory.
PipelineResourceTypeGCS PipelineResourceType = "gcs"
)

// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage, PipelineResourceTypePullRequest}
var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 0 additions & 16 deletions pkg/apis/resource/v1alpha1/pipelineresource_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
"context"
"fmt"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/validate"
Expand Down Expand Up @@ -67,12 +66,6 @@ func (rs *PipelineResourceSpec) Validate(ctx context.Context) *apis.FieldError {
}
}

if rs.Type == PipelineResourceTypePullRequest {
if err := validatePullRequest(rs); err != nil {
return err
}
}

for _, allowedType := range AllResourceTypes {
if allowedType == rs.Type {
return nil
Expand All @@ -86,12 +79,3 @@ func (rs *PipelineResourceSpec) Validate(ctx context.Context) *apis.FieldError {
func AllowedStorageType(gotType string) bool {
return gotType == PipelineResourceTypeGCS
}

func validatePullRequest(s *PipelineResourceSpec) *apis.FieldError {
for _, param := range s.SecretParams {
if param.FieldName != "authToken" {
return apis.ErrInvalidValue(fmt.Sprintf("invalid field name %q in secret parameter. Expected %q", param.FieldName, "authToken"), "spec.secrets.fieldName")
}
}
return nil
}
40 changes: 0 additions & 40 deletions pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ func TestResourceValidation_Invalid(t *testing.T) {
},
},
want: apis.ErrMissingField("spec.type"),
}, {
name: "pull request with invalid field name in secrets",
res: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypePullRequest,
SecretParams: []v1alpha1.SecretParam{{
FieldName: "INVALID_FIELD_NAME",
}},
},
},
want: apis.ErrInvalidValue("invalid field name \"INVALID_FIELD_NAME\" in secret parameter. Expected \"authToken\"", "spec.secrets.fieldName"),
},
}
for _, tt := range tests {
Expand All @@ -136,32 +122,6 @@ func TestResourceValidation_Invalid(t *testing.T) {
}
}

func TestResourceValidation_Valid(t *testing.T) {
tests := []struct {
name string
res *v1alpha1.PipelineResource
}{
{
name: "specify pullrequest with no secrets",
res: &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "temp",
},
Spec: v1alpha1.PipelineResourceSpec{
Type: v1alpha1.PipelineResourceTypePullRequest,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.res.Validate(context.Background()); err != nil {
t.Errorf("Unexpected PipelineRun.Validate() error = %v", err)
}
})
}
}

func TestAllowedGCSStorageType(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading

0 comments on commit 3dd6180

Please sign in to comment.