Skip to content

Commit

Permalink
address comments from review of pr/91
Browse files Browse the repository at this point in the history
  • Loading branch information
nader-ziada authored and knative-prow-robot committed Oct 4, 2018
1 parent c108f3e commit 70b951d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/pipeline-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ spec:
params:
- name: url
value: github.com/wizzbangcorp/wizzbang
- name: Revision
value: master
- name: ServiceAccount
value: pipeline-sa
```

Params that can be added are the following:
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"fmt"
"strings"
)

Expand All @@ -34,8 +35,11 @@ type GitResource struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// NewGitResource create a new git resource to pass to Knativve Build
func NewGitResource(r *PipelineResource) *GitResource {
// NewGitResource create a new git resource to pass to Knative Build
func NewGitResource(r *PipelineResource) (*GitResource, error) {
if r.Spec.Type != PipelineResourceTypeGit {
return nil, fmt.Errorf("GitResource: Cannot create a Git resource from a %s Pipeline Resource", r.Spec.Type)
}
gitResource := GitResource{
Name: r.Name,
Type: r.Spec.Type,
Expand All @@ -50,7 +54,11 @@ func NewGitResource(r *PipelineResource) *GitResource {
gitResource.Revision = param.Value
}
}
return &gitResource
// default revision to master is nothing is provided
if gitResource.Revision == "" {
gitResource.Revision = "master"
}
return &gitResource, nil
}

// GetName returns the name of the resource
Expand Down
52 changes: 52 additions & 0 deletions pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,58 @@ func TestAddResourceToBuild(t *testing.T) {
},
},
},
}, {
desc: "simple with branch",
task: task,
taskRun: &v1alpha1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "build-from-repo-run",
Namespace: "marshmallow",
},
Spec: v1alpha1.TaskRunSpec{
TaskRef: v1alpha1.TaskRef{
Name: "simpleTask",
},
Inputs: v1alpha1.TaskRunInputs{
Resources: []v1alpha1.PipelineResourceVersion{
v1alpha1.PipelineResourceVersion{
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "workspace",
},
Version: "branch",
},
},
},
},
},
build: build,
wantErr: false,
want: &buildv1alpha1.Build{
TypeMeta: metav1.TypeMeta{
Kind: "Build",
APIVersion: "build.knative.dev/v1alpha1"},
ObjectMeta: metav1.ObjectMeta{
Name: "build-from-repo",
Namespace: "marshmallow",
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "pipeline.knative.dev/v1alpha1",
Kind: "TaskRun",
Name: "build-from-repo-run",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
},
},
},
Spec: buildv1alpha1.BuildSpec{
Source: &buildv1alpha1.SourceSpec{
Git: &buildv1alpha1.GitSourceSpec{
Url: "https://github.com/grafeas/kritis",
Revision: "branch",
},
},
},
},
}, {
desc: "set revision to default value",
task: task,
Expand Down
15 changes: 8 additions & 7 deletions pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ func AddInputResource(
for _, input := range task.Spec.Inputs.Sources {
resource, err := pipelineResourceLister.PipelineResources(task.Namespace).Get(input.Name)
if err != nil {

logger.Errorf("Failed to reconcile TaskRun: %q failed to Get Pipeline Resource: %q", task.Name, input.Name)
return nil, err
}
if resource.Spec.Type == v1alpha1.PipelineResourceTypeGit {
gitResource = v1alpha1.NewGitResource(resource)
gitResource, err = v1alpha1.NewGitResource(resource)
if err != nil {
logger.Errorf("Failed to reconcile TaskRun: %q Invalid Pipeline Resource: %q", task.Name, input.Name)
return nil, err
}
for _, trInput := range taskRun.Spec.Inputs.Resources {
if trInput.ResourceRef.Name == input.Name {
gitResource.Revision = trInput.Version
if trInput.Version != "" {
gitResource.Revision = trInput.Version
}
break
}
}
break
}
}
// default revision to master is nothing is provided
if gitResource.Revision == "" {
gitResource.Revision = "master"
}

gitSourceSpec := &buildv1alpha1.GitSourceSpec{
Url: gitResource.URL,
Expand Down

0 comments on commit 70b951d

Please sign in to comment.