-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move gitops function to Build Service and remove dependency on Applic…
…ation Service (#283)
- Loading branch information
Showing
18 changed files
with
560 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
|
@@ -43,6 +44,50 @@ import ( | |
// That way it can be mocked in tests | ||
var DevfileSearchForDockerfile = devfile.SearchForDockerfile | ||
|
||
// getGitProvider returns git provider name based on the repository url, e.g. github, gitlab, etc or git-privider annotation | ||
func getGitProvider(component appstudiov1alpha1.Component) (string, error) { | ||
allowedGitProviders := map[string]bool{"github": true, "gitlab": true, "bitbucket": true} | ||
gitProvider := "" | ||
|
||
sourceUrl := component.Spec.Source.GitSource.URL | ||
|
||
if strings.HasPrefix(sourceUrl, "git@") { | ||
// [email protected]:redhat-appstudio/application-service.git | ||
sourceUrl = strings.TrimPrefix(sourceUrl, "git@") | ||
host := strings.Split(sourceUrl, ":")[0] | ||
gitProvider = strings.Split(host, ".")[0] | ||
} else { | ||
// https://github.com/redhat-appstudio/application-service | ||
u, err := url.Parse(sourceUrl) | ||
if err != nil { | ||
return "", err | ||
} | ||
uParts := strings.Split(u.Hostname(), ".") | ||
if len(uParts) == 1 { | ||
gitProvider = uParts[0] | ||
} else { | ||
gitProvider = uParts[len(uParts)-2] | ||
} | ||
} | ||
|
||
var err error | ||
if !allowedGitProviders[gitProvider] { | ||
// Self-hosted git provider, check for git-provider annotation on the component | ||
gitProviderAnnotationValue := component.GetAnnotations()[GitProviderAnnotationName] | ||
if gitProviderAnnotationValue != "" { | ||
if allowedGitProviders[gitProviderAnnotationValue] { | ||
gitProvider = gitProviderAnnotationValue | ||
} else { | ||
err = fmt.Errorf("unsupported \"%s\" annotation value: %s", GitProviderAnnotationName, gitProviderAnnotationValue) | ||
} | ||
} else { | ||
err = fmt.Errorf("self-hosted git provider is not specified via \"%s\" annotation in the component", GitProviderAnnotationName) | ||
} | ||
} | ||
|
||
return gitProvider, err | ||
} | ||
|
||
// GetPipelineForComponent searches for the build pipeline to use on the component. | ||
func (r *ComponentBuildReconciler) GetPipelineForComponent(ctx context.Context, component *appstudiov1alpha1.Component) (*tektonapi.PipelineRef, []tektonapi.Param, error) { | ||
var pipelineSelectors []buildappstudiov1alpha1.BuildPipelineSelector | ||
|
Oops, something went wrong.