environment.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package models
  2. import (
  3. "strings"
  4. "github.com/porter-dev/porter/api/types"
  5. "gorm.io/gorm"
  6. )
  7. type EnvironmentMode uint
  8. type Environment struct {
  9. gorm.Model
  10. ProjectID uint
  11. ClusterID uint
  12. GitInstallationID uint
  13. GitRepoOwner string
  14. GitRepoName string
  15. GitRepoBranches string
  16. Name string
  17. Mode string
  18. NewCommentsDisabled bool
  19. // WebhookID uniquely identifies the environment when other fields (project, cluster)
  20. // aren't present
  21. WebhookID string `gorm:"unique"`
  22. GithubWebhookID int64
  23. }
  24. func (e *Environment) ToEnvironmentType() *types.Environment {
  25. return &types.Environment{
  26. ID: e.Model.ID,
  27. ProjectID: e.ProjectID,
  28. ClusterID: e.ClusterID,
  29. GitInstallationID: e.GitInstallationID,
  30. GitRepoOwner: e.GitRepoOwner,
  31. GitRepoName: e.GitRepoName,
  32. GitRepoBranches: strings.Split(e.GitRepoBranches, ","),
  33. NewCommentsDisabled: e.NewCommentsDisabled,
  34. Name: e.Name,
  35. Mode: e.Mode,
  36. }
  37. }
  38. type Deployment struct {
  39. gorm.Model
  40. EnvironmentID uint
  41. Namespace string
  42. Status types.DeploymentStatus
  43. Subdomain string
  44. PullRequestID uint
  45. GHDeploymentID int64
  46. GHPRCommentID int64
  47. PRName string
  48. RepoName string
  49. RepoOwner string
  50. CommitSHA string
  51. PRBranchFrom string
  52. PRBranchInto string
  53. }
  54. func (d *Deployment) ToDeploymentType() *types.Deployment {
  55. ghMetadata := &types.GitHubMetadata{
  56. DeploymentID: d.GHDeploymentID,
  57. PRName: d.PRName,
  58. RepoName: d.RepoName,
  59. RepoOwner: d.RepoOwner,
  60. CommitSHA: d.CommitSHA,
  61. PRBranchFrom: d.PRBranchFrom,
  62. PRBranchInto: d.PRBranchInto,
  63. }
  64. return &types.Deployment{
  65. CreatedAt: d.CreatedAt,
  66. UpdatedAt: d.UpdatedAt,
  67. ID: d.Model.ID,
  68. EnvironmentID: d.EnvironmentID,
  69. Namespace: d.Namespace,
  70. Status: d.Status,
  71. Subdomain: d.Subdomain,
  72. PullRequestID: d.PullRequestID,
  73. GitHubMetadata: ghMetadata,
  74. }
  75. }