diff --git a/docs/daytona_create.md b/docs/daytona_create.md index 007df8d46d..b9f8162569 100644 --- a/docs/daytona_create.md +++ b/docs/daytona_create.md @@ -9,20 +9,21 @@ daytona create [REPOSITORY_URL | PROJECT_CONFIG_NAME]... [flags] ### Options ``` - --blank Create a blank project without using existing configurations - --branch strings Specify the Git branches to use in the projects - --builder BuildChoice Specify the builder (currently auto/devcontainer/none) - --custom-image string Create the project with the custom image passed as the flag value; Requires setting --custom-image-user flag as well - --custom-image-user string Create the project with the custom image user passed as the flag value; Requires setting --custom-image flag as well - --devcontainer-path string Automatically assign the devcontainer builder with the path passed as the flag value - --env stringArray Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') - -i, --ide string Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm) - --manual Manually enter the Git repository - --multi-project Workspace with multiple projects/repos - --name string Specify the workspace name - -n, --no-ide Do not open the workspace in the IDE after workspace creation - -t, --target string Specify the target (e.g. 'local') - -y, --yes Automatically confirm any prompts + --blank Create a blank project without using existing configurations + --branch strings Specify the Git branches to use in the projects + --builder BuildChoice Specify the builder (currently auto/devcontainer/none) + --custom-image string Create the project with the custom image passed as the flag value; Requires setting --custom-image-user flag as well + --custom-image-user string Create the project with the custom image user passed as the flag value; Requires setting --custom-image flag as well + --devcontainer-path string Automatically assign the devcontainer builder with the path passed as the flag value + --env stringArray Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') + --git-provider-config-id string Specify the Git Provider Configuration Id + -i, --ide string Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm) + --manual Manually enter the Git repository + --multi-project Workspace with multiple projects/repos + --name string Specify the workspace name + -n, --no-ide Do not open the workspace in the IDE after workspace creation + -t, --target string Specify the target (e.g. 'local') + -y, --yes Automatically confirm any prompts ``` ### Options inherited from parent commands diff --git a/docs/daytona_project-config_add.md b/docs/daytona_project-config_add.md index 0dd2d7b2eb..7944518944 100644 --- a/docs/daytona_project-config_add.md +++ b/docs/daytona_project-config_add.md @@ -9,13 +9,14 @@ daytona project-config add [flags] ### Options ``` - --builder BuildChoice Specify the builder (currently auto/devcontainer/none) - --custom-image string Create the project with the custom image passed as the flag value; Requires setting --custom-image-user flag as well - --custom-image-user string Create the project with the custom image user passed as the flag value; Requires setting --custom-image flag as well - --devcontainer-path string Automatically assign the devcontainer builder with the path passed as the flag value - --env stringArray Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') - --manual Manually enter the Git repository - --name string Specify the project config name + --builder BuildChoice Specify the builder (currently auto/devcontainer/none) + --custom-image string Create the project with the custom image passed as the flag value; Requires setting --custom-image-user flag as well + --custom-image-user string Create the project with the custom image user passed as the flag value; Requires setting --custom-image flag as well + --devcontainer-path string Automatically assign the devcontainer builder with the path passed as the flag value + --env stringArray Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') + --git-provider-config-id string Specify the Git Provider Configuration Id + --manual Manually enter the Git repository + --name string Specify the project config name ``` ### Options inherited from parent commands diff --git a/hack/docs/daytona_create.yaml b/hack/docs/daytona_create.yaml index 3f211cb59b..3420a97951 100644 --- a/hack/docs/daytona_create.yaml +++ b/hack/docs/daytona_create.yaml @@ -23,6 +23,8 @@ options: default_value: '[]' usage: | Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') + - name: git-provider-config-id + usage: Specify the Git Provider Configuration Id - name: ide shorthand: i usage: | diff --git a/hack/docs/daytona_project-config_add.yaml b/hack/docs/daytona_project-config_add.yaml index 2b79cae0d6..674f7bdd56 100644 --- a/hack/docs/daytona_project-config_add.yaml +++ b/hack/docs/daytona_project-config_add.yaml @@ -17,6 +17,8 @@ options: default_value: '[]' usage: | Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...') + - name: git-provider-config-id + usage: Specify the Git Provider Configuration Id - name: manual default_value: "false" usage: Manually enter the Git repository diff --git a/internal/util/apiclient/conversion/project.go b/internal/util/apiclient/conversion/project.go index c00326d265..ed0f8de4fc 100644 --- a/internal/util/apiclient/conversion/project.go +++ b/internal/util/apiclient/conversion/project.go @@ -50,14 +50,15 @@ func ToProject(projectDTO *apiclient.Project) *project.Project { } project := &project.Project{ - Name: projectDTO.Name, - Image: projectDTO.Image, - User: projectDTO.User, - BuildConfig: projectBuild, - Repository: repository, - Target: projectDTO.Target, - WorkspaceId: projectDTO.WorkspaceId, - State: projectState, + Name: projectDTO.Name, + Image: projectDTO.Image, + User: projectDTO.User, + BuildConfig: projectBuild, + Repository: repository, + Target: projectDTO.Target, + WorkspaceId: projectDTO.WorkspaceId, + State: projectState, + GitProviderConfigId: projectDTO.GitProviderConfigId, } if projectDTO.Repository.PrNumber != nil { @@ -148,9 +149,10 @@ func ToGitStatusDTO(gitStatus *project.GitStatus) *apiclient.GitStatus { func ToProjectConfig(createProjectConfigDto pc_dto.CreateProjectConfigDTO) *config.ProjectConfig { result := &config.ProjectConfig{ - Name: createProjectConfigDto.Name, - BuildConfig: createProjectConfigDto.BuildConfig, - EnvVars: createProjectConfigDto.EnvVars, + Name: createProjectConfigDto.Name, + BuildConfig: createProjectConfigDto.BuildConfig, + EnvVars: createProjectConfigDto.EnvVars, + GitProviderConfigId: createProjectConfigDto.GitProviderConfigId, } result.RepositoryUrl = createProjectConfigDto.RepositoryUrl @@ -168,10 +170,11 @@ func ToProjectConfig(createProjectConfigDto pc_dto.CreateProjectConfigDTO) *conf func CreateDtoToProject(createProjectDto project_dto.CreateProjectDTO) *project.Project { p := &project.Project{ - Name: createProjectDto.Name, - BuildConfig: createProjectDto.BuildConfig, - Repository: createProjectDto.Source.Repository, - EnvVars: createProjectDto.EnvVars, + Name: createProjectDto.Name, + BuildConfig: createProjectDto.BuildConfig, + Repository: createProjectDto.Source.Repository, + EnvVars: createProjectDto.EnvVars, + GitProviderConfigId: createProjectDto.GitProviderConfigId, } if createProjectDto.Image != nil { @@ -187,10 +190,11 @@ func CreateDtoToProject(createProjectDto project_dto.CreateProjectDTO) *project. func CreateConfigDtoToProject(createProjectConfigDto pc_dto.CreateProjectConfigDTO) *project.Project { return &project.Project{ - Name: createProjectConfigDto.Name, - Image: *createProjectConfigDto.Image, - User: *createProjectConfigDto.User, - BuildConfig: createProjectConfigDto.BuildConfig, + Name: createProjectConfigDto.Name, + Image: *createProjectConfigDto.Image, + User: *createProjectConfigDto.User, + BuildConfig: createProjectConfigDto.BuildConfig, + GitProviderConfigId: createProjectConfigDto.GitProviderConfigId, Repository: &gitprovider.GitRepository{ Url: createProjectConfigDto.RepositoryUrl, }, diff --git a/pkg/api/controllers/gitprovider/dto/dto.go b/pkg/api/controllers/gitprovider/dto/dto.go index c37e891644..1e93e4e0d3 100644 --- a/pkg/api/controllers/gitprovider/dto/dto.go +++ b/pkg/api/controllers/gitprovider/dto/dto.go @@ -8,8 +8,10 @@ type RepositoryUrl struct { } // @name RepositoryUrl type SetGitProviderConfig struct { - Id string `json:"id" validate:"required"` - Username *string `json:"username" validate:"optional"` + Id string `json:"id" validate:"optional"` + ProviderId string `json:"providerId" validate:"required"` + Username *string `json:"username,omitempty" validate:"optional"` Token string `json:"token" validate:"required"` BaseApiUrl *string `json:"baseApiUrl,omitempty" validate:"optional"` + Alias *string `json:"alias,omitempty" validate:"optional"` } // @name SetGitProviderConfig diff --git a/pkg/api/controllers/gitprovider/gitprovider.go b/pkg/api/controllers/gitprovider/gitprovider.go index 738e5a584c..c5153325d2 100644 --- a/pkg/api/controllers/gitprovider/gitprovider.go +++ b/pkg/api/controllers/gitprovider/gitprovider.go @@ -133,6 +133,7 @@ func SetGitProvider(ctx *gin.Context) { gitProviderConfig := gitprovider.GitProviderConfig{ Id: setConfigDto.Id, + ProviderId: setConfigDto.ProviderId, Token: setConfigDto.Token, BaseApiUrl: setConfigDto.BaseApiUrl, } @@ -141,6 +142,10 @@ func SetGitProvider(ctx *gin.Context) { gitProviderConfig.Username = *setConfigDto.Username } + if setConfigDto.Alias != nil { + gitProviderConfig.Alias = *setConfigDto.Alias + } + server := server.GetInstance(nil) err = server.GitProviderService.SetGitProviderConfig(&gitProviderConfig) diff --git a/pkg/api/docs/docs.go b/pkg/api/docs/docs.go index cd05493d44..533939478c 100644 --- a/pkg/api/docs/docs.go +++ b/pkg/api/docs/docs.go @@ -1966,6 +1966,9 @@ const docTemplate = `{ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -1997,6 +2000,9 @@ const docTemplate = `{ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2169,17 +2175,25 @@ const docTemplate = `{ "GitProvider": { "type": "object", "required": [ + "alias", "id", + "providerId", "token", "username" ], "properties": { + "alias": { + "type": "string" + }, "baseApiUrl": { "type": "string" }, "id": { "type": "string" }, + "providerId": { + "type": "string" + }, "token": { "type": "string" }, @@ -2443,6 +2457,9 @@ const docTemplate = `{ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2489,6 +2506,9 @@ const docTemplate = `{ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2700,16 +2720,22 @@ const docTemplate = `{ "SetGitProviderConfig": { "type": "object", "required": [ - "id", + "providerId", "token" ], "properties": { + "alias": { + "type": "string" + }, "baseApiUrl": { "type": "string" }, "id": { "type": "string" }, + "providerId": { + "type": "string" + }, "token": { "type": "string" }, diff --git a/pkg/api/docs/swagger.json b/pkg/api/docs/swagger.json index da8d9028b1..e9a276076e 100644 --- a/pkg/api/docs/swagger.json +++ b/pkg/api/docs/swagger.json @@ -1963,6 +1963,9 @@ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -1994,6 +1997,9 @@ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2166,17 +2172,25 @@ "GitProvider": { "type": "object", "required": [ + "alias", "id", + "providerId", "token", "username" ], "properties": { + "alias": { + "type": "string" + }, "baseApiUrl": { "type": "string" }, "id": { "type": "string" }, + "providerId": { + "type": "string" + }, "token": { "type": "string" }, @@ -2440,6 +2454,9 @@ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2486,6 +2503,9 @@ "type": "string" } }, + "gitProviderConfigId": { + "type": "string" + }, "image": { "type": "string" }, @@ -2697,16 +2717,22 @@ "SetGitProviderConfig": { "type": "object", "required": [ - "id", + "providerId", "token" ], "properties": { + "alias": { + "type": "string" + }, "baseApiUrl": { "type": "string" }, "id": { "type": "string" }, + "providerId": { + "type": "string" + }, "token": { "type": "string" }, diff --git a/pkg/api/docs/swagger.yaml b/pkg/api/docs/swagger.yaml index c0710ce1b9..afd1a7c9e8 100644 --- a/pkg/api/docs/swagger.yaml +++ b/pkg/api/docs/swagger.yaml @@ -140,6 +140,8 @@ definitions: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -161,6 +163,8 @@ definitions: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -280,16 +284,22 @@ definitions: type: object GitProvider: properties: + alias: + type: string baseApiUrl: type: string id: type: string + providerId: + type: string token: type: string username: type: string required: + - alias - id + - providerId - token - username type: object @@ -462,6 +472,8 @@ definitions: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -495,6 +507,8 @@ definitions: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -648,16 +662,20 @@ definitions: type: object SetGitProviderConfig: properties: + alias: + type: string baseApiUrl: type: string id: type: string + providerId: + type: string token: type: string username: type: string required: - - id + - providerId - token type: object SetProjectState: diff --git a/pkg/apiclient/api/openapi.yaml b/pkg/apiclient/api/openapi.yaml index 1435608e6e..5e4d9a2fd4 100644 --- a/pkg/apiclient/api/openapi.yaml +++ b/pkg/apiclient/api/openapi.yaml @@ -1459,6 +1459,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -1472,6 +1473,8 @@ components: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -1493,6 +1496,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -1517,6 +1521,8 @@ components: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -1558,6 +1564,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -1581,6 +1588,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -1726,21 +1734,29 @@ components: type: object GitProvider: example: + providerId: providerId baseApiUrl: baseApiUrl + alias: alias id: id token: token username: username properties: + alias: + type: string baseApiUrl: type: string id: type: string + providerId: + type: string token: type: string username: type: string required: + - alias - id + - providerId - token - username type: object @@ -1977,6 +1993,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -2019,6 +2036,8 @@ components: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -2065,6 +2084,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image default: true envVars: @@ -2081,6 +2101,8 @@ components: additionalProperties: type: string type: object + gitProviderConfigId: + type: string image: type: string name: @@ -2293,21 +2315,27 @@ components: type: object SetGitProviderConfig: example: + providerId: providerId baseApiUrl: baseApiUrl + alias: alias id: id token: token username: username properties: + alias: + type: string baseApiUrl: type: string id: type: string + providerId: + type: string token: type: string username: type: string required: - - id + - providerId - token type: object SetProjectState: @@ -2364,6 +2392,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -2405,6 +2434,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -2469,6 +2499,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars @@ -2510,6 +2541,7 @@ components: user: user devcontainer: filePath: filePath + gitProviderConfigId: gitProviderConfigId image: image envVars: key: envVars diff --git a/pkg/apiclient/docs/CreateProjectConfigDTO.md b/pkg/apiclient/docs/CreateProjectConfigDTO.md index 084564a698..f421b5d580 100644 --- a/pkg/apiclient/docs/CreateProjectConfigDTO.md +++ b/pkg/apiclient/docs/CreateProjectConfigDTO.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **BuildConfig** | Pointer to [**BuildConfig**](BuildConfig.md) | | [optional] **EnvVars** | **map[string]string** | | +**GitProviderConfigId** | Pointer to **string** | | [optional] **Image** | Pointer to **string** | | [optional] **Name** | **string** | | **RepositoryUrl** | **string** | | @@ -75,6 +76,31 @@ and a boolean to check if the value has been set. SetEnvVars sets EnvVars field to given value. +### GetGitProviderConfigId + +`func (o *CreateProjectConfigDTO) GetGitProviderConfigId() string` + +GetGitProviderConfigId returns the GitProviderConfigId field if non-nil, zero value otherwise. + +### GetGitProviderConfigIdOk + +`func (o *CreateProjectConfigDTO) GetGitProviderConfigIdOk() (*string, bool)` + +GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetGitProviderConfigId + +`func (o *CreateProjectConfigDTO) SetGitProviderConfigId(v string)` + +SetGitProviderConfigId sets GitProviderConfigId field to given value. + +### HasGitProviderConfigId + +`func (o *CreateProjectConfigDTO) HasGitProviderConfigId() bool` + +HasGitProviderConfigId returns a boolean if a field has been set. + ### GetImage `func (o *CreateProjectConfigDTO) GetImage() string` diff --git a/pkg/apiclient/docs/CreateProjectDTO.md b/pkg/apiclient/docs/CreateProjectDTO.md index 1743dc4225..e084e5a9e5 100644 --- a/pkg/apiclient/docs/CreateProjectDTO.md +++ b/pkg/apiclient/docs/CreateProjectDTO.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **BuildConfig** | Pointer to [**BuildConfig**](BuildConfig.md) | | [optional] **EnvVars** | **map[string]string** | | +**GitProviderConfigId** | Pointer to **string** | | [optional] **Image** | Pointer to **string** | | [optional] **Name** | **string** | | **Source** | [**CreateProjectSourceDTO**](CreateProjectSourceDTO.md) | | @@ -75,6 +76,31 @@ and a boolean to check if the value has been set. SetEnvVars sets EnvVars field to given value. +### GetGitProviderConfigId + +`func (o *CreateProjectDTO) GetGitProviderConfigId() string` + +GetGitProviderConfigId returns the GitProviderConfigId field if non-nil, zero value otherwise. + +### GetGitProviderConfigIdOk + +`func (o *CreateProjectDTO) GetGitProviderConfigIdOk() (*string, bool)` + +GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetGitProviderConfigId + +`func (o *CreateProjectDTO) SetGitProviderConfigId(v string)` + +SetGitProviderConfigId sets GitProviderConfigId field to given value. + +### HasGitProviderConfigId + +`func (o *CreateProjectDTO) HasGitProviderConfigId() bool` + +HasGitProviderConfigId returns a boolean if a field has been set. + ### GetImage `func (o *CreateProjectDTO) GetImage() string` diff --git a/pkg/apiclient/docs/GitProvider.md b/pkg/apiclient/docs/GitProvider.md index 74e57a986e..bf09388d36 100644 --- a/pkg/apiclient/docs/GitProvider.md +++ b/pkg/apiclient/docs/GitProvider.md @@ -4,8 +4,10 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**Alias** | **string** | | **BaseApiUrl** | Pointer to **string** | | [optional] **Id** | **string** | | +**ProviderId** | **string** | | **Token** | **string** | | **Username** | **string** | | @@ -13,7 +15,7 @@ Name | Type | Description | Notes ### NewGitProvider -`func NewGitProvider(id string, token string, username string, ) *GitProvider` +`func NewGitProvider(alias string, id string, providerId string, token string, username string, ) *GitProvider` NewGitProvider instantiates a new GitProvider object This constructor will assign default values to properties that have it defined, @@ -28,6 +30,26 @@ NewGitProviderWithDefaults instantiates a new GitProvider object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set +### GetAlias + +`func (o *GitProvider) GetAlias() string` + +GetAlias returns the Alias field if non-nil, zero value otherwise. + +### GetAliasOk + +`func (o *GitProvider) GetAliasOk() (*string, bool)` + +GetAliasOk returns a tuple with the Alias field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetAlias + +`func (o *GitProvider) SetAlias(v string)` + +SetAlias sets Alias field to given value. + + ### GetBaseApiUrl `func (o *GitProvider) GetBaseApiUrl() string` @@ -73,6 +95,26 @@ and a boolean to check if the value has been set. SetId sets Id field to given value. +### GetProviderId + +`func (o *GitProvider) GetProviderId() string` + +GetProviderId returns the ProviderId field if non-nil, zero value otherwise. + +### GetProviderIdOk + +`func (o *GitProvider) GetProviderIdOk() (*string, bool)` + +GetProviderIdOk returns a tuple with the ProviderId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetProviderId + +`func (o *GitProvider) SetProviderId(v string)` + +SetProviderId sets ProviderId field to given value. + + ### GetToken `func (o *GitProvider) GetToken() string` diff --git a/pkg/apiclient/docs/GitProviderAPI.md b/pkg/apiclient/docs/GitProviderAPI.md index 45c6c15588..4daf28cb83 100644 --- a/pkg/apiclient/docs/GitProviderAPI.md +++ b/pkg/apiclient/docs/GitProviderAPI.md @@ -806,7 +806,7 @@ import ( ) func main() { - gitProviderConfig := *openapiclient.NewSetGitProviderConfig("Id_example", "Token_example") // SetGitProviderConfig | Git provider + gitProviderConfig := *openapiclient.NewSetGitProviderConfig("ProviderId_example", "Token_example") // SetGitProviderConfig | Git provider configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) diff --git a/pkg/apiclient/docs/Project.md b/pkg/apiclient/docs/Project.md index 67acf2cf41..1e95900872 100644 --- a/pkg/apiclient/docs/Project.md +++ b/pkg/apiclient/docs/Project.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **BuildConfig** | Pointer to [**BuildConfig**](BuildConfig.md) | | [optional] **EnvVars** | **map[string]string** | | +**GitProviderConfigId** | Pointer to **string** | | [optional] **Image** | **string** | | **Name** | **string** | | **Repository** | [**GitRepository**](GitRepository.md) | | @@ -78,6 +79,31 @@ and a boolean to check if the value has been set. SetEnvVars sets EnvVars field to given value. +### GetGitProviderConfigId + +`func (o *Project) GetGitProviderConfigId() string` + +GetGitProviderConfigId returns the GitProviderConfigId field if non-nil, zero value otherwise. + +### GetGitProviderConfigIdOk + +`func (o *Project) GetGitProviderConfigIdOk() (*string, bool)` + +GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetGitProviderConfigId + +`func (o *Project) SetGitProviderConfigId(v string)` + +SetGitProviderConfigId sets GitProviderConfigId field to given value. + +### HasGitProviderConfigId + +`func (o *Project) HasGitProviderConfigId() bool` + +HasGitProviderConfigId returns a boolean if a field has been set. + ### GetImage `func (o *Project) GetImage() string` diff --git a/pkg/apiclient/docs/ProjectConfig.md b/pkg/apiclient/docs/ProjectConfig.md index 137f0d3a33..4c211bd2fa 100644 --- a/pkg/apiclient/docs/ProjectConfig.md +++ b/pkg/apiclient/docs/ProjectConfig.md @@ -7,6 +7,7 @@ Name | Type | Description | Notes **BuildConfig** | Pointer to [**BuildConfig**](BuildConfig.md) | | [optional] **Default** | **bool** | | **EnvVars** | **map[string]string** | | +**GitProviderConfigId** | Pointer to **string** | | [optional] **Image** | **string** | | **Name** | **string** | | **Prebuilds** | Pointer to [**[]PrebuildConfig**](PrebuildConfig.md) | | [optional] @@ -97,6 +98,31 @@ and a boolean to check if the value has been set. SetEnvVars sets EnvVars field to given value. +### GetGitProviderConfigId + +`func (o *ProjectConfig) GetGitProviderConfigId() string` + +GetGitProviderConfigId returns the GitProviderConfigId field if non-nil, zero value otherwise. + +### GetGitProviderConfigIdOk + +`func (o *ProjectConfig) GetGitProviderConfigIdOk() (*string, bool)` + +GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetGitProviderConfigId + +`func (o *ProjectConfig) SetGitProviderConfigId(v string)` + +SetGitProviderConfigId sets GitProviderConfigId field to given value. + +### HasGitProviderConfigId + +`func (o *ProjectConfig) HasGitProviderConfigId() bool` + +HasGitProviderConfigId returns a boolean if a field has been set. + ### GetImage `func (o *ProjectConfig) GetImage() string` diff --git a/pkg/apiclient/docs/SetGitProviderConfig.md b/pkg/apiclient/docs/SetGitProviderConfig.md index 184bd74519..21ba99e4cd 100644 --- a/pkg/apiclient/docs/SetGitProviderConfig.md +++ b/pkg/apiclient/docs/SetGitProviderConfig.md @@ -4,8 +4,10 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**Alias** | Pointer to **string** | | [optional] **BaseApiUrl** | Pointer to **string** | | [optional] -**Id** | **string** | | +**Id** | Pointer to **string** | | [optional] +**ProviderId** | **string** | | **Token** | **string** | | **Username** | Pointer to **string** | | [optional] @@ -13,7 +15,7 @@ Name | Type | Description | Notes ### NewSetGitProviderConfig -`func NewSetGitProviderConfig(id string, token string, ) *SetGitProviderConfig` +`func NewSetGitProviderConfig(providerId string, token string, ) *SetGitProviderConfig` NewSetGitProviderConfig instantiates a new SetGitProviderConfig object This constructor will assign default values to properties that have it defined, @@ -28,6 +30,31 @@ NewSetGitProviderConfigWithDefaults instantiates a new SetGitProviderConfig obje This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set +### GetAlias + +`func (o *SetGitProviderConfig) GetAlias() string` + +GetAlias returns the Alias field if non-nil, zero value otherwise. + +### GetAliasOk + +`func (o *SetGitProviderConfig) GetAliasOk() (*string, bool)` + +GetAliasOk returns a tuple with the Alias field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetAlias + +`func (o *SetGitProviderConfig) SetAlias(v string)` + +SetAlias sets Alias field to given value. + +### HasAlias + +`func (o *SetGitProviderConfig) HasAlias() bool` + +HasAlias returns a boolean if a field has been set. + ### GetBaseApiUrl `func (o *SetGitProviderConfig) GetBaseApiUrl() string` @@ -72,6 +99,31 @@ and a boolean to check if the value has been set. SetId sets Id field to given value. +### HasId + +`func (o *SetGitProviderConfig) HasId() bool` + +HasId returns a boolean if a field has been set. + +### GetProviderId + +`func (o *SetGitProviderConfig) GetProviderId() string` + +GetProviderId returns the ProviderId field if non-nil, zero value otherwise. + +### GetProviderIdOk + +`func (o *SetGitProviderConfig) GetProviderIdOk() (*string, bool)` + +GetProviderIdOk returns a tuple with the ProviderId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetProviderId + +`func (o *SetGitProviderConfig) SetProviderId(v string)` + +SetProviderId sets ProviderId field to given value. + ### GetToken diff --git a/pkg/apiclient/model_create_project_config_dto.go b/pkg/apiclient/model_create_project_config_dto.go index c2aa4a9cbf..0de5ca203e 100644 --- a/pkg/apiclient/model_create_project_config_dto.go +++ b/pkg/apiclient/model_create_project_config_dto.go @@ -21,12 +21,13 @@ var _ MappedNullable = &CreateProjectConfigDTO{} // CreateProjectConfigDTO struct for CreateProjectConfigDTO type CreateProjectConfigDTO struct { - BuildConfig *BuildConfig `json:"buildConfig,omitempty"` - EnvVars map[string]string `json:"envVars"` - Image *string `json:"image,omitempty"` - Name string `json:"name"` - RepositoryUrl string `json:"repositoryUrl"` - User *string `json:"user,omitempty"` + BuildConfig *BuildConfig `json:"buildConfig,omitempty"` + EnvVars map[string]string `json:"envVars"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty"` + Image *string `json:"image,omitempty"` + Name string `json:"name"` + RepositoryUrl string `json:"repositoryUrl"` + User *string `json:"user,omitempty"` } type _CreateProjectConfigDTO CreateProjectConfigDTO @@ -107,6 +108,38 @@ func (o *CreateProjectConfigDTO) SetEnvVars(v map[string]string) { o.EnvVars = v } +// GetGitProviderConfigId returns the GitProviderConfigId field value if set, zero value otherwise. +func (o *CreateProjectConfigDTO) GetGitProviderConfigId() string { + if o == nil || IsNil(o.GitProviderConfigId) { + var ret string + return ret + } + return *o.GitProviderConfigId +} + +// GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateProjectConfigDTO) GetGitProviderConfigIdOk() (*string, bool) { + if o == nil || IsNil(o.GitProviderConfigId) { + return nil, false + } + return o.GitProviderConfigId, true +} + +// HasGitProviderConfigId returns a boolean if a field has been set. +func (o *CreateProjectConfigDTO) HasGitProviderConfigId() bool { + if o != nil && !IsNil(o.GitProviderConfigId) { + return true + } + + return false +} + +// SetGitProviderConfigId gets a reference to the given string and assigns it to the GitProviderConfigId field. +func (o *CreateProjectConfigDTO) SetGitProviderConfigId(v string) { + o.GitProviderConfigId = &v +} + // GetImage returns the Image field value if set, zero value otherwise. func (o *CreateProjectConfigDTO) GetImage() string { if o == nil || IsNil(o.Image) { @@ -233,6 +266,9 @@ func (o CreateProjectConfigDTO) ToMap() (map[string]interface{}, error) { toSerialize["buildConfig"] = o.BuildConfig } toSerialize["envVars"] = o.EnvVars + if !IsNil(o.GitProviderConfigId) { + toSerialize["gitProviderConfigId"] = o.GitProviderConfigId + } if !IsNil(o.Image) { toSerialize["image"] = o.Image } diff --git a/pkg/apiclient/model_create_project_dto.go b/pkg/apiclient/model_create_project_dto.go index 7bce0cf2f2..df7c43ec87 100644 --- a/pkg/apiclient/model_create_project_dto.go +++ b/pkg/apiclient/model_create_project_dto.go @@ -21,12 +21,13 @@ var _ MappedNullable = &CreateProjectDTO{} // CreateProjectDTO struct for CreateProjectDTO type CreateProjectDTO struct { - BuildConfig *BuildConfig `json:"buildConfig,omitempty"` - EnvVars map[string]string `json:"envVars"` - Image *string `json:"image,omitempty"` - Name string `json:"name"` - Source CreateProjectSourceDTO `json:"source"` - User *string `json:"user,omitempty"` + BuildConfig *BuildConfig `json:"buildConfig,omitempty"` + EnvVars map[string]string `json:"envVars"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty"` + Image *string `json:"image,omitempty"` + Name string `json:"name"` + Source CreateProjectSourceDTO `json:"source"` + User *string `json:"user,omitempty"` } type _CreateProjectDTO CreateProjectDTO @@ -107,6 +108,38 @@ func (o *CreateProjectDTO) SetEnvVars(v map[string]string) { o.EnvVars = v } +// GetGitProviderConfigId returns the GitProviderConfigId field value if set, zero value otherwise. +func (o *CreateProjectDTO) GetGitProviderConfigId() string { + if o == nil || IsNil(o.GitProviderConfigId) { + var ret string + return ret + } + return *o.GitProviderConfigId +} + +// GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CreateProjectDTO) GetGitProviderConfigIdOk() (*string, bool) { + if o == nil || IsNil(o.GitProviderConfigId) { + return nil, false + } + return o.GitProviderConfigId, true +} + +// HasGitProviderConfigId returns a boolean if a field has been set. +func (o *CreateProjectDTO) HasGitProviderConfigId() bool { + if o != nil && !IsNil(o.GitProviderConfigId) { + return true + } + + return false +} + +// SetGitProviderConfigId gets a reference to the given string and assigns it to the GitProviderConfigId field. +func (o *CreateProjectDTO) SetGitProviderConfigId(v string) { + o.GitProviderConfigId = &v +} + // GetImage returns the Image field value if set, zero value otherwise. func (o *CreateProjectDTO) GetImage() string { if o == nil || IsNil(o.Image) { @@ -233,6 +266,9 @@ func (o CreateProjectDTO) ToMap() (map[string]interface{}, error) { toSerialize["buildConfig"] = o.BuildConfig } toSerialize["envVars"] = o.EnvVars + if !IsNil(o.GitProviderConfigId) { + toSerialize["gitProviderConfigId"] = o.GitProviderConfigId + } if !IsNil(o.Image) { toSerialize["image"] = o.Image } diff --git a/pkg/apiclient/model_git_provider.go b/pkg/apiclient/model_git_provider.go index f4af818674..25a322386e 100644 --- a/pkg/apiclient/model_git_provider.go +++ b/pkg/apiclient/model_git_provider.go @@ -21,8 +21,10 @@ var _ MappedNullable = &GitProvider{} // GitProvider struct for GitProvider type GitProvider struct { + Alias string `json:"alias"` BaseApiUrl *string `json:"baseApiUrl,omitempty"` Id string `json:"id"` + ProviderId string `json:"providerId"` Token string `json:"token"` Username string `json:"username"` } @@ -33,9 +35,11 @@ type _GitProvider GitProvider // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewGitProvider(id string, token string, username string) *GitProvider { +func NewGitProvider(alias string, id string, providerId string, token string, username string) *GitProvider { this := GitProvider{} + this.Alias = alias this.Id = id + this.ProviderId = providerId this.Token = token this.Username = username return &this @@ -49,6 +53,30 @@ func NewGitProviderWithDefaults() *GitProvider { return &this } +// GetAlias returns the Alias field value +func (o *GitProvider) GetAlias() string { + if o == nil { + var ret string + return ret + } + + return o.Alias +} + +// GetAliasOk returns a tuple with the Alias field value +// and a boolean to check if the value has been set. +func (o *GitProvider) GetAliasOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Alias, true +} + +// SetAlias sets field value +func (o *GitProvider) SetAlias(v string) { + o.Alias = v +} + // GetBaseApiUrl returns the BaseApiUrl field value if set, zero value otherwise. func (o *GitProvider) GetBaseApiUrl() string { if o == nil || IsNil(o.BaseApiUrl) { @@ -105,6 +133,30 @@ func (o *GitProvider) SetId(v string) { o.Id = v } +// GetProviderId returns the ProviderId field value +func (o *GitProvider) GetProviderId() string { + if o == nil { + var ret string + return ret + } + + return o.ProviderId +} + +// GetProviderIdOk returns a tuple with the ProviderId field value +// and a boolean to check if the value has been set. +func (o *GitProvider) GetProviderIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProviderId, true +} + +// SetProviderId sets field value +func (o *GitProvider) SetProviderId(v string) { + o.ProviderId = v +} + // GetToken returns the Token field value func (o *GitProvider) GetToken() string { if o == nil { @@ -163,10 +215,12 @@ func (o GitProvider) MarshalJSON() ([]byte, error) { func (o GitProvider) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} + toSerialize["alias"] = o.Alias if !IsNil(o.BaseApiUrl) { toSerialize["baseApiUrl"] = o.BaseApiUrl } toSerialize["id"] = o.Id + toSerialize["providerId"] = o.ProviderId toSerialize["token"] = o.Token toSerialize["username"] = o.Username return toSerialize, nil @@ -177,7 +231,9 @@ func (o *GitProvider) UnmarshalJSON(data []byte) (err error) { // by unmarshalling the object into a generic map with string keys and checking // that every required field exists as a key in the generic map. requiredProperties := []string{ + "alias", "id", + "providerId", "token", "username", } diff --git a/pkg/apiclient/model_project.go b/pkg/apiclient/model_project.go index f71dd21754..95951f8077 100644 --- a/pkg/apiclient/model_project.go +++ b/pkg/apiclient/model_project.go @@ -21,15 +21,16 @@ var _ MappedNullable = &Project{} // Project struct for Project type Project struct { - BuildConfig *BuildConfig `json:"buildConfig,omitempty"` - EnvVars map[string]string `json:"envVars"` - Image string `json:"image"` - Name string `json:"name"` - Repository GitRepository `json:"repository"` - State *ProjectState `json:"state,omitempty"` - Target string `json:"target"` - User string `json:"user"` - WorkspaceId string `json:"workspaceId"` + BuildConfig *BuildConfig `json:"buildConfig,omitempty"` + EnvVars map[string]string `json:"envVars"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty"` + Image string `json:"image"` + Name string `json:"name"` + Repository GitRepository `json:"repository"` + State *ProjectState `json:"state,omitempty"` + Target string `json:"target"` + User string `json:"user"` + WorkspaceId string `json:"workspaceId"` } type _Project Project @@ -114,6 +115,38 @@ func (o *Project) SetEnvVars(v map[string]string) { o.EnvVars = v } +// GetGitProviderConfigId returns the GitProviderConfigId field value if set, zero value otherwise. +func (o *Project) GetGitProviderConfigId() string { + if o == nil || IsNil(o.GitProviderConfigId) { + var ret string + return ret + } + return *o.GitProviderConfigId +} + +// GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Project) GetGitProviderConfigIdOk() (*string, bool) { + if o == nil || IsNil(o.GitProviderConfigId) { + return nil, false + } + return o.GitProviderConfigId, true +} + +// HasGitProviderConfigId returns a boolean if a field has been set. +func (o *Project) HasGitProviderConfigId() bool { + if o != nil && !IsNil(o.GitProviderConfigId) { + return true + } + + return false +} + +// SetGitProviderConfigId gets a reference to the given string and assigns it to the GitProviderConfigId field. +func (o *Project) SetGitProviderConfigId(v string) { + o.GitProviderConfigId = &v +} + // GetImage returns the Image field value func (o *Project) GetImage() string { if o == nil { @@ -304,6 +337,9 @@ func (o Project) ToMap() (map[string]interface{}, error) { toSerialize["buildConfig"] = o.BuildConfig } toSerialize["envVars"] = o.EnvVars + if !IsNil(o.GitProviderConfigId) { + toSerialize["gitProviderConfigId"] = o.GitProviderConfigId + } toSerialize["image"] = o.Image toSerialize["name"] = o.Name toSerialize["repository"] = o.Repository diff --git a/pkg/apiclient/model_project_config.go b/pkg/apiclient/model_project_config.go index cb1b7ab7b0..2e5b034213 100644 --- a/pkg/apiclient/model_project_config.go +++ b/pkg/apiclient/model_project_config.go @@ -21,14 +21,15 @@ var _ MappedNullable = &ProjectConfig{} // ProjectConfig struct for ProjectConfig type ProjectConfig struct { - BuildConfig *BuildConfig `json:"buildConfig,omitempty"` - Default bool `json:"default"` - EnvVars map[string]string `json:"envVars"` - Image string `json:"image"` - Name string `json:"name"` - Prebuilds []PrebuildConfig `json:"prebuilds,omitempty"` - RepositoryUrl string `json:"repositoryUrl"` - User string `json:"user"` + BuildConfig *BuildConfig `json:"buildConfig,omitempty"` + Default bool `json:"default"` + EnvVars map[string]string `json:"envVars"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty"` + Image string `json:"image"` + Name string `json:"name"` + Prebuilds []PrebuildConfig `json:"prebuilds,omitempty"` + RepositoryUrl string `json:"repositoryUrl"` + User string `json:"user"` } type _ProjectConfig ProjectConfig @@ -136,6 +137,38 @@ func (o *ProjectConfig) SetEnvVars(v map[string]string) { o.EnvVars = v } +// GetGitProviderConfigId returns the GitProviderConfigId field value if set, zero value otherwise. +func (o *ProjectConfig) GetGitProviderConfigId() string { + if o == nil || IsNil(o.GitProviderConfigId) { + var ret string + return ret + } + return *o.GitProviderConfigId +} + +// GetGitProviderConfigIdOk returns a tuple with the GitProviderConfigId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectConfig) GetGitProviderConfigIdOk() (*string, bool) { + if o == nil || IsNil(o.GitProviderConfigId) { + return nil, false + } + return o.GitProviderConfigId, true +} + +// HasGitProviderConfigId returns a boolean if a field has been set. +func (o *ProjectConfig) HasGitProviderConfigId() bool { + if o != nil && !IsNil(o.GitProviderConfigId) { + return true + } + + return false +} + +// SetGitProviderConfigId gets a reference to the given string and assigns it to the GitProviderConfigId field. +func (o *ProjectConfig) SetGitProviderConfigId(v string) { + o.GitProviderConfigId = &v +} + // GetImage returns the Image field value func (o *ProjectConfig) GetImage() string { if o == nil { @@ -279,6 +312,9 @@ func (o ProjectConfig) ToMap() (map[string]interface{}, error) { } toSerialize["default"] = o.Default toSerialize["envVars"] = o.EnvVars + if !IsNil(o.GitProviderConfigId) { + toSerialize["gitProviderConfigId"] = o.GitProviderConfigId + } toSerialize["image"] = o.Image toSerialize["name"] = o.Name if !IsNil(o.Prebuilds) { diff --git a/pkg/apiclient/model_set_git_provider_config.go b/pkg/apiclient/model_set_git_provider_config.go index 5fff1bb051..f55438f12b 100644 --- a/pkg/apiclient/model_set_git_provider_config.go +++ b/pkg/apiclient/model_set_git_provider_config.go @@ -21,8 +21,10 @@ var _ MappedNullable = &SetGitProviderConfig{} // SetGitProviderConfig struct for SetGitProviderConfig type SetGitProviderConfig struct { + Alias *string `json:"alias,omitempty"` BaseApiUrl *string `json:"baseApiUrl,omitempty"` - Id string `json:"id"` + Id *string `json:"id,omitempty"` + ProviderId string `json:"providerId"` Token string `json:"token"` Username *string `json:"username,omitempty"` } @@ -33,9 +35,9 @@ type _SetGitProviderConfig SetGitProviderConfig // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewSetGitProviderConfig(id string, token string) *SetGitProviderConfig { +func NewSetGitProviderConfig(providerId string, token string) *SetGitProviderConfig { this := SetGitProviderConfig{} - this.Id = id + this.ProviderId = providerId this.Token = token return &this } @@ -48,6 +50,38 @@ func NewSetGitProviderConfigWithDefaults() *SetGitProviderConfig { return &this } +// GetAlias returns the Alias field value if set, zero value otherwise. +func (o *SetGitProviderConfig) GetAlias() string { + if o == nil || IsNil(o.Alias) { + var ret string + return ret + } + return *o.Alias +} + +// GetAliasOk returns a tuple with the Alias field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SetGitProviderConfig) GetAliasOk() (*string, bool) { + if o == nil || IsNil(o.Alias) { + return nil, false + } + return o.Alias, true +} + +// HasAlias returns a boolean if a field has been set. +func (o *SetGitProviderConfig) HasAlias() bool { + if o != nil && !IsNil(o.Alias) { + return true + } + + return false +} + +// SetAlias gets a reference to the given string and assigns it to the Alias field. +func (o *SetGitProviderConfig) SetAlias(v string) { + o.Alias = &v +} + // GetBaseApiUrl returns the BaseApiUrl field value if set, zero value otherwise. func (o *SetGitProviderConfig) GetBaseApiUrl() string { if o == nil || IsNil(o.BaseApiUrl) { @@ -80,28 +114,60 @@ func (o *SetGitProviderConfig) SetBaseApiUrl(v string) { o.BaseApiUrl = &v } -// GetId returns the Id field value +// GetId returns the Id field value if set, zero value otherwise. func (o *SetGitProviderConfig) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SetGitProviderConfig) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *SetGitProviderConfig) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *SetGitProviderConfig) SetId(v string) { + o.Id = &v +} + +// GetProviderId returns the ProviderId field value +func (o *SetGitProviderConfig) GetProviderId() string { if o == nil { var ret string return ret } - return o.Id + return o.ProviderId } -// GetIdOk returns a tuple with the Id field value +// GetProviderIdOk returns a tuple with the ProviderId field value // and a boolean to check if the value has been set. -func (o *SetGitProviderConfig) GetIdOk() (*string, bool) { +func (o *SetGitProviderConfig) GetProviderIdOk() (*string, bool) { if o == nil { return nil, false } - return &o.Id, true + return &o.ProviderId, true } -// SetId sets field value -func (o *SetGitProviderConfig) SetId(v string) { - o.Id = v +// SetProviderId sets field value +func (o *SetGitProviderConfig) SetProviderId(v string) { + o.ProviderId = v } // GetToken returns the Token field value @@ -170,10 +236,16 @@ func (o SetGitProviderConfig) MarshalJSON() ([]byte, error) { func (o SetGitProviderConfig) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} + if !IsNil(o.Alias) { + toSerialize["alias"] = o.Alias + } if !IsNil(o.BaseApiUrl) { toSerialize["baseApiUrl"] = o.BaseApiUrl } - toSerialize["id"] = o.Id + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + toSerialize["providerId"] = o.ProviderId toSerialize["token"] = o.Token if !IsNil(o.Username) { toSerialize["username"] = o.Username @@ -186,7 +258,7 @@ func (o *SetGitProviderConfig) UnmarshalJSON(data []byte) (err error) { // by unmarshalling the object into a generic map with string keys and checking // that every required field exists as a key in the generic map. requiredProperties := []string{ - "id", + "providerId", "token", } diff --git a/pkg/cmd/gitprovider/add.go b/pkg/cmd/gitprovider/add.go index 7d6cc7c8d8..9b1bcecb2f 100644 --- a/pkg/cmd/gitprovider/add.go +++ b/pkg/cmd/gitprovider/add.go @@ -28,10 +28,11 @@ var GitProviderAddCmd = &cobra.Command{ setGitProviderConfig := apiclient.SetGitProviderConfig{} setGitProviderConfig.BaseApiUrl = new(string) setGitProviderConfig.Username = new(string) + setGitProviderConfig.Alias = new(string) - gitprovider_view.GitProviderSelectionView(&setGitProviderConfig, nil, false) + gitprovider_view.GitProviderSelectionView(ctx, &setGitProviderConfig, apiClient) - if setGitProviderConfig.Id == "" { + if setGitProviderConfig.ProviderId == "" { return nil } diff --git a/pkg/cmd/gitprovider/delete.go b/pkg/cmd/gitprovider/delete.go index 2fb08b4555..9f6424b8b5 100644 --- a/pkg/cmd/gitprovider/delete.go +++ b/pkg/cmd/gitprovider/delete.go @@ -31,22 +31,24 @@ var gitProviderDeleteCmd = &cobra.Command{ return apiclient_util.HandleErrorResponse(res, err) } - var gitProviderData apiclient.SetGitProviderConfig - gitProviderData.BaseApiUrl = new(string) - gitProviderData.Username = new(string) - if len(gitProviders) == 0 { views.RenderInfoMessage("No git providers registered") return nil } - gitprovider_view.GitProviderSelectionView(&gitProviderData, gitProviders, true) + var gitProviderData apiclient.SetGitProviderConfig + gitProviderData.Id = new(string) + gitProviderData.BaseApiUrl = new(string) + gitProviderData.Username = new(string) + gitProviderData.Alias = new(string) + + gitprovider_view.GitProviderDeleteView(&gitProviderData, gitProviders, apiClient, ctx) - if gitProviderData.Id == "" { + if *gitProviderData.Id == "" { return errors.New("git provider id can not be blank") } - _, err = apiClient.GitProviderAPI.RemoveGitProvider(ctx, gitProviderData.Id).Execute() + _, err = apiClient.GitProviderAPI.RemoveGitProvider(ctx, *gitProviderData.Id).Execute() if err != nil { return err } diff --git a/pkg/cmd/gitprovider/list.go b/pkg/cmd/gitprovider/list.go index 707bd3acd3..7bdedb1588 100644 --- a/pkg/cmd/gitprovider/list.go +++ b/pkg/cmd/gitprovider/list.go @@ -42,12 +42,14 @@ var gitProviderListCmd = &cobra.Command{ for _, gitProvider := range gitProviders { for _, supportedProvider := range supportedProviders { - if gitProvider.Id == supportedProvider.Id { + if gitProvider.ProviderId == supportedProvider.Id { gitProviderViewList = append(gitProviderViewList, gitprovider_view.GitProviderView{ - Id: gitProvider.Id, - Name: supportedProvider.Name, - Username: gitProvider.Username, + Id: gitProvider.Id, + ProviderId: gitProvider.ProviderId, + Name: supportedProvider.Name, + Username: gitProvider.Username, + Alias: gitProvider.Alias, }, ) } @@ -61,7 +63,7 @@ var gitProviderListCmd = &cobra.Command{ } for _, gitProviderView := range gitProviderViewList { - views.RenderListLine(fmt.Sprintf("%s (%s)", gitProviderView.Name, gitProviderView.Username)) + views.RenderListLine(fmt.Sprintf("%s (%s)", gitProviderView.Name, gitProviderView.Alias)) } return nil }, diff --git a/pkg/cmd/projectconfig/add.go b/pkg/cmd/projectconfig/add.go index c0d3da8061..66ac7e5a5a 100644 --- a/pkg/cmd/projectconfig/add.go +++ b/pkg/cmd/projectconfig/add.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "net/url" "github.com/daytonaio/daytona/internal/util" apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient" @@ -136,12 +137,13 @@ func RunProjectConfigAddFlow(apiClient *apiclient.APIClient, gitProviders []apic } createProjectConfig := apiclient.CreateProjectConfigDTO{ - Name: chosenName, - BuildConfig: createDtos[0].BuildConfig, - Image: createDtos[0].Image, - User: createDtos[0].User, - RepositoryUrl: createDtos[0].Source.Repository.Url, - EnvVars: createDtos[0].EnvVars, + Name: chosenName, + BuildConfig: createDtos[0].BuildConfig, + Image: createDtos[0].Image, + User: createDtos[0].User, + RepositoryUrl: createDtos[0].Source.Repository.Url, + EnvVars: createDtos[0].EnvVars, + GitProviderConfigId: createDtos[0].GitProviderConfigId, } res, err = apiClient.ProjectConfigAPI.SetProjectConfig(ctx).ProjectConfig(createProjectConfig).Execute() @@ -150,12 +152,13 @@ func RunProjectConfigAddFlow(apiClient *apiclient.APIClient, gitProviders []apic } projectConfig := apiclient.ProjectConfig{ - BuildConfig: createProjectConfig.BuildConfig, - Default: false, - EnvVars: createProjectConfig.EnvVars, - Name: createProjectConfig.Name, - Prebuilds: nil, - RepositoryUrl: createProjectConfig.RepositoryUrl, + BuildConfig: createProjectConfig.BuildConfig, + Default: false, + EnvVars: createProjectConfig.EnvVars, + Name: createProjectConfig.Name, + Prebuilds: nil, + RepositoryUrl: createProjectConfig.RepositoryUrl, + GitProviderConfigId: createProjectConfig.GitProviderConfigId, } if createProjectConfig.Image != nil { @@ -166,6 +169,14 @@ func RunProjectConfigAddFlow(apiClient *apiclient.APIClient, gitProviders []apic projectConfig.User = *createProjectConfig.User } + if createProjectConfig.GitProviderConfigId == nil && *createProjectConfig.GitProviderConfigId == "" { + gitProviderConfigId, res, err := apiClient.GitProviderAPI.GetGitProviderIdForUrl(ctx, url.QueryEscape(createProjectConfig.RepositoryUrl)).Execute() + if err != nil { + return nil, apiclient_util.HandleErrorResponse(res, err) + } + projectConfig.GitProviderConfigId = &gitProviderConfigId + } + return &projectConfig, nil } @@ -209,13 +220,22 @@ func processCmdArgument(argument string, apiClient *apiclient.APIClient, ctx con name = workspace_util.GetSuggestedName(projectName, existingProjectConfigNames) } + if project.GitProviderConfigId == nil || *project.GitProviderConfigId == "" { + gitProviderConfigId, res, err := apiClient.GitProviderAPI.GetGitProviderIdForUrl(ctx, url.QueryEscape(repoUrl)).Execute() + if err != nil { + return nil, apiclient_util.HandleErrorResponse(res, err) + } + *project.GitProviderConfigId = gitProviderConfigId + } + newProjectConfig := apiclient.CreateProjectConfigDTO{ - Name: name, - BuildConfig: project.BuildConfig, - Image: project.Image, - User: project.User, - RepositoryUrl: repoUrl, - EnvVars: project.EnvVars, + Name: name, + BuildConfig: project.BuildConfig, + Image: project.Image, + User: project.User, + RepositoryUrl: repoUrl, + EnvVars: project.EnvVars, + GitProviderConfigId: project.GitProviderConfigId, } if newProjectConfig.Image == nil { @@ -252,12 +272,14 @@ func getExistingProjectConfigNames(apiClient *apiclient.APIClient) ([]string, er var nameFlag string var projectConfigurationFlags = workspace_util.ProjectConfigurationFlags{ - Builder: new(views_util.BuildChoice), - CustomImage: new(string), - CustomImageUser: new(string), - DevcontainerPath: new(string), - EnvVars: new([]string), - Manual: new(bool), + Builder: new(views_util.BuildChoice), + CustomImage: new(string), + CustomImageUser: new(string), + Branches: new([]string), + DevcontainerPath: new(string), + EnvVars: new([]string), + Manual: new(bool), + GitProviderConfigId: new(string), } func init() { diff --git a/pkg/cmd/workspace/create.go b/pkg/cmd/workspace/create.go index 007d206040..97fb01a754 100644 --- a/pkg/cmd/workspace/create.go +++ b/pkg/cmd/workspace/create.go @@ -228,13 +228,14 @@ var blankFlag bool var multiProjectFlag bool var projectConfigurationFlags = workspace_util.ProjectConfigurationFlags{ - Builder: new(views_util.BuildChoice), - CustomImage: new(string), - CustomImageUser: new(string), - Branches: new([]string), - DevcontainerPath: new(string), - EnvVars: new([]string), - Manual: new(bool), + Builder: new(views_util.BuildChoice), + CustomImage: new(string), + CustomImageUser: new(string), + Branches: new([]string), + DevcontainerPath: new(string), + EnvVars: new([]string), + Manual: new(bool), + GitProviderConfigId: new(string), } func init() { @@ -403,6 +404,7 @@ func processGitURL(ctx context.Context, repoUrl string, apiClient *apiclient.API if !blankFlag { projectConfig, res, err := apiClient.ProjectConfigAPI.GetDefaultProjectConfig(ctx, encodedURLParam).Execute() if err == nil { + projectConfig.GitProviderConfigId = projectConfigurationFlags.GitProviderConfigId return workspace_util.AddProjectFromConfig(projectConfig, apiClient, projects, branch) } diff --git a/pkg/cmd/workspace/util/add_from_config.go b/pkg/cmd/workspace/util/add_from_config.go index 7271765aff..30b2de961b 100644 --- a/pkg/cmd/workspace/util/add_from_config.go +++ b/pkg/cmd/workspace/util/add_from_config.go @@ -38,7 +38,8 @@ func AddProjectFromConfig(projectConfig *apiclient.ProjectConfig, apiClient *api } project := &apiclient.CreateProjectDTO{ - Name: projectConfig.Name, + Name: projectConfig.Name, + GitProviderConfigId: projectConfig.GitProviderConfigId, Source: apiclient.CreateProjectSourceDTO{ Repository: *configRepo, }, diff --git a/pkg/cmd/workspace/util/branch_wizard.go b/pkg/cmd/workspace/util/branch_wizard.go index bd6d43efaf..b97e41f392 100644 --- a/pkg/cmd/workspace/util/branch_wizard.go +++ b/pkg/cmd/workspace/util/branch_wizard.go @@ -17,12 +17,13 @@ import ( ) type BranchWizardConfig struct { - ApiClient *apiclient.APIClient - ProviderId string - NamespaceId string - Namespace string - ChosenRepo *apiclient.GitRepository - ProjectOrder int + ApiClient *apiclient.APIClient + GitProviderConfigId string + NamespaceId string + Namespace string + ChosenRepo *apiclient.GitRepository + ProjectOrder int + ProviderId string } func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, error) { @@ -32,7 +33,7 @@ func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, e ctx := context.Background() err = views_util.WithSpinner("Loading", func() error { - branchList, _, err = config.ApiClient.GitProviderAPI.GetRepoBranches(ctx, config.ProviderId, url.QueryEscape(config.NamespaceId), url.QueryEscape(config.ChosenRepo.Id)).Execute() + branchList, _, err = config.ApiClient.GitProviderAPI.GetRepoBranches(ctx, config.GitProviderConfigId, url.QueryEscape(config.NamespaceId), url.QueryEscape(config.ChosenRepo.Id)).Execute() return err }) @@ -52,7 +53,7 @@ func SetBranchFromWizard(config BranchWizardConfig) (*apiclient.GitRepository, e var prList []apiclient.GitPullRequest err = views_util.WithSpinner("Loading", func() error { - prList, _, err = config.ApiClient.GitProviderAPI.GetRepoPRs(ctx, config.ProviderId, url.QueryEscape(config.NamespaceId), url.QueryEscape(config.ChosenRepo.Id)).Execute() + prList, _, err = config.ApiClient.GitProviderAPI.GetRepoPRs(ctx, config.GitProviderConfigId, url.QueryEscape(config.NamespaceId), url.QueryEscape(config.ChosenRepo.Id)).Execute() return err }) diff --git a/pkg/cmd/workspace/util/creation_data.go b/pkg/cmd/workspace/util/creation_data.go index ae65cbdf5c..0e9174af28 100644 --- a/pkg/cmd/workspace/util/creation_data.go +++ b/pkg/cmd/workspace/util/creation_data.go @@ -92,7 +92,8 @@ func GetProjectsCreationDataFromPrompt(config ProjectsDataPromptConfig) ([]apicl } createProjectDto := apiclient.CreateProjectDTO{ - Name: projectName, + Name: projectName, + GitProviderConfigId: projectConfig.GitProviderConfigId, Source: apiclient.CreateProjectSourceDTO{ Repository: *configRepo, }, @@ -110,6 +111,14 @@ func GetProjectsCreationDataFromPrompt(config ProjectsDataPromptConfig) ([]apicl createProjectDto.User = &projectConfig.User } + if projectConfig.GitProviderConfigId == nil || *projectConfig.GitProviderConfigId == "" { + gitProviderConfigId, res, err := config.ApiClient.GitProviderAPI.GetGitProviderIdForUrl(context.Background(), url.QueryEscape(projectConfig.RepositoryUrl)).Execute() + if err != nil { + return nil, apiclient_util.HandleErrorResponse(res, err) + } + createProjectDto.GitProviderConfigId = &gitProviderConfigId + } + projectList = append(projectList, createProjectDto) continue } @@ -141,7 +150,12 @@ func GetProjectsCreationDataFromPrompt(config ProjectsDataPromptConfig) ([]apicl return nil, err } - projectList = append(projectList, newCreateProjectConfigDTO(config, providerRepo, providerRepoName)) + gitProviderConfigId, res, err := config.ApiClient.GitProviderAPI.GetGitProviderIdForUrl(context.Background(), url.QueryEscape(providerRepo.Url)).Execute() + if err != nil { + return nil, apiclient_util.HandleErrorResponse(res, err) + } + + projectList = append(projectList, newCreateProjectConfigDTO(config, providerRepo, providerRepoName, gitProviderConfigId)) } return projectList, nil @@ -191,17 +205,17 @@ func GetBranchFromProjectConfig(projectConfig *apiclient.ProjectConfig, apiClien return nil, apiclient_util.HandleErrorResponse(res, err) } - providerId, res, err := apiClient.GitProviderAPI.GetGitProviderIdForUrl(ctx, encodedURLParam).Execute() + gitProviderConfigId, res, err := apiClient.GitProviderAPI.GetGitProviderIdForUrl(ctx, encodedURLParam).Execute() if err != nil { return nil, apiclient_util.HandleErrorResponse(res, err) } branchWizardConfig := BranchWizardConfig{ - ApiClient: apiClient, - ProviderId: providerId, - NamespaceId: repoResponse.Owner, - ChosenRepo: repoResponse, - ProjectOrder: projectOrder, + ApiClient: apiClient, + GitProviderConfigId: gitProviderConfigId, + NamespaceId: repoResponse.Owner, + ChosenRepo: repoResponse, + ProjectOrder: projectOrder, } repo, err := SetBranchFromWizard(branchWizardConfig) @@ -221,7 +235,8 @@ func GetBranchFromProjectConfig(projectConfig *apiclient.ProjectConfig, apiClien func GetCreateProjectDtoFromFlags(projectConfigurationFlags ProjectConfigurationFlags) (*apiclient.CreateProjectDTO, error) { project := &apiclient.CreateProjectDTO{ - BuildConfig: &apiclient.BuildConfig{}, + GitProviderConfigId: projectConfigurationFlags.GitProviderConfigId, + BuildConfig: &apiclient.BuildConfig{}, } if *projectConfigurationFlags.Builder == views_util.DEVCONTAINER || *projectConfigurationFlags.DevcontainerPath != "" { @@ -259,9 +274,10 @@ func GetCreateProjectDtoFromFlags(projectConfigurationFlags ProjectConfiguration return project, nil } -func newCreateProjectConfigDTO(config ProjectsDataPromptConfig, providerRepo *apiclient.GitRepository, providerRepoName string) apiclient.CreateProjectDTO { +func newCreateProjectConfigDTO(config ProjectsDataPromptConfig, providerRepo *apiclient.GitRepository, providerRepoName string, gitProviderConfigId string) apiclient.CreateProjectDTO { project := apiclient.CreateProjectDTO{ - Name: providerRepoName, + Name: providerRepoName, + GitProviderConfigId: &gitProviderConfigId, Source: apiclient.CreateProjectSourceDTO{ Repository: *providerRepo, }, diff --git a/pkg/cmd/workspace/util/repository_wizard.go b/pkg/cmd/workspace/util/repository_wizard.go index 88167d8471..7375ffc799 100644 --- a/pkg/cmd/workspace/util/repository_wizard.go +++ b/pkg/cmd/workspace/util/repository_wizard.go @@ -30,7 +30,7 @@ type RepositoryWizardConfig struct { } func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepository, error) { - var providerId string + var gitProviderConfigId string var namespaceId string var err error @@ -42,7 +42,8 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos } if (len(config.UserGitProviders) == 0 && len(samples) == 0) || config.Manual { - return create.GetRepositoryFromUrlInput(config.MultiProject, config.ProjectOrder, config.ApiClient, config.SelectedRepos) + repo, err := create.GetRepositoryFromUrlInput(config.MultiProject, config.ProjectOrder, config.ApiClient, config.SelectedRepos) + return repo, err } supportedProviders := config_const.GetSupportedGitProviders() @@ -50,28 +51,31 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos for _, gitProvider := range config.UserGitProviders { for _, supportedProvider := range supportedProviders { - if gitProvider.Id == supportedProvider.Id { + if gitProvider.ProviderId == supportedProvider.Id { gitProviderViewList = append(gitProviderViewList, gitprovider_view.GitProviderView{ - Id: gitProvider.Id, - Name: supportedProvider.Name, - Username: gitProvider.Username, + Id: gitProvider.Id, + ProviderId: gitProvider.ProviderId, + Name: supportedProvider.Name, + Username: gitProvider.Username, + Alias: gitProvider.Alias, }, ) } } } - providerId = selection.GetProviderIdFromPrompt(gitProviderViewList, config.ProjectOrder, len(samples) > 0) - if providerId == "" { + gitProviderConfigId = selection.GetProviderIdFromPrompt(gitProviderViewList, config.ProjectOrder, len(samples) > 0) + if gitProviderConfigId == "" { return nil, common.ErrCtrlCAbort } - if providerId == selection.CustomRepoIdentifier { - return create.GetRepositoryFromUrlInput(config.MultiProject, config.ProjectOrder, config.ApiClient, config.SelectedRepos) + if gitProviderConfigId == selection.CustomRepoIdentifier { + repo, err := create.GetRepositoryFromUrlInput(config.MultiProject, config.ProjectOrder, config.ApiClient, config.SelectedRepos) + return repo, err } - if providerId == selection.CREATE_FROM_SAMPLE { + if gitProviderConfigId == selection.CREATE_FROM_SAMPLE { sample := selection.GetSampleFromPrompt(samples) if sample == nil { return nil, common.ErrCtrlCAbort @@ -87,10 +91,17 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos return repo, nil } + var providerId string + for _, gp := range gitProviderViewList { + if gp.Id == gitProviderConfigId { + providerId = gp.ProviderId + } + } + var namespaceList []apiclient.GitNamespace err = views_util.WithSpinner("Loading", func() error { - namespaceList, _, err = config.ApiClient.GitProviderAPI.GetNamespaces(ctx, providerId).Execute() + namespaceList, _, err = config.ApiClient.GitProviderAPI.GetNamespaces(ctx, gitProviderConfigId).Execute() return err }) if err != nil { @@ -115,7 +126,7 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos var providerRepos []apiclient.GitRepository err = views_util.WithSpinner("Loading", func() error { - providerRepos, _, err = config.ApiClient.GitProviderAPI.GetRepositories(ctx, providerId, namespaceId).Execute() + providerRepos, _, err = config.ApiClient.GitProviderAPI.GetRepositories(ctx, gitProviderConfigId, namespaceId).Execute() return err }) @@ -134,11 +145,12 @@ func getRepositoryFromWizard(config RepositoryWizardConfig) (*apiclient.GitRepos } return SetBranchFromWizard(BranchWizardConfig{ - ApiClient: config.ApiClient, - ProviderId: providerId, - NamespaceId: namespaceId, - Namespace: namespace, - ChosenRepo: chosenRepo, - ProjectOrder: config.ProjectOrder, + ApiClient: config.ApiClient, + GitProviderConfigId: gitProviderConfigId, + NamespaceId: namespaceId, + Namespace: namespace, + ChosenRepo: chosenRepo, + ProjectOrder: config.ProjectOrder, + ProviderId: providerId, }) } diff --git a/pkg/cmd/workspace/util/workspace.go b/pkg/cmd/workspace/util/workspace.go index c82583273f..ffb95bce96 100644 --- a/pkg/cmd/workspace/util/workspace.go +++ b/pkg/cmd/workspace/util/workspace.go @@ -13,13 +13,14 @@ import ( ) type ProjectConfigurationFlags struct { - Builder *views_util.BuildChoice - CustomImage *string - CustomImageUser *string - Branches *[]string - DevcontainerPath *string - EnvVars *[]string - Manual *bool + Builder *views_util.BuildChoice + CustomImage *string + CustomImageUser *string + Branches *[]string + DevcontainerPath *string + EnvVars *[]string + Manual *bool + GitProviderConfigId *string } func AddProjectConfigurationFlags(cmd *cobra.Command, flags ProjectConfigurationFlags, multiProjectFlagException bool) { @@ -29,6 +30,7 @@ func AddProjectConfigurationFlags(cmd *cobra.Command, flags ProjectConfiguration cmd.Flags().Var(flags.Builder, "builder", fmt.Sprintf("Specify the builder (currently %s/%s/%s)", views_util.AUTOMATIC, views_util.DEVCONTAINER, views_util.NONE)) cmd.Flags().StringArrayVar(flags.EnvVars, "env", []string{}, "Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...')") cmd.Flags().BoolVar(flags.Manual, "manual", false, "Manually enter the Git repository") + cmd.Flags().StringVar(flags.GitProviderConfigId, "git-provider-config-id", "", "Specify the Git Provider Configuration Id") cmd.MarkFlagsMutuallyExclusive("builder", "custom-image") cmd.MarkFlagsMutuallyExclusive("builder", "custom-image-user") @@ -46,7 +48,7 @@ func AddProjectConfigurationFlags(cmd *cobra.Command, flags ProjectConfiguration } func CheckAnyProjectConfigurationFlagSet(flags ProjectConfigurationFlags) bool { - return *flags.CustomImage != "" || *flags.CustomImageUser != "" || *flags.DevcontainerPath != "" || *flags.Builder != "" || len(*flags.EnvVars) > 0 + return *flags.GitProviderConfigId != "" || *flags.CustomImage != "" || *flags.CustomImageUser != "" || *flags.DevcontainerPath != "" || *flags.Builder != "" || len(*flags.EnvVars) > 0 } func IsProjectRunning(workspace *apiclient.WorkspaceDTO, projectName string) bool { diff --git a/pkg/db/dto/git_provider.go b/pkg/db/dto/git_provider.go index aba25d1689..5b99d87fcb 100644 --- a/pkg/db/dto/git_provider.go +++ b/pkg/db/dto/git_provider.go @@ -9,17 +9,21 @@ import ( type GitProviderConfigDTO struct { Id string `gorm:"primaryKey"` + ProviderId string `json:"providerId"` Username string `json:"username"` Token string `json:"token"` BaseApiUrl *string `json:"baseApiUrl,omitempty"` + Alias string `json:"alias"` } func ToGitProviderConfigDTO(gitProvider gitprovider.GitProviderConfig) GitProviderConfigDTO { gitProviderDTO := GitProviderConfigDTO{ Id: gitProvider.Id, + ProviderId: gitProvider.ProviderId, Username: gitProvider.Username, Token: gitProvider.Token, BaseApiUrl: gitProvider.BaseApiUrl, + Alias: gitProvider.Alias, } return gitProviderDTO @@ -28,8 +32,10 @@ func ToGitProviderConfigDTO(gitProvider gitprovider.GitProviderConfig) GitProvid func ToGitProviderConfig(gitProviderDTO GitProviderConfigDTO) gitprovider.GitProviderConfig { return gitprovider.GitProviderConfig{ Id: gitProviderDTO.Id, + ProviderId: gitProviderDTO.ProviderId, Username: gitProviderDTO.Username, Token: gitProviderDTO.Token, BaseApiUrl: gitProviderDTO.BaseApiUrl, + Alias: gitProviderDTO.Alias, } } diff --git a/pkg/db/dto/project.go b/pkg/db/dto/project.go index 8a3ecb4dde..04a34d4372 100644 --- a/pkg/db/dto/project.go +++ b/pkg/db/dto/project.go @@ -52,28 +52,30 @@ type ProjectBuildDTO struct { } type ProjectDTO struct { - Name string `json:"name"` - Image string `json:"image"` - User string `json:"user"` - Build *ProjectBuildDTO `json:"build,omitempty" gorm:"serializer:json"` - Repository RepositoryDTO `json:"repository" gorm:"serializer:json"` - WorkspaceId string `json:"workspaceId"` - Target string `json:"target"` - ApiKey string `json:"apiKey"` - State *ProjectStateDTO `json:"state,omitempty" gorm:"serializer:json"` + Name string `json:"name"` + Image string `json:"image"` + User string `json:"user"` + Build *ProjectBuildDTO `json:"build,omitempty" gorm:"serializer:json"` + Repository RepositoryDTO `json:"repository" gorm:"serializer:json"` + WorkspaceId string `json:"workspaceId"` + Target string `json:"target"` + ApiKey string `json:"apiKey"` + State *ProjectStateDTO `json:"state,omitempty" gorm:"serializer:json"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty"` } func ToProjectDTO(project *project.Project) ProjectDTO { return ProjectDTO{ - Name: project.Name, - Image: project.Image, - User: project.User, - Build: ToProjectBuildDTO(project.BuildConfig), - Repository: ToRepositoryDTO(project.Repository), - WorkspaceId: project.WorkspaceId, - Target: project.Target, - State: ToProjectStateDTO(project.State), - ApiKey: project.ApiKey, + Name: project.Name, + Image: project.Image, + User: project.User, + Build: ToProjectBuildDTO(project.BuildConfig), + Repository: ToRepositoryDTO(project.Repository), + WorkspaceId: project.WorkspaceId, + Target: project.Target, + State: ToProjectStateDTO(project.State), + ApiKey: project.ApiKey, + GitProviderConfigId: project.GitProviderConfigId, } } @@ -156,15 +158,16 @@ func ToProjectBuildDTO(build *buildconfig.BuildConfig) *ProjectBuildDTO { func ToProject(projectDTO ProjectDTO) *project.Project { return &project.Project{ - Name: projectDTO.Name, - Image: projectDTO.Image, - User: projectDTO.User, - BuildConfig: ToProjectBuild(projectDTO.Build), - Repository: ToRepository(projectDTO.Repository), - WorkspaceId: projectDTO.WorkspaceId, - Target: projectDTO.Target, - State: ToProjectState(projectDTO.State), - ApiKey: projectDTO.ApiKey, + Name: projectDTO.Name, + Image: projectDTO.Image, + User: projectDTO.User, + BuildConfig: ToProjectBuild(projectDTO.Build), + Repository: ToRepository(projectDTO.Repository), + WorkspaceId: projectDTO.WorkspaceId, + Target: projectDTO.Target, + State: ToProjectState(projectDTO.State), + ApiKey: projectDTO.ApiKey, + GitProviderConfigId: projectDTO.GitProviderConfigId, } } diff --git a/pkg/db/dto/project_config.go b/pkg/db/dto/project_config.go index dd1c611f80..a0a5f9c92a 100644 --- a/pkg/db/dto/project_config.go +++ b/pkg/db/dto/project_config.go @@ -8,14 +8,15 @@ import ( ) type ProjectConfigDTO struct { - Name string `gorm:"primaryKey"` - Image string `json:"image"` - User string `json:"user"` - Build *ProjectBuildDTO `json:"build,omitempty" gorm:"serializer:json"` - RepositoryUrl string `json:"repositoryUrl"` - EnvVars map[string]string `json:"envVars" gorm:"serializer:json"` - Prebuilds []PrebuildDTO `gorm:"serializer:json"` - IsDefault bool `json:"isDefault"` + Name string `gorm:"primaryKey"` + Image string `json:"image"` + User string `json:"user"` + Build *ProjectBuildDTO `json:"build,omitempty" gorm:"serializer:json"` + RepositoryUrl string `json:"repositoryUrl"` + EnvVars map[string]string `json:"envVars" gorm:"serializer:json"` + Prebuilds []PrebuildDTO `gorm:"serializer:json"` + IsDefault bool `json:"isDefault"` + GitProviderConfigId *string `json:"gitProviderConfigId" validate:"optional"` } type PrebuildDTO struct { @@ -33,14 +34,15 @@ func ToProjectConfigDTO(projectConfig *config.ProjectConfig) ProjectConfigDTO { } return ProjectConfigDTO{ - Name: projectConfig.Name, - Image: projectConfig.Image, - User: projectConfig.User, - Build: ToProjectBuildDTO(projectConfig.BuildConfig), - RepositoryUrl: projectConfig.RepositoryUrl, - EnvVars: projectConfig.EnvVars, - Prebuilds: prebuilds, - IsDefault: projectConfig.IsDefault, + Name: projectConfig.Name, + Image: projectConfig.Image, + User: projectConfig.User, + Build: ToProjectBuildDTO(projectConfig.BuildConfig), + RepositoryUrl: projectConfig.RepositoryUrl, + EnvVars: projectConfig.EnvVars, + Prebuilds: prebuilds, + IsDefault: projectConfig.IsDefault, + GitProviderConfigId: projectConfig.GitProviderConfigId, } } @@ -51,14 +53,15 @@ func ToProjectConfig(projectConfigDTO ProjectConfigDTO) *config.ProjectConfig { } return &config.ProjectConfig{ - Name: projectConfigDTO.Name, - Image: projectConfigDTO.Image, - User: projectConfigDTO.User, - BuildConfig: ToProjectBuild(projectConfigDTO.Build), - RepositoryUrl: projectConfigDTO.RepositoryUrl, - EnvVars: projectConfigDTO.EnvVars, - Prebuilds: prebuilds, - IsDefault: projectConfigDTO.IsDefault, + Name: projectConfigDTO.Name, + Image: projectConfigDTO.Image, + User: projectConfigDTO.User, + BuildConfig: ToProjectBuild(projectConfigDTO.Build), + RepositoryUrl: projectConfigDTO.RepositoryUrl, + EnvVars: projectConfigDTO.EnvVars, + Prebuilds: prebuilds, + IsDefault: projectConfigDTO.IsDefault, + GitProviderConfigId: projectConfigDTO.GitProviderConfigId, } } diff --git a/pkg/gitprovider/types.go b/pkg/gitprovider/types.go index 202069cd93..c88444d959 100644 --- a/pkg/gitprovider/types.go +++ b/pkg/gitprovider/types.go @@ -5,9 +5,11 @@ package gitprovider type GitProviderConfig struct { Id string `json:"id" validate:"required"` + ProviderId string `json:"providerId" validate:"required"` Username string `json:"username" validate:"required"` BaseApiUrl *string `json:"baseApiUrl,omitempty" validate:"optional"` Token string `json:"token" validate:"required"` + Alias string `json:"alias" validate:"required"` } // @name GitProvider type GitUser struct { diff --git a/pkg/server/gitproviders/gitprovider.go b/pkg/server/gitproviders/gitprovider.go index fc67541a7a..66b21ad3f5 100644 --- a/pkg/server/gitproviders/gitprovider.go +++ b/pkg/server/gitproviders/gitprovider.go @@ -11,6 +11,7 @@ import ( "github.com/daytonaio/daytona/cmd/daytona/config" "github.com/daytonaio/daytona/pkg/gitprovider" + "github.com/docker/docker/pkg/stringid" ) func (s *GitProviderService) GetGitProviderForUrl(repoUrl string) (gitprovider.GitProvider, string, error) { @@ -22,31 +23,38 @@ func (s *GitProviderService) GetGitProviderForUrl(repoUrl string) (gitprovider.G for _, p := range gitProviders { gitProvider, err := s.GetGitProvider(p.Id) if err != nil { - return nil, "", err + continue } canHandle, _ := gitProvider.CanHandle(repoUrl) if canHandle { - return gitProvider, p.Id, nil + _, err = gitProvider.GetRepositoryContext(gitprovider.GetRepositoryContext{ + Url: repoUrl, + }) + if err == nil { + return gitProvider, p.Id, nil + } } } - u, err := url.Parse(repoUrl) - if err != nil { - return nil, "", nil + for _, p := range config.GetSupportedGitProviders() { + gitProvider, err := s.newGitProvider(&gitprovider.GitProviderConfig{ + ProviderId: p.Id, + Id: p.Id, + Username: "", + Token: "", + BaseApiUrl: nil, + }) + if err != nil { + continue + } + canHandle, _ := gitProvider.CanHandle(repoUrl) + if canHandle { + return gitProvider, p.Id, nil + } } - hostname := strings.TrimPrefix(u.Hostname(), "www.") - providerId := strings.Split(hostname, ".")[0] - - gitProvider, err := s.newGitProvider(&gitprovider.GitProviderConfig{ - Id: providerId, - Username: "", - Token: "", - BaseApiUrl: nil, - }) - - return gitProvider, providerId, err + return nil, "", errors.New("can not get public client for the URL " + repoUrl) } func (s *GitProviderService) GetConfigForUrl(repoUrl string) (*gitprovider.GitProviderConfig, error) { @@ -66,8 +74,14 @@ func (s *GitProviderService) GetConfigForUrl(repoUrl string) (*gitprovider.GitPr canHandle, _ := gitProvider.CanHandle(repoUrl) if canHandle { - return p, nil + _, err = gitProvider.GetRepositoryContext(gitprovider.GetRepositoryContext{ + Url: repoUrl, + }) + if err == nil { + return p, nil + } } + } supportedGitProviders := config.GetSupportedGitProviders() @@ -118,6 +132,15 @@ func (s *GitProviderService) SetGitProviderConfig(providerConfig *gitprovider.Gi return err } providerConfig.Username = userData.Username + if providerConfig.Id == "" { + id := stringid.GenerateRandomID() + id = stringid.TruncateID(id) + providerConfig.Id = id + } + + if providerConfig.Alias == "" { + providerConfig.Alias = userData.Username + } return s.configStore.Save(providerConfig) } diff --git a/pkg/server/gitproviders/service.go b/pkg/server/gitproviders/service.go index c29b2ea6fd..4b3ec59e7a 100644 --- a/pkg/server/gitproviders/service.go +++ b/pkg/server/gitproviders/service.go @@ -55,6 +55,7 @@ func (s *GitProviderService) GetGitProvider(id string) (gitprovider.GitProvider, if gitprovider.IsGitProviderNotFound(err) { providerConfig = &gitprovider.GitProviderConfig{ Id: id, + ProviderId: id, Username: "", Token: "", BaseApiUrl: nil, @@ -88,8 +89,8 @@ func (s *GitProviderService) GetLastCommitSha(repo *gitprovider.GitRepository) ( for _, p := range gitProviders { isAwsUrl := strings.Contains(repo.Url, ".amazonaws.com/") || strings.Contains(repo.Url, ".console.aws.amazon.com/") - if p.Id == "aws-codecommit" && isAwsUrl { - provider, err = s.GetGitProvider(p.Id) + if p.ProviderId == "aws-codecommit" && isAwsUrl { + provider, err = s.GetGitProvider(p.ProviderId) if err == nil { return "", err } @@ -97,8 +98,8 @@ func (s *GitProviderService) GetLastCommitSha(repo *gitprovider.GitRepository) ( break } - if strings.Contains(repo.Url, fmt.Sprintf("%s.", p.Id)) { - provider, err = s.GetGitProvider(p.Id) + if strings.Contains(repo.Url, fmt.Sprintf("%s.", p.ProviderId)) { + provider, err = s.GetGitProvider(p.ProviderId) if err == nil { return "", err } @@ -112,7 +113,7 @@ func (s *GitProviderService) GetLastCommitSha(repo *gitprovider.GitRepository) ( } if p.BaseApiUrl != nil && strings.Contains(repo.Url, hostname) { - provider, err = s.GetGitProvider(p.Id) + provider, err = s.GetGitProvider(p.ProviderId) if err == nil { return "", err } @@ -127,7 +128,8 @@ func (s *GitProviderService) GetLastCommitSha(repo *gitprovider.GitRepository) ( providerId := strings.Split(hostname, ".")[0] provider, err = s.newGitProvider(&gitprovider.GitProviderConfig{ - Id: providerId, + Id: "", + ProviderId: providerId, Username: "", Token: "", BaseApiUrl: nil, @@ -151,7 +153,7 @@ func (s *GitProviderService) GetLastCommitSha(repo *gitprovider.GitRepository) ( } func (s *GitProviderService) newGitProvider(config *gitprovider.GitProviderConfig) (gitprovider.GitProvider, error) { - switch config.Id { + switch config.ProviderId { case "github": return gitprovider.NewGitHubGitProvider(config.Token, nil), nil case "github-enterprise-server": diff --git a/pkg/server/projectconfig/dto/projectconfig.go b/pkg/server/projectconfig/dto/projectconfig.go index 56b64c95d5..9ff6ab4082 100644 --- a/pkg/server/projectconfig/dto/projectconfig.go +++ b/pkg/server/projectconfig/dto/projectconfig.go @@ -8,12 +8,13 @@ import ( ) type CreateProjectConfigDTO struct { - Name string `json:"name" validate:"required"` - Image *string `json:"image,omitempty" validate:"optional"` - User *string `json:"user,omitempty" validate:"optional"` - BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` - RepositoryUrl string `json:"repositoryUrl" validate:"required"` - EnvVars map[string]string `json:"envVars" validate:"required"` + Name string `json:"name" validate:"required"` + Image *string `json:"image,omitempty" validate:"optional"` + User *string `json:"user,omitempty" validate:"optional"` + BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` + RepositoryUrl string `json:"repositoryUrl" validate:"required"` + EnvVars map[string]string `json:"envVars" validate:"required"` + GitProviderConfigId *string `json:"gitProviderConfigId" validate:"optional"` } // @name CreateProjectConfigDTO type PrebuildDTO struct { diff --git a/pkg/server/workspaces/create.go b/pkg/server/workspaces/create.go index 8e06544bfd..1797e86fa2 100644 --- a/pkg/server/workspaces/create.go +++ b/pkg/server/workspaces/create.go @@ -78,6 +78,15 @@ func (s *WorkspaceService) CreateWorkspace(ctx context.Context, req dto.CreateWo } p.Repository.Url = util.CleanUpRepositoryUrl(p.Repository.Url) + if p.GitProviderConfigId == nil || *p.GitProviderConfigId == "" { + _, id, err := s.gitProviderService.GetGitProviderForUrl(p.Repository.Url) + if err != nil { + return nil, err + } + p.GitProviderConfigId = &id + + } + if p.Repository.Sha == "" { sha, err := s.gitProviderService.GetLastCommitSha(p.Repository) if err != nil { diff --git a/pkg/server/workspaces/dto/workspace.go b/pkg/server/workspaces/dto/workspace.go index 56ef278ff6..a5fea289ad 100644 --- a/pkg/server/workspaces/dto/workspace.go +++ b/pkg/server/workspaces/dto/workspace.go @@ -28,12 +28,13 @@ type CreateWorkspaceDTO struct { } // @name CreateWorkspaceDTO type CreateProjectDTO struct { - Name string `json:"name" validate:"required"` - Image *string `json:"image,omitempty" validate:"optional"` - User *string `json:"user,omitempty" validate:"optional"` - BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` - Source CreateProjectSourceDTO `json:"source" validate:"required"` - EnvVars map[string]string `json:"envVars" validate:"required"` + Name string `json:"name" validate:"required"` + Image *string `json:"image,omitempty" validate:"optional"` + User *string `json:"user,omitempty" validate:"optional"` + BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` + Source CreateProjectSourceDTO `json:"source" validate:"required"` + EnvVars map[string]string `json:"envVars" validate:"required"` + GitProviderConfigId *string `json:"gitProviderConfigId" validate:"optional"` } // @name CreateProjectDTO type CreateProjectSourceDTO struct { diff --git a/pkg/server/workspaces/service_test.go b/pkg/server/workspaces/service_test.go index 9f598eac39..583461ba61 100644 --- a/pkg/server/workspaces/service_test.go +++ b/pkg/server/workspaces/service_test.go @@ -39,6 +39,18 @@ var target = provider.ProviderTarget{ }, Options: "test-options", } +var gitProviderConfigId = "github" + +var baseApiUrl = "https://api.github.com" + +var gitProviderConfig = gitprovider.GitProviderConfig{ + Id: "github", + ProviderId: gitProviderConfigId, + Alias: "test-alias", + Username: "test-username", + Token: "test-token", + BaseApiUrl: &baseApiUrl, +} var createWorkspaceDto = dto.CreateWorkspaceDTO{ Name: "test", @@ -46,12 +58,15 @@ var createWorkspaceDto = dto.CreateWorkspaceDTO{ Target: target.Name, Projects: []dto.CreateProjectDTO{ { - Name: "project1", + Name: "project1", + GitProviderConfigId: &gitProviderConfig.Id, Source: dto.CreateProjectSourceDTO{ Repository: &gitprovider.GitRepository{ - Id: "123", - Url: "https://github.com/daytonaio/daytona", - Name: "daytona", + Id: "123", + Url: "https://github.com/daytonaio/daytona", + Name: "daytona", + Branch: "main", + Sha: "sha1", }, }, Image: util.Pointer(defaultProjectImage), @@ -118,14 +133,6 @@ func TestWorkspaceService(t *testing.T) { apiKeyService.On("Generate", apikey.ApiKeyTypeWorkspace, createWorkspaceDto.Id).Return(createWorkspaceDto.Id, nil) gitProviderService.On("GetLastCommitSha", createWorkspaceDto.Projects[0].Source.Repository).Return("123", nil) - baseApiUrl := "https://api.github.com" - gitProviderConfig := gitprovider.GitProviderConfig{ - Id: "github", - Username: "test-username", - Token: "test-token", - BaseApiUrl: &baseApiUrl, - } - for _, project := range createWorkspaceDto.Projects { apiKeyService.On("Generate", apikey.ApiKeyTypeProject, fmt.Sprintf("%s/%s", createWorkspaceDto.Id, project.Name)).Return(project.Name, nil) } @@ -260,13 +267,6 @@ func TestWorkspaceService(t *testing.T) { apiKeyService.On("Generate", apikey.ApiKeyTypeWorkspace, createWorkspaceDto.Id).Return(createWorkspaceDto.Id, nil) gitProviderService.On("GetLastCommitSha", createWorkspaceDto.Projects[0].Source.Repository).Return("123", nil) - baseApiUrl := "https://api.github.com" - gitProviderConfig := gitprovider.GitProviderConfig{ - Id: "github", - Username: "test-username", - Token: "test-token", - BaseApiUrl: &baseApiUrl, - } gitProviderService.On("GetConfigForUrl", "https://github.com/daytonaio/daytona").Return(&gitProviderConfig, nil) for _, project := range createWorkspaceDto.Projects { diff --git a/pkg/views/gitprovider/select.go b/pkg/views/gitprovider/select.go index 5bc5978190..7aa72cd324 100644 --- a/pkg/views/gitprovider/select.go +++ b/pkg/views/gitprovider/select.go @@ -4,6 +4,7 @@ package gitprovider import ( + "context" "errors" "fmt" "log" @@ -16,34 +17,18 @@ import ( "github.com/daytonaio/daytona/pkg/views" ) -type GitProviderView struct { - Id string - Name string - Username string - BaseApiUrl string - Token string -} - var commonGitProviderIds = []string{"github", "gitlab", "bitbucket"} -func GitProviderSelectionView(gitProviderAddView *apiclient.SetGitProviderConfig, userGitProviders []apiclient.GitProvider, isDeleting bool) { +func GitProviderSelectionView(ctx context.Context, gitProviderAddView *apiclient.SetGitProviderConfig, apiClient *apiclient.APIClient) { supportedProviders := config.GetSupportedGitProviders() var gitProviderOptions []huh.Option[string] var otherGitProviderOptions []huh.Option[string] for _, supportedProvider := range supportedProviders { - if isDeleting { - for _, userProvider := range userGitProviders { - if userProvider.Id == supportedProvider.Id { - gitProviderOptions = append(gitProviderOptions, huh.Option[string]{Key: supportedProvider.Name, Value: supportedProvider.Id}) - } - } + if slices.Contains(commonGitProviderIds, supportedProvider.Id) { + gitProviderOptions = append(gitProviderOptions, huh.Option[string]{Key: supportedProvider.Name, Value: supportedProvider.Id}) } else { - if slices.Contains(commonGitProviderIds, supportedProvider.Id) { - gitProviderOptions = append(gitProviderOptions, huh.Option[string]{Key: supportedProvider.Name, Value: supportedProvider.Id}) - } else { - otherGitProviderOptions = append(otherGitProviderOptions, huh.Option[string]{Key: supportedProvider.Name, Value: supportedProvider.Id}) - } + otherGitProviderOptions = append(otherGitProviderOptions, huh.Option[string]{Key: supportedProvider.Name, Value: supportedProvider.Id}) } } @@ -58,15 +43,15 @@ func GitProviderSelectionView(gitProviderAddView *apiclient.SetGitProviderConfig Options( gitProviderOptions..., ). - Value(&gitProviderAddView.Id)).WithHeight(8), + Value(&gitProviderAddView.ProviderId)).WithHeight(8), huh.NewGroup( huh.NewSelect[string](). Title("Choose a Git provider"). Options( otherGitProviderOptions..., ). - Value(&gitProviderAddView.Id)).WithHeight(12).WithHideFunc(func() bool { - return gitProviderAddView.Id != "other" + Value(&gitProviderAddView.ProviderId)).WithHeight(12).WithHideFunc(func() bool { + return gitProviderAddView.ProviderId != "other" }), ).WithTheme(views.GetCustomTheme()) @@ -87,13 +72,13 @@ func GitProviderSelectionView(gitProviderAddView *apiclient.SetGitProviderConfig return nil }), ).WithHeight(5).WithHideFunc(func() bool { - return isDeleting || !providerRequiresUsername(gitProviderAddView.Id) + return !providerRequiresUsername(gitProviderAddView.ProviderId) }), huh.NewGroup( huh.NewInput(). Title("Self-managed API URL"). Value(gitProviderAddView.BaseApiUrl). - Description(getApiUrlDescription(gitProviderAddView.Id)). + Description(getApiUrlDescription(gitProviderAddView.ProviderId)). Validate(func(str string) error { if str == "" { return errors.New("URL can not be blank") @@ -101,7 +86,7 @@ func GitProviderSelectionView(gitProviderAddView *apiclient.SetGitProviderConfig return nil }), ).WithHeight(6).WithHideFunc(func() bool { - return isDeleting || !providerRequiresApiUrl(gitProviderAddView.Id) + return !providerRequiresApiUrl(gitProviderAddView.ProviderId) }), huh.NewGroup( huh.NewInput(). @@ -114,17 +99,42 @@ func GitProviderSelectionView(gitProviderAddView *apiclient.SetGitProviderConfig } return nil }), - ).WithHeight(5).WithHide(isDeleting), + ).WithHeight(5), + huh.NewGroup( + huh.NewInput(). + Title("Alias"). + Description("Will default to username if left empty"). + Value(gitProviderAddView.Alias), + ).WithHeight(6), ).WithTheme(views.GetCustomTheme()) - if !isDeleting { - views.RenderInfoMessage(getGitProviderHelpMessage(gitProviderAddView.Id)) + views.RenderInfoMessage(getGitProviderHelpMessage(gitProviderAddView.ProviderId)) + err = userDataForm.Run() + if err != nil { + log.Fatal(err) } - err = userDataForm.Run() +} + +func GitProviderDeleteView(gitProviderAddView *apiclient.SetGitProviderConfig, userGitProviders []apiclient.GitProvider, apiClient *apiclient.APIClient, ctx context.Context) { + var gitProviderOptions []huh.Option[string] + for _, userProvider := range userGitProviders { + gitProviderOptions = append(gitProviderOptions, huh.Option[string]{Key: fmt.Sprintf("%s %s", userProvider.ProviderId, userProvider.Alias), Value: userProvider.Id}) + } + gitProviderForm := huh.NewForm( + huh.NewGroup( + huh.NewSelect[string](). + Title("Choose a Git provider"). + Options( + gitProviderOptions..., + ). + Value(gitProviderAddView.Id)).WithHeight(8), + ).WithTheme(views.GetCustomTheme()) + err := gitProviderForm.Run() if err != nil { log.Fatal(err) } + } func providerRequiresUsername(gitProviderId string) bool { diff --git a/pkg/views/gitprovider/types.go b/pkg/views/gitprovider/types.go new file mode 100644 index 0000000000..46e40b7cb6 --- /dev/null +++ b/pkg/views/gitprovider/types.go @@ -0,0 +1,14 @@ +// Copyright 2024 Daytona Platforms Inc. +// SPDX-License-Identifier: Apache-2.0 + +package gitprovider + +type GitProviderView struct { + Id string + ProviderId string + Name string + Username string + BaseApiUrl string + Token string + Alias string +} diff --git a/pkg/views/workspace/selection/gitprovider.go b/pkg/views/workspace/selection/gitprovider.go index f9e0d1c2a9..1000f7c420 100644 --- a/pkg/views/workspace/selection/gitprovider.go +++ b/pkg/views/workspace/selection/gitprovider.go @@ -22,7 +22,7 @@ func selectGitProviderPrompt(gitProviders []gitprovider_view.GitProviderView, pr // Populate items with titles and descriptions from workspaces. for _, provider := range gitProviders { - newItem := item[string]{id: provider.Id, title: provider.Name, choiceProperty: provider.Id} + newItem := item[string]{id: provider.Id, title: fmt.Sprintf("%s (%s)", provider.Name, provider.Alias), choiceProperty: provider.Id} items = append(items, newItem) } @@ -61,6 +61,5 @@ func GetProviderIdFromPrompt(gitProviders []gitprovider_view.GitProviderView, pr choiceChan := make(chan string) go selectGitProviderPrompt(gitProviders, projectOrder, choiceChan, samplesEnabled) - return <-choiceChan } diff --git a/pkg/workspace/project/config/config.go b/pkg/workspace/project/config/config.go index 30a9a165e3..f7c7e42d91 100644 --- a/pkg/workspace/project/config/config.go +++ b/pkg/workspace/project/config/config.go @@ -10,14 +10,15 @@ import ( ) type ProjectConfig struct { - Name string `json:"name" validate:"required"` - Image string `json:"image" validate:"required"` - User string `json:"user" validate:"required"` - BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` - RepositoryUrl string `json:"repositoryUrl" validate:"required"` - EnvVars map[string]string `json:"envVars" validate:"required"` - IsDefault bool `json:"default" validate:"required"` - Prebuilds []*PrebuildConfig `json:"prebuilds" validate:"optional"` + Name string `json:"name" validate:"required"` + Image string `json:"image" validate:"required"` + User string `json:"user" validate:"required"` + BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` + RepositoryUrl string `json:"repositoryUrl" validate:"required"` + EnvVars map[string]string `json:"envVars" validate:"required"` + IsDefault bool `json:"default" validate:"required"` + Prebuilds []*PrebuildConfig `json:"prebuilds" validate:"optional"` + GitProviderConfigId *string `json:"gitProviderConfigId" validate:"optional"` } // @name ProjectConfig func (pc *ProjectConfig) SetPrebuild(p *PrebuildConfig) error { diff --git a/pkg/workspace/project/project.go b/pkg/workspace/project/project.go index 52d9d4b0ad..e0655c6370 100644 --- a/pkg/workspace/project/project.go +++ b/pkg/workspace/project/project.go @@ -12,16 +12,17 @@ import ( ) type Project struct { - Name string `json:"name" validate:"required"` - Image string `json:"image" validate:"required"` - User string `json:"user" validate:"required"` - BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` - Repository *gitprovider.GitRepository `json:"repository" validate:"required"` - EnvVars map[string]string `json:"envVars" validate:"required"` - WorkspaceId string `json:"workspaceId" validate:"required"` - ApiKey string `json:"-"` - Target string `json:"target" validate:"required"` - State *ProjectState `json:"state,omitempty" validate:"optional"` + Name string `json:"name" validate:"required"` + Image string `json:"image" validate:"required"` + User string `json:"user" validate:"required"` + BuildConfig *buildconfig.BuildConfig `json:"buildConfig,omitempty" validate:"optional"` + Repository *gitprovider.GitRepository `json:"repository" validate:"required"` + EnvVars map[string]string `json:"envVars" validate:"required"` + WorkspaceId string `json:"workspaceId" validate:"required"` + ApiKey string `json:"-"` + Target string `json:"target" validate:"required"` + State *ProjectState `json:"state,omitempty" validate:"optional"` + GitProviderConfigId *string `json:"gitProviderConfigId,omitempty" validate:"optional"` } // @name Project type ProjectInfo struct {