environment.go 1.7 KB

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