environment.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // WebhookID uniquely identifies the environment when other fields (project, cluster)
  18. // aren't present
  19. WebhookID string `gorm:"unique"`
  20. GithubWebhookID int64
  21. }
  22. func (e *Environment) ToEnvironmentType() *types.Environment {
  23. return &types.Environment{
  24. ID: e.Model.ID,
  25. ProjectID: e.ProjectID,
  26. ClusterID: e.ClusterID,
  27. GitInstallationID: e.GitInstallationID,
  28. GitRepoOwner: e.GitRepoOwner,
  29. GitRepoName: e.GitRepoName,
  30. NewCommentsDisabled: e.NewCommentsDisabled,
  31. Name: e.Name,
  32. Mode: e.Mode,
  33. }
  34. }
  35. type Deployment struct {
  36. gorm.Model
  37. EnvironmentID uint
  38. Namespace string
  39. Status types.DeploymentStatus
  40. Subdomain string
  41. PullRequestID uint
  42. GHDeploymentID int64
  43. GHPRCommentID int64
  44. PRName string
  45. RepoName string
  46. RepoOwner string
  47. CommitSHA string
  48. PRBranchFrom string
  49. PRBranchInto string
  50. }
  51. func (d *Deployment) ToDeploymentType() *types.Deployment {
  52. ghMetadata := &types.GitHubMetadata{
  53. DeploymentID: d.GHDeploymentID,
  54. PRName: d.PRName,
  55. RepoName: d.RepoName,
  56. RepoOwner: d.RepoOwner,
  57. CommitSHA: d.CommitSHA,
  58. PRBranchFrom: d.PRBranchFrom,
  59. PRBranchInto: d.PRBranchInto,
  60. }
  61. return &types.Deployment{
  62. CreatedAt: d.CreatedAt,
  63. UpdatedAt: d.UpdatedAt,
  64. ID: d.Model.ID,
  65. EnvironmentID: d.EnvironmentID,
  66. Namespace: d.Namespace,
  67. Status: d.Status,
  68. Subdomain: d.Subdomain,
  69. PullRequestID: d.PullRequestID,
  70. GitHubMetadata: ghMetadata,
  71. }
  72. }