environment.go 1.7 KB

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