in internal/pkg/deploy/pipeline.go [219:294]
func PipelineSourceFromManifest(mfSource *manifest.Source) (source interface{}, shouldPrompt bool, err error) {
branch, err := convertOptionalProperty(mfSource.Properties, "branch", DefaultPipelineBranch)
if err != nil {
return nil, false, err
}
repository, err := convertRequiredProperty(mfSource.Properties, "repository")
if err != nil {
return nil, false, err
}
outputFormat, err := convertOptionalProperty(mfSource.Properties, "output_artifact_format", "")
if err != nil {
return nil, false, err
}
switch mfSource.ProviderName {
case manifest.GithubV1ProviderName:
token, err := convertRequiredProperty(mfSource.Properties, "access_token_secret")
if err != nil {
return nil, false, err
}
return &GitHubV1Source{
ProviderName: manifest.GithubV1ProviderName,
Branch: branch,
RepositoryURL: GitHubURL(repository),
PersonalAccessTokenSecretID: token,
}, false, nil
case manifest.GithubProviderName:
// If the creation of the user's pipeline manifest predates Copilot's conversion to GHv2/CSC, the provider
// listed in the manifest will be "GitHub," not "GitHubV1." To differentiate it from the new default
// "GitHub," which refers to v2, we check for the presence of a secret, indicating a v1 GitHub connection.
if mfSource.Properties["access_token_secret"] != nil {
return &GitHubV1Source{
ProviderName: manifest.GithubV1ProviderName,
Branch: branch,
RepositoryURL: GitHubURL(repository),
PersonalAccessTokenSecretID: (mfSource.Properties["access_token_secret"]).(string),
}, false, nil
} else {
// If an existing CSC connection is being used, don't prompt to update connection from 'PENDING' to 'AVAILABLE'.
connection, ok := mfSource.Properties["connection_arn"]
repo := &GitHubSource{
ProviderName: manifest.GithubProviderName,
Branch: branch,
RepositoryURL: GitHubURL(repository),
OutputArtifactFormat: outputFormat,
}
if !ok {
return repo, true, nil
}
repo.ConnectionARN = connection.(string)
return repo, false, nil
}
case manifest.CodeCommitProviderName:
return &CodeCommitSource{
ProviderName: manifest.CodeCommitProviderName,
Branch: branch,
RepositoryURL: repository,
OutputArtifactFormat: outputFormat,
}, false, nil
case manifest.BitbucketProviderName:
// If an existing CSC connection is being used, don't prompt to update connection from 'PENDING' to 'AVAILABLE'.
connection, ok := mfSource.Properties["connection_arn"]
repo := &BitbucketSource{
ProviderName: manifest.BitbucketProviderName,
Branch: branch,
RepositoryURL: repository,
OutputArtifactFormat: outputFormat,
}
if !ok {
return repo, true, nil
}
repo.ConnectionARN = connection.(string)
return repo, false, nil
default:
return nil, false, fmt.Errorf("invalid repo source provider: %s", mfSource.ProviderName)
}
}