environment.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. "gorm.io/gorm"
  5. )
  6. type EnvironmentMode uint
  7. type Environment struct {
  8. gorm.Model
  9. ProjectID uint
  10. ClusterID uint
  11. GitInstallationID uint
  12. GitRepoOwner string
  13. GitRepoName string
  14. Name string
  15. Mode string
  16. NewCommentsDisabled bool
  17. CustomNamespace bool
  18. NamespaceAnnotations []byte
  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. NewCommentsDisabled: e.NewCommentsDisabled,
  33. Name: e.Name,
  34. Mode: e.Mode,
  35. }
  36. }
  37. type Deployment struct {
  38. gorm.Model
  39. EnvironmentID uint
  40. Namespace string
  41. Status types.DeploymentStatus
  42. Subdomain string
  43. PullRequestID uint
  44. GHDeploymentID int64
  45. GHPRCommentID int64
  46. PRName string
  47. RepoName string
  48. RepoOwner string
  49. CommitSHA string
  50. PRBranchFrom string
  51. PRBranchInto string
  52. }
  53. func (d *Deployment) ToDeploymentType() *types.Deployment {
  54. ghMetadata := &types.GitHubMetadata{
  55. DeploymentID: d.GHDeploymentID,
  56. PRName: d.PRName,
  57. RepoName: d.RepoName,
  58. RepoOwner: d.RepoOwner,
  59. CommitSHA: d.CommitSHA,
  60. PRBranchFrom: d.PRBranchFrom,
  61. PRBranchInto: d.PRBranchInto,
  62. }
  63. return &types.Deployment{
  64. CreatedAt: d.CreatedAt,
  65. UpdatedAt: d.UpdatedAt,
  66. ID: d.Model.ID,
  67. EnvironmentID: d.EnvironmentID,
  68. Namespace: d.Namespace,
  69. Status: d.Status,
  70. Subdomain: d.Subdomain,
  71. PullRequestID: d.PullRequestID,
  72. GitHubMetadata: ghMetadata,
  73. }
  74. }