types: add RemoteSourceID to Project

In future we may support specifying a remote source for a project without a
linked account and thus use a user provided token (saved in the project) or
other ways to define a remote repo (like standard git repos over ssh).
This commit is contained in:
Simone Gotti 2019-05-03 09:55:37 +02:00
parent b9db3137ad
commit 6943c10dc9
2 changed files with 11 additions and 3 deletions

View File

@ -41,6 +41,12 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
if !util.ValidateName(req.Name) { if !util.ValidateName(req.Name) {
return nil, util.NewErrBadRequest(errors.Errorf("invalid project name %q", req.Name)) return nil, util.NewErrBadRequest(errors.Errorf("invalid project name %q", req.Name))
} }
if req.RemoteSourceName == "" {
return nil, util.NewErrBadRequest(errors.Errorf("empty remote source name"))
}
if req.RepoPath == "" {
return nil, util.NewErrBadRequest(errors.Errorf("empty remote repo path name"))
}
user, resp, err := c.configstoreClient.GetUser(ctx, req.CurrentUserID) user, resp, err := c.configstoreClient.GetUser(ctx, req.CurrentUserID)
if err != nil { if err != nil {
@ -49,7 +55,6 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName) rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
if err != nil { if err != nil {
c.log.Errorf("err: %+v", err)
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
} }
c.log.Infof("rs: %s", util.Dump(rs)) c.log.Infof("rs: %s", util.Dump(rs))
@ -94,6 +99,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
ID: parentID, ID: parentID,
}, },
Visibility: req.Visibility, Visibility: req.Visibility,
RemoteSourceID: rs.ID,
LinkedAccountID: la.ID, LinkedAccountID: la.ID,
RepositoryID: repo.ID, RepositoryID: repo.ID,
RepositoryPath: req.RepoPath, RepositoryPath: req.RepoPath,

View File

@ -160,6 +160,10 @@ type Project struct {
Visibility Visibility `json:"visibility,omitempty"` Visibility Visibility `json:"visibility,omitempty"`
// Remote Repository fields
RemoteSourceID string `json:"remote_source_id,omitempty"`
LinkedAccountID string `json:"linked_account_id,omitempty"`
// The remote repository id // The remote repository id
RepositoryID string `json:"repository_id,omitempty"` RepositoryID string `json:"repository_id,omitempty"`
@ -171,8 +175,6 @@ type Project struct {
// do this but gitlab can and github has an hidden api to do this) // do this but gitlab can and github has an hidden api to do this)
RepositoryPath string `json:"repository_path,omitempty"` RepositoryPath string `json:"repository_path,omitempty"`
LinkedAccountID string `json:"linked_account_id,omitempty"`
SSHPrivateKey string `json:"ssh_private_key,omitempty"` // PEM Encoded private key SSHPrivateKey string `json:"ssh_private_key,omitempty"` // PEM Encoded private key
SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check,omitempty"` SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check,omitempty"`