@@ -60,7 +60,7 @@ func (a *APIRouter) GetPipelines(w http.ResponseWriter, r *http.Request) {
60
60
61
61
// TODO: replace this with logr or sugar.
62
62
log .Printf ("urlToFetch = %#v\n " , urlToFetch )
63
- repo , err := parseURL (urlToFetch )
63
+ repo , parsedRepo , err := parseURL (urlToFetch )
64
64
if err != nil {
65
65
log .Printf ("ERROR: failed to parse the URL: %s" , err )
66
66
http .Error (w , err .Error (), http .StatusBadRequest )
@@ -85,7 +85,7 @@ func (a *APIRouter) GetPipelines(w http.ResponseWriter, r *http.Request) {
85
85
// Add a "not found" error that can be returned, otherwise it's a
86
86
// StatusInternalServerError.
87
87
log .Println ("got an authenticated client" )
88
- body , err := client .FileContents (r .Context (), repo , "pipelines.yaml" , refFromQuery (r . URL .Query ()))
88
+ body , err := client .FileContents (r .Context (), repo , "pipelines.yaml" , refFromQuery (parsedRepo .Query ()))
89
89
if err != nil {
90
90
log .Printf ("ERROR: failed to get file contents for repo %#v: %s" , repo , err )
91
91
http .Error (w , err .Error (), http .StatusBadRequest )
@@ -114,7 +114,7 @@ func (a *APIRouter) GetApplication(w http.ResponseWriter, r *http.Request) {
114
114
115
115
// TODO: replace this with logr or sugar.
116
116
log .Printf ("urlToFetch = %#v\n " , urlToFetch )
117
- repo , err := parseURL (urlToFetch )
117
+ repo , parsedRepo , err := parseURL (urlToFetch )
118
118
if err != nil {
119
119
log .Printf ("ERROR: failed to parse the URL: %s" , err )
120
120
http .Error (w , err .Error (), http .StatusBadRequest )
@@ -138,7 +138,7 @@ func (a *APIRouter) GetApplication(w http.ResponseWriter, r *http.Request) {
138
138
//
139
139
// Add a "not found" error that can be returned, otherwise it's a
140
140
// StatusInternalServerError.
141
- body , err := client .FileContents (r .Context (), repo , "pipelines.yaml" , refFromQuery (r . URL .Query ()))
141
+ body , err := client .FileContents (r .Context (), repo , "pipelines.yaml" , refFromQuery (parsedRepo .Query ()))
142
142
if err != nil {
143
143
log .Printf ("ERROR: failed to get file contents for repo %#v: %s" , repo , err )
144
144
http .Error (w , err .Error (), http .StatusBadRequest )
@@ -179,12 +179,12 @@ func (a *APIRouter) getAuthenticatedGitClient(fetchURL, token string) (git.SCM,
179
179
return a .gitClientFactory .Create (fetchURL , token )
180
180
}
181
181
182
- func parseURL (s string ) (string , error ) {
182
+ func parseURL (s string ) (string , * url. URL , error ) {
183
183
parsed , err := url .Parse (s )
184
184
if err != nil {
185
- return "" , fmt .Errorf ("failed to parse %#v: %w" , s , err )
185
+ return "" , nil , fmt .Errorf ("failed to parse %#v: %w" , s , err )
186
186
}
187
- return strings .TrimLeft (strings .TrimSuffix (parsed .Path , ".git" ), "/" ), nil
187
+ return strings .TrimLeft (strings .TrimSuffix (parsed .Path , ".git" ), "/" ), parsed , nil
188
188
}
189
189
190
190
func secretRefFromQuery (v url.Values ) (types.NamespacedName , bool ) {
0 commit comments