4
4
"context"
5
5
"fmt"
6
6
"net/url"
7
- "strings "
7
+ "path "
8
8
9
9
"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher"
10
10
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
@@ -21,24 +21,14 @@ func alreadyFetchedResource[T NamedItem](resources map[string]T, resourceName st
21
21
return false
22
22
}
23
23
24
- func createTaskURL (eventPipelines map [string ]* tektonv1.Pipeline , pipeline * tektonv1.Pipeline , tasks []string ) ([]string , error ) {
25
- var pURL * url.URL
26
- var err error
27
- for ep := range eventPipelines {
28
- // ensure the URL to be parsed matches the
29
- // remote pipeline of the current PipelineRun
30
- if eventPipelines [ep ] != pipeline {
31
- continue
32
- }
33
- pURL , err = url .Parse (ep )
34
- if err != nil {
35
- return tasks , err
36
- }
37
- pPath := strings .SplitAfter (pURL .Path , "/" )
38
- // pop the pipeline target path from the URL
39
- pPath = pPath [:len (pPath )- 1 ]
40
- pURL .Path = strings .Join (pPath , "" )
24
+ func assembleTaskFQDNs (remotePipelineURL string , tasks []string ) ([]string , error ) {
25
+ pURL , err := url .Parse (remotePipelineURL )
26
+ if err != nil {
27
+ return tasks , err
41
28
}
29
+ // pop the pipeline file path from the URL
30
+ pURL .Path = path .Dir (pURL .Path )
31
+
42
32
taskURLS := make ([]string , len (tasks ))
43
33
for i , t := range tasks {
44
34
tURL , err := url .Parse (t )
@@ -68,8 +58,9 @@ func createTaskURL(eventPipelines map[string]*tektonv1.Pipeline, pipeline *tekto
68
58
func resolveRemoteResources (ctx context.Context , rt * matcher.RemoteTasks , types TektonTypes , ropt * Opts ) ([]* tektonv1.PipelineRun , error ) {
69
59
// contain Resources fetched for the event
70
60
fetchedResourcesForEvent := FetchedResources {
71
- Tasks : map [string ]* tektonv1.Task {},
72
- Pipelines : map [string ]* tektonv1.Pipeline {},
61
+ Tasks : map [string ]* tektonv1.Task {},
62
+ Pipelines : map [string ]* tektonv1.Pipeline {},
63
+ PipelineURLs : []string {},
73
64
}
74
65
pipelineRuns := []* tektonv1.PipelineRun {}
75
66
for _ , pipelinerun := range types .PipelineRuns {
@@ -110,6 +101,7 @@ func resolveRemoteResources(ctx context.Context, rt *matcher.RemoteTasks, types
110
101
}
111
102
// add the pipeline to the Resources fetched for the Event
112
103
fetchedResourcesForEvent .Pipelines [remotePipeline ] = pipeline
104
+ fetchedResourcesForEvent .PipelineURLs = append (fetchedResourcesForEvent .PipelineURLs , remotePipeline )
113
105
}
114
106
}
115
107
}
@@ -132,8 +124,11 @@ func resolveRemoteResources(ctx context.Context, rt *matcher.RemoteTasks, types
132
124
if err != nil {
133
125
return []* tektonv1.PipelineRun {}, fmt .Errorf ("error getting remote task from pipeline annotations: %w" , err )
134
126
}
127
+ // this will always work because the slice cannot be empty (there is a check
128
+ // for empty strings; even with an empty string it will work), and cannot be nil
129
+ remotePipelineURL := fetchedResourcesForEvent .PipelineURLs [len (fetchedResourcesForEvent .PipelineURLs )- 1 ]
135
130
// check for relative task references and assemble FQDNs
136
- pipelineTasks , err = createTaskURL ( fetchedResourcesForEvent . Pipelines , fetchedResourcesForPipelineRun . Pipeline , pipelineTasks )
131
+ pipelineTasks , err = assembleTaskFQDNs ( remotePipelineURL , pipelineTasks )
137
132
if err != nil {
138
133
return []* tektonv1.PipelineRun {}, err
139
134
}
0 commit comments