mirror of https://github.com/harness/drone.git
feat: [CDE-195]: gitness use repo ref (#2336)
* feat: [CDE-195]: gitness use repo ref * feat: [CDE-195]: UI changes for type and ref. * feat: [CDE-195]: gitness use repo refpull/3545/head v1.0.3-gitspaces-beta
parent
910c4819c7
commit
1e6330a589
|
@ -67,8 +67,11 @@ func (c *Controller) Action(
|
|||
}
|
||||
|
||||
// check if it's an internal repo
|
||||
if gitspaceConfig.CodeRepoType == enum.CodeRepoTypeGitness && gitspaceConfig.CodeRepoURL != "" {
|
||||
repo, err := c.repoStore.FindByRef(ctx, gitspaceConfig.CodeRepoURL)
|
||||
if gitspaceConfig.CodeRepoType == enum.CodeRepoTypeGitness {
|
||||
if gitspaceConfig.CodeRepoRef == nil {
|
||||
return nil, fmt.Errorf("couldn't fetch repo for the user, no ref found: %w", err)
|
||||
}
|
||||
repo, err := c.repoStore.FindByRef(ctx, *gitspaceConfig.CodeRepoRef)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't fetch repo for the user: %w", err)
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ type CreateInput struct {
|
|||
ResourceSpaceRef string `json:"resource_space_ref"`
|
||||
CodeRepoURL string `json:"code_repo_url"`
|
||||
CodeRepoType enum.GitspaceCodeRepoType `json:"code_repo_type"`
|
||||
CodeRepoRef *string `json:"code_repo_ref"`
|
||||
Branch string `json:"branch"`
|
||||
DevcontainerPath *string `json:"devcontainer_path"`
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
|
@ -77,8 +78,8 @@ func (c *Controller) Create(
|
|||
return nil, err
|
||||
}
|
||||
// check if it's an internal repo
|
||||
if in.CodeRepoType == enum.CodeRepoTypeGitness && in.CodeRepoURL != "" {
|
||||
repo, err := c.repoStore.FindByRef(ctx, in.CodeRepoURL)
|
||||
if in.CodeRepoType == enum.CodeRepoTypeGitness && *in.CodeRepoRef != "" {
|
||||
repo, err := c.repoStore.FindByRef(ctx, *in.CodeRepoRef)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't fetch repo for the user: %w", err)
|
||||
}
|
||||
|
@ -140,6 +141,7 @@ func (c *Controller) Create(
|
|||
CodeRepoType: in.CodeRepoType,
|
||||
State: enum.GitspaceStateUninitialized,
|
||||
CodeRepoURL: in.CodeRepoURL,
|
||||
CodeRepoRef: in.CodeRepoRef,
|
||||
Branch: in.Branch,
|
||||
DevcontainerPath: in.DevcontainerPath,
|
||||
UserID: session.Principal.UID,
|
||||
|
|
|
@ -69,7 +69,7 @@ func (s GitnessSCM) ResolveCredentials(
|
|||
return nil, fmt.Errorf("failed to parse repository URL %s: %w", gitspaceConfig.CodeRepoURL, err)
|
||||
}
|
||||
repoName := strings.TrimSuffix(path.Base(repoURL.Path), ".git")
|
||||
repo, err := s.repoStore.FindByRef(ctx, gitspaceConfig.CodeRepoURL)
|
||||
repo, err := s.repoStore.FindByRef(ctx, *gitspaceConfig.CodeRepoRef)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find repository: %w", err)
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func (s GitnessSCM) GetFileContent(ctx context.Context,
|
|||
gitspaceConfig *types.GitspaceConfig,
|
||||
filePath string,
|
||||
) ([]byte, error) {
|
||||
repo, err := s.repoStore.FindByRef(ctx, gitspaceConfig.CodeRepoURL)
|
||||
repo, err := s.repoStore.FindByRef(ctx, *gitspaceConfig.CodeRepoRef)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find repository: %w", err)
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ const (
|
|||
gconf_space_id,
|
||||
gconf_created,
|
||||
gconf_updated,
|
||||
gconf_is_deleted
|
||||
gconf_is_deleted,
|
||||
gconf_code_repo_ref
|
||||
`
|
||||
gitspaceConfigsTable = `gitspace_configs`
|
||||
ReturningClause = "RETURNING "
|
||||
|
@ -61,6 +62,7 @@ type gitspaceConfig struct {
|
|||
IDE enum.IDEType `db:"gconf_ide"`
|
||||
InfraProviderResourceID int64 `db:"gconf_infra_provider_resource_id"`
|
||||
CodeAuthType string `db:"gconf_code_auth_type"`
|
||||
CodeRepoRef null.String `db:"gconf_code_repo_ref"`
|
||||
CodeAuthID string `db:"gconf_code_auth_id"`
|
||||
CodeRepoType enum.GitspaceCodeRepoType `db:"gconf_code_repo_type"`
|
||||
CodeRepoIsPrivate bool `db:"gconf_code_repo_is_private"`
|
||||
|
@ -170,6 +172,7 @@ func (s gitspaceConfigStore) Create(ctx context.Context, gitspaceConfig *types.G
|
|||
gitspaceConfig.Created,
|
||||
gitspaceConfig.Updated,
|
||||
gitspaceConfig.IsDeleted,
|
||||
gitspaceConfig.CodeRepoRef,
|
||||
).
|
||||
Suffix(ReturningClause + "gconf_id")
|
||||
sql, args, err := stmt.ToSql()
|
||||
|
@ -216,6 +219,7 @@ func mapToInternalGitspaceConfig(config *types.GitspaceConfig) *gitspaceConfig {
|
|||
CodeAuthID: config.CodeAuthID,
|
||||
CodeRepoIsPrivate: config.CodeRepoIsPrivate,
|
||||
CodeRepoType: config.CodeRepoType,
|
||||
CodeRepoRef: null.StringFromPtr(config.CodeRepoRef),
|
||||
CodeRepoURL: config.CodeRepoURL,
|
||||
DevcontainerPath: null.StringFromPtr(config.DevcontainerPath),
|
||||
Branch: config.Branch,
|
||||
|
@ -284,6 +288,7 @@ func (s *gitspaceConfigStore) mapToGitspaceConfig(
|
|||
InfraProviderResourceID: in.InfraProviderResourceID,
|
||||
IDE: in.IDE,
|
||||
CodeRepoType: in.CodeRepoType,
|
||||
CodeRepoRef: in.CodeRepoRef.Ptr(),
|
||||
CodeRepoURL: in.CodeRepoURL,
|
||||
Branch: in.Branch,
|
||||
DevcontainerPath: in.DevcontainerPath.Ptr(),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE gitspace_configs DROP COLUMN gconf_code_repo_ref;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE gitspace_configs ADD COLUMN gconf_code_repo_ref TEXT;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE gitspace_configs DROP COLUMN gconf_code_repo_ref;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE gitspace_configs ADD COLUMN gconf_code_repo_ref TEXT;
|
|
@ -27,6 +27,7 @@ type GitspaceConfig struct {
|
|||
InfraProviderResourceID int64 `json:"-"`
|
||||
InfraProviderResourceIdentifier string `json:"resource_identifier"`
|
||||
CodeRepoURL string `json:"code_repo_url"`
|
||||
CodeRepoRef *string `json:"code_repo_ref"`
|
||||
CodeRepoType enum.GitspaceCodeRepoType `json:"code_repo_type"`
|
||||
Branch string `json:"branch"`
|
||||
DevcontainerPath *string `json:"devcontainer_path,omitempty"`
|
||||
|
|
|
@ -13,6 +13,7 @@ import NewRepoModalButton from 'components/NewRepoModalButton/NewRepoModalButton
|
|||
import noRepo from 'cde-gitness/assests/noRepo.svg?url'
|
||||
import { RepoCreationType } from 'utils/GitUtils'
|
||||
import gitnessRepoLogo from 'cde-gitness/assests/gitness.svg?url'
|
||||
import { EnumGitspaceCodeRepoType } from 'cde-gitness/constants'
|
||||
import { GitspaceSelect } from '../../../cde/components/GitspaceSelect/GitspaceSelect'
|
||||
import css from './GitnessRepoImportForm.module.scss'
|
||||
|
||||
|
@ -166,7 +167,9 @@ export const GitnessRepoImportForm = () => {
|
|||
code_repo_url: repo.git_url,
|
||||
branch: repo.default_branch,
|
||||
identifier: repoParams?.[repoParams.length - 1],
|
||||
name: repo.path
|
||||
name: repo.path,
|
||||
code_repo_ref: repo.path,
|
||||
code_repo_type: EnumGitspaceCodeRepoType.GITNESS
|
||||
}
|
||||
})
|
||||
formik.setFieldValue('code_repo_url', repo.git_url)
|
||||
|
|
|
@ -18,6 +18,7 @@ import NewRepoModalButton from 'components/NewRepoModalButton/NewRepoModalButton
|
|||
import { RepoCreationType } from 'utils/GitUtils'
|
||||
import { useAppContext } from 'AppContext'
|
||||
import { OpenapiCreateGitspaceRequest, useGitspacelookup } from 'cde-gitness/services'
|
||||
import { EnumGitspaceCodeRepoType } from 'cde-gitness/constants'
|
||||
import css from './ThirdPartyRepoImportForm.module.scss'
|
||||
|
||||
enum RepoCheckStatus {
|
||||
|
@ -56,7 +57,8 @@ export const ThirdPartyRepoImportForm = () => {
|
|||
code_repo_url: response.url,
|
||||
branch: response.branch,
|
||||
identifier: getRepoIdFromURL(response.url),
|
||||
name: getRepoNameFromURL(response.url)
|
||||
name: getRepoNameFromURL(response.url),
|
||||
code_repo_type: EnumGitspaceCodeRepoType.UNKNOWN
|
||||
}
|
||||
})
|
||||
setRepoCheckState(RepoCheckStatus.Valid)
|
||||
|
|
|
@ -2,3 +2,12 @@ export enum StandaloneIDEType {
|
|||
VSCODE = 'vs_code',
|
||||
VSCODEWEB = 'vs_code_web'
|
||||
}
|
||||
|
||||
export enum EnumGitspaceCodeRepoType {
|
||||
GITHUB = 'github',
|
||||
GITLAB = 'gitlab',
|
||||
HARNESS_CODE = 'harness_code',
|
||||
BITBUCKET = 'bitbucket',
|
||||
UNKNOWN = 'unknown',
|
||||
GITNESS = 'gitness'
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export type EnumFileDiffStatus = string
|
|||
|
||||
export type EnumGitspaceAccessType = 'jwt_token' | 'user_credentials' | 'ssh_key'
|
||||
|
||||
export type EnumGitspaceCodeRepoType = 'github' | 'gitlab' | 'harness_code' | 'bitbucket' | 'unknown'
|
||||
export type EnumGitspaceCodeRepoType = 'github' | 'gitlab' | 'harness_code' | 'bitbucket' | 'unknown' | 'gitness'
|
||||
|
||||
export type EnumGitspaceEntityType = 'gitspace_config' | 'gitspace_instance'
|
||||
|
||||
|
@ -318,7 +318,9 @@ export interface OpenapiCreateConnectorRequest {
|
|||
|
||||
export interface OpenapiCreateGitspaceRequest {
|
||||
branch?: string
|
||||
code_repo_url?: string
|
||||
code_repo_url?: string | null
|
||||
code_repo_ref?: string
|
||||
code_repo_type?: EnumGitspaceCodeRepoType
|
||||
devcontainer_path?: string | null
|
||||
ide?: EnumIDEType
|
||||
identifier?: string
|
||||
|
|
Loading…
Reference in New Issue