release.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. StackResourceID uint
  16. // The complete image repository uri to pull from. This is also stored in GitActionConfig,
  17. // but this should be used for the source of truth going forward.
  18. ImageRepoURI string `json:"image_repo_uri,omitempty"`
  19. GitActionConfig *GitActionConfig `json:"git_action_config"`
  20. EventContainer uint
  21. NotificationConfig uint
  22. BuildConfig uint
  23. Tags []*Tag `json:"tags" gorm:"many2many:release_tags"`
  24. // A configurable canonical name of a Porter release
  25. CanonicalName string
  26. }
  27. func (r *Release) ToReleaseType() *types.PorterRelease {
  28. res := &types.PorterRelease{
  29. ID: r.ID,
  30. WebhookToken: r.WebhookToken,
  31. ImageRepoURI: r.ImageRepoURI,
  32. CanonicalName: r.CanonicalName,
  33. }
  34. if r.GitActionConfig != nil {
  35. res.GitActionConfig = r.GitActionConfig.ToGitActionConfigType()
  36. }
  37. tagsCount := len(r.Tags)
  38. if tagsCount > 0 {
  39. for i := 0; i < tagsCount; i++ {
  40. res.Tags = append(res.Tags, r.Tags[i].Name)
  41. }
  42. }
  43. return res
  44. }