porter_app.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. "github.com/porter-dev/porter/api/types"
  5. )
  6. // PorterApp (stack) type that extends gorm.Model
  7. type PorterApp struct {
  8. gorm.Model
  9. ProjectID uint
  10. ClusterID uint
  11. Name string
  12. ImageRepoURI string
  13. // Git repo information (optional)
  14. GitRepoID uint
  15. RepoName string
  16. GitBranch string
  17. GithubWebhookID int64 `gorm:"-"` // do not use in read/writes. this is temporary until migrations are run
  18. BuildContext string
  19. Builder string
  20. Buildpacks string
  21. Dockerfile string
  22. PullRequestURL string
  23. // Porter YAML
  24. PorterYamlPath string
  25. }
  26. // ToPorterAppType generates an external types.PorterApp to be shared over REST
  27. func (a *PorterApp) ToPorterAppType() *types.PorterApp {
  28. return &types.PorterApp{
  29. ID: a.ID,
  30. ProjectID: a.ProjectID,
  31. ClusterID: a.ClusterID,
  32. Name: a.Name,
  33. ImageRepoURI: a.ImageRepoURI,
  34. GitRepoID: a.GitRepoID,
  35. RepoName: a.RepoName,
  36. GitBranch: a.GitBranch,
  37. BuildContext: a.BuildContext,
  38. Builder: a.Builder,
  39. Buildpacks: a.Buildpacks,
  40. Dockerfile: a.Dockerfile,
  41. PullRequestURL: a.PullRequestURL,
  42. PorterYamlPath: a.PorterYamlPath,
  43. }
  44. }
  45. // ToPorterAppTypeWithRevision generates an external types.PorterApp with the latest helm revision number to be shared over REST
  46. // this is a bit hacky since it mixes db information with non-db information in the response
  47. // TODO: rethink this when we switch to versioned porter.yamls
  48. func (a *PorterApp) ToPorterAppTypeWithRevision(revision int) *types.PorterApp {
  49. return &types.PorterApp{
  50. ID: a.ID,
  51. ProjectID: a.ProjectID,
  52. ClusterID: a.ClusterID,
  53. Name: a.Name,
  54. ImageRepoURI: a.ImageRepoURI,
  55. GitRepoID: a.GitRepoID,
  56. RepoName: a.RepoName,
  57. GitBranch: a.GitBranch,
  58. BuildContext: a.BuildContext,
  59. Builder: a.Builder,
  60. Buildpacks: a.Buildpacks,
  61. Dockerfile: a.Dockerfile,
  62. PullRequestURL: a.PullRequestURL,
  63. PorterYamlPath: a.PorterYamlPath,
  64. HelmRevisionNumber: revision,
  65. }
  66. }