release.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. "gorm.io/gorm"
  5. )
  6. // Release model used to retrieve webhook tokens for a chart.
  7. // Release type that extends gorm.Model
  8. type Release struct {
  9. gorm.Model
  10. WebhookToken string `json:"webhook_token" gorm:"unique"`
  11. ClusterID uint `json:"cluster_id"`
  12. ProjectID uint `json:"project_id"`
  13. Name string `json:"name"`
  14. Namespace string `json:"namespace"`
  15. // The complete image repository uri to pull from. This is also stored in GitActionConfig,
  16. // but this should be used for the source of truth going forward.
  17. ImageRepoURI string `json:"image_repo_uri,omitempty"`
  18. GitActionConfig *GitActionConfig `json:"git_action_config"`
  19. NotificationConfig uint
  20. }
  21. // ReleaseExternal represents the Release type that is sent over REST
  22. type ReleaseExternal struct {
  23. ID uint `json:"id"`
  24. WebhookToken string `json:"webhook_token"`
  25. GitActionConfig *GitActionConfigExternal `json:"git_action_config,omitempty"`
  26. }
  27. // Externalize generates an external User to be shared over REST
  28. func (r *Release) Externalize() *ReleaseExternal {
  29. return &ReleaseExternal{
  30. ID: r.ID,
  31. WebhookToken: r.WebhookToken,
  32. GitActionConfig: r.GitActionConfig.Externalize(),
  33. }
  34. }
  35. func (r *Release) ToReleaseType() *types.PorterRelease {
  36. res := &types.PorterRelease{
  37. ID: r.ID,
  38. WebhookToken: r.WebhookToken,
  39. }
  40. if r.GitActionConfig != nil {
  41. res.GitActionConfig = r.GitActionConfig.ToGitActionConfigType()
  42. }
  43. return res
  44. }