2
0

environment.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package models
  2. import (
  3. "github.com/mitchellh/mapstructure"
  4. "github.com/porter-dev/porter/api/types"
  5. "gorm.io/gorm"
  6. )
  7. type EnvironmentMode uint
  8. type Environment struct {
  9. gorm.Model
  10. ProjectID uint
  11. ClusterID uint
  12. GitInstallationID uint
  13. GitRepoOwner string
  14. GitRepoName string
  15. Name string
  16. Mode string
  17. NewCommentsDisabled bool
  18. CustomNamespace bool
  19. NamespaceAnnotations []byte
  20. // WebhookID uniquely identifies the environment when other fields (project, cluster)
  21. // aren't present
  22. WebhookID string `gorm:"unique"`
  23. GithubWebhookID int64
  24. }
  25. func (e *Environment) ToEnvironmentType() *types.Environment {
  26. env := &types.Environment{
  27. ID: e.Model.ID,
  28. ProjectID: e.ProjectID,
  29. ClusterID: e.ClusterID,
  30. GitInstallationID: e.GitInstallationID,
  31. GitRepoOwner: e.GitRepoOwner,
  32. GitRepoName: e.GitRepoName,
  33. NewCommentsDisabled: e.NewCommentsDisabled,
  34. CustomNamespace: e.CustomNamespace,
  35. NamespaceAnnotations: make(map[string]string),
  36. Name: e.Name,
  37. Mode: e.Mode,
  38. }
  39. // FIXME: should not ignore the error here
  40. mapstructure.Decode(e.NamespaceAnnotations, &env.NamespaceAnnotations)
  41. return env
  42. }
  43. type Deployment struct {
  44. gorm.Model
  45. EnvironmentID uint
  46. Namespace string
  47. Status types.DeploymentStatus
  48. Subdomain string
  49. PullRequestID uint
  50. GHDeploymentID int64
  51. GHPRCommentID int64
  52. PRName string
  53. RepoName string
  54. RepoOwner string
  55. CommitSHA string
  56. PRBranchFrom string
  57. PRBranchInto string
  58. }
  59. func (d *Deployment) ToDeploymentType() *types.Deployment {
  60. ghMetadata := &types.GitHubMetadata{
  61. DeploymentID: d.GHDeploymentID,
  62. PRName: d.PRName,
  63. RepoName: d.RepoName,
  64. RepoOwner: d.RepoOwner,
  65. CommitSHA: d.CommitSHA,
  66. PRBranchFrom: d.PRBranchFrom,
  67. PRBranchInto: d.PRBranchInto,
  68. }
  69. return &types.Deployment{
  70. CreatedAt: d.CreatedAt,
  71. UpdatedAt: d.UpdatedAt,
  72. ID: d.Model.ID,
  73. EnvironmentID: d.EnvironmentID,
  74. Namespace: d.Namespace,
  75. Status: d.Status,
  76. Subdomain: d.Subdomain,
  77. PullRequestID: d.PullRequestID,
  78. GitHubMetadata: ghMetadata,
  79. }
  80. }