mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
1889 lines
66 KiB
Go
1889 lines
66 KiB
Go
package scm_provider
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
)
|
|
|
|
func gitlabMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
|
t.Helper()
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
switch r.RequestURI {
|
|
case "/api/v4":
|
|
case "/api/v4/groups/test-cd-proton/projects?include_subgroups=false&per_page=100", "/api/v4/groups/test-cd-proton/projects?include_subgroups=false&per_page=100&topic=&with_shared=false", "/api/v4/groups/test-cd-proton/projects?archived=false&include_subgroups=false&per_page=100", "/api/v4/groups/test-cd-proton/projects?archived=false&include_subgroups=false&per_page=100&topic=&with_shared=false":
|
|
_, err := io.WriteString(w, `[{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084533",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084533/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084533/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/groups/test-cd-proton/projects?archived=true&include_subgroups=false&per_page=100", "/api/v4/groups/test-cd-proton/projects?archived=true&include_subgroups=false&per_page=100&topic=&with_shared=false":
|
|
_, err := io.WriteString(w, `[{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [],
|
|
"topics": [],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084533",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084533/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084533/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
},
|
|
{
|
|
"id": 56522142,
|
|
"description": "",
|
|
"name": "another-repo",
|
|
"name_with_namespace": "test cd proton / another-repo",
|
|
"path": "another-repo",
|
|
"path_with_namespace": "test-cd-proton/another-repo",
|
|
"created_at": "2022-09-13T12:10:14.722Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/another-repo.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/another-repo.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/another-repo",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/another-repo",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/56522142",
|
|
"issues": "https://gitlab.com/api/v4/projects/56522142/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/56522142/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/56522142/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/56522142/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/56522142/events",
|
|
"members": "https://gitlab.com/api/v4/projects/56522142/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/56522142/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": true,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/groups/test-cd-proton/projects?include_subgroups=true&per_page=100&topic=&with_shared=false":
|
|
_, err := io.WriteString(w, `[{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic",
|
|
"specific-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic",
|
|
"specific-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084533",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084533/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084533/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
},
|
|
{
|
|
"id": 27084538,
|
|
"description": "This is a Project from a Subgroup",
|
|
"name": "cd-subgroup",
|
|
"name_with_namespace": "test cd proton / subgroup / cd-subgroup",
|
|
"path": "cd-subgroup",
|
|
"path_with_namespace": "test-cd-proton/subgroup/cd-subgroup",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/subgroup/cd-subgroup.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258542,
|
|
"name": "subgroup",
|
|
"path": "subgroup",
|
|
"kind": "group ",
|
|
"full_path ": "test-cd-proton/subgroup",
|
|
"parent_id ": 12258515,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton/subgroup"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/subgroup/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084538",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084538/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084538/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084538/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084538/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084538/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084538/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084538/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
}
|
|
]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/groups/test-cd-proton/projects?include_subgroups=false&per_page=100&topic=specific-topic&with_shared=false":
|
|
_, err := io.WriteString(w, `[{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic",
|
|
"specific-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic",
|
|
"specific-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084533",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084533/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084533/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
}
|
|
]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/groups/test-cd-proton/projects?include_subgroups=true&per_page=100&topic=&with_shared=true":
|
|
_, err := io.WriteString(w, `[{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "gro* Connection #0 to host gitlab.com left intact up ",
|
|
"full_path ": "test - cd - proton ",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-cd-proton/cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084533",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084533/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084533/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-02T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
},
|
|
{
|
|
"id": 27084534,
|
|
"description": "This is a Shared Project",
|
|
"name": "shared-cd",
|
|
"name_with_namespace": "shared project to test cd proton / cd",
|
|
"path": "shared-cd",
|
|
"path_with_namespace": "test-shared-cd-proton/shared-cd",
|
|
"created_at": "2021-06-11T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-shared-cd-proton/shared-cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-shared-cd-proton/shared-cd.git",
|
|
"web_url": "https://gitlab.com/test-shared-cd-proton/shared-cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258518,
|
|
"name": "test shared cd proton",
|
|
"path": "test-shared-cd-proton",
|
|
"kind": "group",
|
|
"full_path ": "test-shared-cd-proton",
|
|
"parent_id ": null,
|
|
"avatar_url ": null,
|
|
"web_url ": "https: //gitlab.com/groups/test-shared-cd-proton"
|
|
},
|
|
"container_registry_image_prefix": "registry.gitlab.com/test-shared-cd-proton/shared-cd",
|
|
"_links": {
|
|
"self": "https://gitlab.com/api/v4/projects/27084534",
|
|
"issues": "https://gitlab.com/api/v4/projects/27084534/issues",
|
|
"merge_requests": "https://gitlab.com/api/v4/projects/27084534/merge_requests",
|
|
"repo_branches": "https://gitlab.com/api/v4/projects/27084534/repository/branches",
|
|
"labels": "https://gitlab.com/api/v4/projects/27084534/labels",
|
|
"events": "https://gitlab.com/api/v4/projects/27084534/events",
|
|
"members": "https://gitlab.com/api/v4/projects/27084534/members",
|
|
"cluster_agents": "https://gitlab.com/api/v4/projects/27084534/cluster_agents"
|
|
},
|
|
"packages_enabled": true,
|
|
"empty_repo": false,
|
|
"archived": false,
|
|
"visibility": "public",
|
|
"resolve_outdated_diff_discussions": false,
|
|
"container_expiration_policy": {
|
|
"cadence": "1d",
|
|
"enabled": false,
|
|
"keep_n": 10,
|
|
"older_than": "90d",
|
|
"name_regex": ".*",
|
|
"name_regex_keep": null,
|
|
"next_run_at": "2021-06-12T17:30:44.740Z"
|
|
},
|
|
"issues_enabled": true,
|
|
"merge_requests_enabled": true,
|
|
"wiki_enabled": true,
|
|
"jobs_enabled": true,
|
|
"snippets_enabled": true,
|
|
"container_registry_enabled": true,
|
|
"service_desk_enabled": true,
|
|
"can_create_merge_request_in": false,
|
|
"issues_access_level": "enabled",
|
|
"repository_access_level": "enabled",
|
|
"merge_requests_access_level": "enabled",
|
|
"forking_access_level": "enabled",
|
|
"wiki_access_level": "enabled",
|
|
"builds_access_level": "enabled",
|
|
"snippets_access_level": "enabled",
|
|
"pages_access_level": "enabled",
|
|
"operations_access_level": "enabled",
|
|
"analytics_access_level": "enabled",
|
|
"container_registry_access_level": "enabled",
|
|
"security_and_compliance_access_level": "private",
|
|
"emails_disabled": null,
|
|
"shared_runners_enabled": true,
|
|
"lfs_enabled": true,
|
|
"creator_id": 2378866,
|
|
"import_status": "none",
|
|
"open_issues_count": 0,
|
|
"ci_default_git_depth": 50,
|
|
"ci_forward_deployment_enabled": true,
|
|
"ci_job_token_scope_enabled": false,
|
|
"public_jobs": true,
|
|
"build_timeout": 3600,
|
|
"auto_cancel_pending_pipelines": "enabled",
|
|
"ci_config_path": "",
|
|
"shared_with_groups": [
|
|
{
|
|
"group_id": 12258515,
|
|
"group_name": "test-cd-proton",
|
|
"group_full_path": "test-shared-cd-proton",
|
|
"group_access_level": 30,
|
|
"expires_at": null
|
|
}
|
|
],
|
|
"only_allow_merge_if_pipeline_succeeds": false,
|
|
"allow_merge_on_skipped_pipeline": null,
|
|
"restrict_user_defined_variables": false,
|
|
"request_access_enabled": true,
|
|
"only_allow_merge_if_all_discussions_are_resolved": false,
|
|
"remove_source_branch_after_merge": true,
|
|
"printing_merge_request_link_enabled": true,
|
|
"merge_method": "merge",
|
|
"squash_option": "default_off",
|
|
"suggestion_commit_message": null,
|
|
"merge_commit_template": null,
|
|
"squash_commit_template": null,
|
|
"auto_devops_enabled": false,
|
|
"auto_devops_deploy_strategy": "continuous",
|
|
"autoclose_referenced_issues": true,
|
|
"keep_latest_artifact": true,
|
|
"runner_token_expiration_interval": null,
|
|
"approvals_before_merge": 0,
|
|
"mirror": false,
|
|
"external_authorization_classification_label": "",
|
|
"marked_for_deletion_at": null,
|
|
"marked_for_deletion_on": null,
|
|
"requirements_enabled": true,
|
|
"requirements_access_level": "enabled",
|
|
"security_and_compliance_enabled": false,
|
|
"compliance_frameworks": [],
|
|
"issues_template": null,
|
|
"merge_requests_template": null,
|
|
"merge_pipelines_enabled": false,
|
|
"merge_trains_enabled": false
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084533/repository/branches/master":
|
|
_, err := io.WriteString(w, `{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
"short_id": "8898d799",
|
|
"created_at": "2021-06-04T08:24:44.000+00:00",
|
|
"parent_ids": ["3c9d50be1ef949ad28674e238c7e12a17b1e9706", "56482e001731640b4123cf177e51c696f08a3005"],
|
|
"title": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-1317911429' into 'master'\n\n[testapp-ci] manifests/demo/test-app.yaml: release v1.1.0\n\nSee merge request test-cd-proton/cd!3",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-04T08:24:44.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-04T08:24:44.000+00:00",
|
|
"trailers": {},
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/tree/master"
|
|
}`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/56522142/repository/branches/master":
|
|
_, err := io.WriteString(w, `{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "9998d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
"short_id": "9998d799",
|
|
"created_at": "2023-08-04T08:14:14.000+00:00",
|
|
"parent_ids": ["5d9d50be1ef949ad28674e238c7e12a17b1e9706", "99482e001731640b4123cf177e51c696f08a3005"],
|
|
"title": "Merge branch 'pipeline-4547911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-4547911429' into 'master'\n\n[testapp-ci] manifests/demo/test-app.yaml: release v1.2.0\n\nSee merge request test-cd-proton/cd!3",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2023-08-04T08:14:14.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2023-08-04T08:14:14.000+00:00",
|
|
"trailers": {},
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/commit/9998d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/tree/master"
|
|
}`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084533/repository/branches?per_page=100":
|
|
_, err := io.WriteString(w, `[{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
"short_id": "8898d799",
|
|
"created_at": "2021-06-04T08:24:44.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-04T08:24:44.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-04T08:24:44.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/tree/master"
|
|
}, {
|
|
"name": "pipeline-1310077506",
|
|
"commit": {
|
|
"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
|
|
"short_id": "0f92540e",
|
|
"created_at": "2021-06-01T18:39:59.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"author_name": "ci-test-app",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-01T18:39:59.000+00:00",
|
|
"committer_name": "ci-test-app",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-01T18:39:59.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
|
|
},
|
|
"merged": false,
|
|
"protected": false,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": false,
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd/-/tree/pipeline-1310077506"
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084534/repository/branches?per_page=100":
|
|
_, err := io.WriteString(w, `[{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
"short_id": "8898d799",
|
|
"created_at": "2021-06-04T08:24:44.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-04T08:24:44.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-04T08:24:44.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-shared-cd-proton/shared-cd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-shared-cd-proton/shared-cd/-/tree/master"
|
|
}, {
|
|
"name": "pipeline-2310077506",
|
|
"commit": {
|
|
"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
|
|
"short_id": "0f92540e",
|
|
"created_at": "2021-06-01T18:39:59.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"author_name": "ci-test-app",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-01T18:39:59.000+00:00",
|
|
"committer_name": "ci-test-app",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-01T18:39:59.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-shared-cd-proton/shared-cd/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
|
|
},
|
|
"merged": false,
|
|
"protected": false,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": false,
|
|
"web_url": "https://gitlab.com/test-shared-cd-proton/shared-cd/-/tree/pipeline-1310077506"
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084538/repository/branches?per_page=100":
|
|
_, err := io.WriteString(w, `[{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "8898d7999fc99dd0fd578650b58b244fc63f6b58",
|
|
"short_id": "8898d801",
|
|
"created_at": "2021-06-04T08:24:44.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-04T08:24:44.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-04T08:24:44.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/tree/master"
|
|
}, {
|
|
"name": "pipeline-2310077506",
|
|
"commit": {
|
|
"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
|
|
"short_id": "0f92540e",
|
|
"created_at": "2021-06-01T18:39:59.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"author_name": "ci-test-app",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-01T18:39:59.000+00:00",
|
|
"committer_name": "ci-test-app",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-01T18:39:59.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
|
|
},
|
|
"merged": false,
|
|
"protected": false,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": false,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/tree/pipeline-1310077506"
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/56522142/repository/branches?per_page=100":
|
|
_, err := io.WriteString(w, `[{
|
|
"name": "master",
|
|
"commit": {
|
|
"id": "8898d8889fc99dd0fd578650b58b244fc63f6b58",
|
|
"short_id": "8898d801",
|
|
"created_at": "2021-06-04T08:24:44.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"message": "Merge branch 'pipeline-1317911429' into 'master'",
|
|
"author_name": "Martin Vozník",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-04T08:24:44.000+00:00",
|
|
"committer_name": "Martin Vozník",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-04T08:24:44.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
|
|
},
|
|
"merged": false,
|
|
"protected": true,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": true,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/tree/master"
|
|
}, {
|
|
"name": "pipeline-2310077506",
|
|
"commit": {
|
|
"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
|
|
"short_id": "0f92540e",
|
|
"created_at": "2021-06-01T18:39:59.000+00:00",
|
|
"parent_ids": null,
|
|
"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
|
|
"author_name": "ci-test-app",
|
|
"author_email": "[email protected]",
|
|
"authored_date": "2021-06-01T18:39:59.000+00:00",
|
|
"committer_name": "ci-test-app",
|
|
"committer_email": "[email protected]",
|
|
"committed_date": "2021-06-01T18:39:59.000+00:00",
|
|
"trailers": null,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
|
|
},
|
|
"merged": false,
|
|
"protected": false,
|
|
"developers_can_push": false,
|
|
"developers_can_merge": false,
|
|
"can_push": false,
|
|
"default": false,
|
|
"web_url": "https://gitlab.com/test-cd-proton/subgroup/cd-subgroup/-/tree/pipeline-1310077506"
|
|
}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/test-cd-proton%2Fcd":
|
|
_, err := io.WriteString(w, `{
|
|
"id": 27084533,
|
|
"description": "",
|
|
"name": "cd",
|
|
"name_with_namespace": "test cd proton / cd",
|
|
"path": "cd",
|
|
"path_with_namespace": "test-cd-proton/cd",
|
|
"created_at": "2021-06-01T17:30:44.724Z",
|
|
"default_branch": "master",
|
|
"tag_list": [
|
|
"test-topic"
|
|
],
|
|
"topics": [
|
|
"test-topic"
|
|
],
|
|
"ssh_url_to_repo": "[email protected]:test-cd-proton/cd.git",
|
|
"http_url_to_repo": "https://gitlab.com/test-cd-proton/cd.git",
|
|
"web_url": "https://gitlab.com/test-cd-proton/cd",
|
|
"readme_url": null,
|
|
"avatar_url": null,
|
|
"forks_count": 0,
|
|
"star_count": 0,
|
|
"last_activity_at": "2021-06-04T08:19:51.656Z",
|
|
"namespace": {
|
|
"id": 12258515,
|
|
"name": "test cd proton",
|
|
"path": "test-cd-proton",
|
|
"kind": "group",
|
|
"full_path": "test-cd-proton",
|
|
"parent_id": null,
|
|
"avatar_url": null,
|
|
"web_url": "https://gitlab.com/groups/test-cd-proton"
|
|
}
|
|
}`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084533/repository/tree?path=cd&ref=master":
|
|
_, err := io.WriteString(w, `[{"id":"ca14f2a3718159c74572a5325fb4bfb0662a2d3e","name":"ingress.yaml","type":"blob","path":"cd/ingress.yaml","mode":"100644"},{"id":"de2a53a73b1550b3e0f4d37ea0a6d878bf9c5096","name":"install.yaml","type":"blob","path":"cd/install.yaml","mode":"100644"}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084533/repository/tree?path=.&ref=master":
|
|
_, err := io.WriteString(w, `[{"id":"f2bf99fa8f7a27df9c43d2dffc8c8cd747f3181a","name":"cd","type":"tree","path":"cd","mode":"040000"},{"id":"68a3125232e01c1583a6a6299534ce10c5e7dd83","name":"manifests","type":"tree","path":"manifests","mode":"040000"}]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
// Recent versions of the Gitlab API (v17.7+) listTree return 404 not only when a file doesn't exist, but also
|
|
// when a path is to a file instead of a directory. Code was refactored to explicitly search for file then
|
|
// search for directory, catching 404 errors as "file not found".
|
|
case "/api/v4/projects/27084533/repository/files/cd?ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/files/cd%2Finstall%2Eyaml?ref=master":
|
|
_, err := io.WriteString(w, `{"file_name":"install.yaml","file_path":"cd/install.yaml","size":0,"encoding":"base64","content_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","ref":"main","blob_id":"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391","commit_id":"6d4c0f9d34534ccc73aa3f3180b25e2aebe630eb","last_commit_id":"b50eb63f9c0e09bfdb070db26fd32c7210291f52","execute_filemode":false,"content":""}`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
case "/api/v4/projects/27084533/repository/files/notathing?ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/tree?path=notathing&ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/files/cd%2Fnotathing%2Eyaml?ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/tree?path=cd%2Fnotathing.yaml&ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/files/notathing%2Fnotathing%2Eyaml?ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/tree?path=notathing%2Fnotathing.yaml&ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/files/notathing%2Fnotathing%2Fnotathing%2Eyaml?ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/tree?path=notathing%2Fnotathing%2Fnotathing.yaml&ref=master":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
case "/api/v4/projects/27084533/repository/branches/foo":
|
|
w.WriteHeader(http.StatusNotFound)
|
|
default:
|
|
_, err := io.WriteString(w, `[]`)
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGitlabListRepos(t *testing.T) {
|
|
t.Parallel()
|
|
cases := []struct {
|
|
name, proto, topic string
|
|
hasError, allBranches, includeSubgroups, includeSharedProjects, includeArchivedRepos, insecure bool
|
|
branches []string
|
|
expectedRepos []*Repository
|
|
filters []v1alpha1.SCMProviderGeneratorFilter
|
|
}{
|
|
{
|
|
name: "blank protocol",
|
|
allBranches: false,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
branches: []string{"master"},
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ssh protocol",
|
|
proto: "ssh",
|
|
allBranches: false,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
branches: []string{"master"},
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "https protocol",
|
|
proto: "https",
|
|
allBranches: false,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
branches: []string{"master"},
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "https://gitlab.com/test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "labelmatch",
|
|
proto: "ssh",
|
|
allBranches: false,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{
|
|
{
|
|
LabelMatch: new("test-topic"),
|
|
},
|
|
},
|
|
|
|
branches: []string{"master"},
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "other protocol",
|
|
proto: "other",
|
|
hasError: true,
|
|
},
|
|
{
|
|
name: "all branches",
|
|
allBranches: true,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
branches: []string{"master"},
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all subgroups",
|
|
allBranches: true,
|
|
branches: []string{"master"},
|
|
includeSharedProjects: false,
|
|
includeSubgroups: true,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic", "specific-topic"},
|
|
},
|
|
{
|
|
Organization: "",
|
|
Repository: "cd-subgroup",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/subgroup/cd-subgroup.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b58",
|
|
RepositoryId: int64(27084538),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all subgroups and shared projects",
|
|
allBranches: true,
|
|
branches: []string{"master"},
|
|
includeSharedProjects: true,
|
|
includeSubgroups: true,
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
{
|
|
Organization: "",
|
|
Repository: "shared-cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-shared-cd-proton/shared-cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084534),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "specific topic",
|
|
allBranches: true,
|
|
branches: []string{"master"},
|
|
includeSubgroups: false,
|
|
topic: "specific-topic",
|
|
includeArchivedRepos: false,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{"test-topic", "specific-topic"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all branches with archived repos",
|
|
allBranches: true,
|
|
branches: []string{"master"},
|
|
includeSubgroups: false,
|
|
includeArchivedRepos: true,
|
|
filters: []v1alpha1.SCMProviderGeneratorFilter{},
|
|
|
|
expectedRepos: []*Repository{
|
|
{
|
|
Organization: "",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/cd.git",
|
|
SHA: "8898d7999fc99dd0fd578650b58b244fc63f6b53",
|
|
RepositoryId: int64(27084533),
|
|
Labels: []string{},
|
|
},
|
|
{
|
|
Organization: "",
|
|
Repository: "another-repo",
|
|
Branch: "master",
|
|
URL: "[email protected]:test-cd-proton/another-repo.git",
|
|
SHA: "8898d8889fc99dd0fd578650b58b244fc63f6b58",
|
|
RepositoryId: int64(56522142),
|
|
Labels: []string{"test-topic"},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gitlabMockHandler(t)(w, r)
|
|
}))
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
provider, _ := NewGitlabProvider("test-cd-proton", "", ts.URL, c.allBranches, c.includeSubgroups, c.includeSharedProjects, c.includeArchivedRepos, c.insecure, "", c.topic, nil, "", "")
|
|
rawRepos, err := ListRepos(t.Context(), provider, c.filters, c.proto)
|
|
if c.hasError {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
|
|
repos := []*Repository{}
|
|
uniqueRepos := map[string]int{}
|
|
|
|
for _, r := range rawRepos {
|
|
if _, ok := uniqueRepos[r.Repository]; !ok {
|
|
repos = append(repos, r)
|
|
}
|
|
uniqueRepos[r.Repository]++
|
|
}
|
|
assert.NotEmpty(t, repos)
|
|
|
|
// In case of listing subgroups, validate the number of returned projects
|
|
if c.includeSubgroups || c.includeSharedProjects {
|
|
assert.Len(t, uniqueRepos, 2)
|
|
}
|
|
// In case we filter on the topic, ensure we got only one repo returned
|
|
if c.topic != "" {
|
|
assert.Len(t, uniqueRepos, 1)
|
|
}
|
|
assert.Len(t, repos, len(c.expectedRepos))
|
|
assert.ElementsMatch(t, c.expectedRepos, repos)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGitlabHasPath(t *testing.T) {
|
|
t.Parallel()
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gitlabMockHandler(t)(w, r)
|
|
}))
|
|
host, _ := NewGitlabProvider("test-cd-proton", "", ts.URL, false, true, true, false, false, "", "", nil, "", "")
|
|
repo := &Repository{
|
|
Organization: "test-cd-proton",
|
|
Repository: "cd",
|
|
Branch: "master",
|
|
}
|
|
|
|
cases := []struct {
|
|
name, path string
|
|
exists bool
|
|
}{
|
|
{
|
|
name: "directory exists",
|
|
path: "cd",
|
|
exists: true,
|
|
},
|
|
{
|
|
name: "file exists",
|
|
path: "cd/install.yaml",
|
|
exists: true,
|
|
},
|
|
{
|
|
name: "directory does not exist",
|
|
path: "notathing",
|
|
exists: false,
|
|
},
|
|
{
|
|
name: "file does not exist",
|
|
path: "cd/notathing.yaml",
|
|
exists: false,
|
|
},
|
|
{
|
|
name: "noexistent file in noexistent directory",
|
|
path: "notathing/notathing.yaml",
|
|
exists: false,
|
|
},
|
|
{
|
|
name: "noexistent file in nested noexistent directory",
|
|
path: "notathing/notathing/notathing.yaml",
|
|
exists: false,
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
ok, err := host.RepoHasPath(t.Context(), repo, c.path)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, c.exists, ok)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGitlabGetBranches(t *testing.T) {
|
|
t.Parallel()
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gitlabMockHandler(t)(w, r)
|
|
}))
|
|
host, _ := NewGitlabProvider("test-cd-proton", "", ts.URL, false, true, true, false, false, "", "", nil, "", "")
|
|
|
|
repo := &Repository{
|
|
RepositoryId: int64(27084533),
|
|
Branch: "master",
|
|
}
|
|
t.Run("branch exists", func(t *testing.T) {
|
|
t.Parallel()
|
|
repos, err := host.GetBranches(t.Context(), repo)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "master", repos[0].Branch)
|
|
})
|
|
|
|
repo2 := &Repository{
|
|
RepositoryId: int64(27084533),
|
|
Branch: "foo",
|
|
}
|
|
t.Run("unknown branch", func(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := host.GetBranches(t.Context(), repo2)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestGetBranchesTLS(t *testing.T) {
|
|
t.Parallel()
|
|
tests := []struct {
|
|
name string
|
|
tlsInsecure bool
|
|
passCerts bool
|
|
requireErr bool
|
|
}{
|
|
{
|
|
name: "TLS Insecure: true, No Certs",
|
|
tlsInsecure: true,
|
|
passCerts: false,
|
|
requireErr: false,
|
|
},
|
|
{
|
|
name: "TLS Insecure: true, With Certs",
|
|
tlsInsecure: true,
|
|
passCerts: true,
|
|
requireErr: false,
|
|
},
|
|
{
|
|
name: "TLS Insecure: false, With Certs",
|
|
tlsInsecure: false,
|
|
passCerts: true,
|
|
requireErr: false,
|
|
},
|
|
{
|
|
name: "TLS Insecure: false, No Certs",
|
|
tlsInsecure: false,
|
|
passCerts: false,
|
|
requireErr: true,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gitlabMockHandler(t)(w, r)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
var certs []byte
|
|
if test.passCerts {
|
|
for _, cert := range ts.TLS.Certificates {
|
|
for _, c := range cert.Certificate {
|
|
parsedCert, err := x509.ParseCertificate(c)
|
|
require.NoError(t, err, "Failed to parse certificate")
|
|
certs = append(certs, pem.EncodeToMemory(&pem.Block{
|
|
Type: "CERTIFICATE",
|
|
Bytes: parsedCert.Raw,
|
|
})...)
|
|
}
|
|
}
|
|
}
|
|
|
|
host, err := NewGitlabProvider("test-cd-proton", "", ts.URL, false, true, true, false, test.tlsInsecure, "", "", certs, "", "")
|
|
require.NoError(t, err)
|
|
repo := &Repository{
|
|
RepositoryId: int64(27084533),
|
|
Branch: "master",
|
|
}
|
|
_, err = host.GetBranches(t.Context(), repo)
|
|
if test.requireErr {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewGitlabProvider_Proxy(t *testing.T) {
|
|
t.Parallel()
|
|
targetTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if r.URL.Path == "/api/v4" || r.URL.Path == "/api/v4/" {
|
|
_, _ = w.Write([]byte(`{}`))
|
|
return
|
|
}
|
|
// Return a branch list that won't cause panic
|
|
// We need to check if the request is for listing branches (returns array) or getting one (returns object)
|
|
if strings.Contains(r.URL.Path, "/repository/branches/master") {
|
|
_, _ = w.Write([]byte(`{"name":"master","commit":{"id":"123456"}}`))
|
|
} else {
|
|
_, _ = w.Write([]byte(`[{"name":"master","commit":{"id":"123456"}}]`))
|
|
}
|
|
}))
|
|
defer targetTS.Close()
|
|
|
|
proxyCalled := 0
|
|
proxyTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
proxyCalled++
|
|
r.RequestURI = ""
|
|
u, _ := url.Parse(targetTS.URL)
|
|
r.URL.Scheme = u.Scheme
|
|
r.URL.Host = u.Host
|
|
r.Host = u.Host
|
|
|
|
resp, err := http.DefaultClient.Do(r)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
for k, vv := range resp.Header {
|
|
for _, v := range vv {
|
|
w.Header().Add(k, v)
|
|
}
|
|
}
|
|
w.WriteHeader(resp.StatusCode)
|
|
_, _ = io.Copy(w, resp.Body)
|
|
}))
|
|
defer proxyTS.Close()
|
|
|
|
targetURL := "http://gitlab.example.com"
|
|
|
|
provider, err := NewGitlabProvider("test-org", "test-token", targetURL, false, false, false, false, false, "", "", nil, proxyTS.URL, "")
|
|
require.NoError(t, err)
|
|
require.NotNil(t, provider)
|
|
|
|
repo := &Repository{
|
|
Organization: "test-org",
|
|
Repository: "test-repo",
|
|
Branch: "master",
|
|
RepositoryId: 1,
|
|
}
|
|
_, err = provider.GetBranches(t.Context(), repo)
|
|
require.NoError(t, err)
|
|
|
|
assert.Positive(t, proxyCalled, "Proxy should have been called")
|
|
}
|