environment.go 1.8 KB

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