porter_app.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. BuildContext string
  18. Builder string
  19. Buildpacks string
  20. Dockerfile string
  21. PullRequestURL string
  22. // Porter YAML
  23. PorterYamlPath string
  24. }
  25. // ToPorterAppType generates an external types.PorterApp to be shared over REST
  26. func (a *PorterApp) ToPorterAppType() *types.PorterApp {
  27. return &types.PorterApp{
  28. ID: a.ID,
  29. ProjectID: a.ProjectID,
  30. ClusterID: a.ClusterID,
  31. Name: a.Name,
  32. ImageRepoURI: a.ImageRepoURI,
  33. GitRepoID: a.GitRepoID,
  34. RepoName: a.RepoName,
  35. GitBranch: a.GitBranch,
  36. BuildContext: a.BuildContext,
  37. Builder: a.Builder,
  38. Buildpacks: a.Buildpacks,
  39. Dockerfile: a.Dockerfile,
  40. PullRequestURL: a.PullRequestURL,
  41. PorterYamlPath: a.PorterYamlPath,
  42. }
  43. }
  44. // ToPorterAppTypeWithRevision generates an external types.PorterApp with the latest helm revision number to be shared over REST
  45. // this is a bit hacky since it mixes db information with non-db information in the response
  46. // TODO: rethink this when we switch to versioned porter.yamls
  47. func (a *PorterApp) ToPorterAppTypeWithRevision(revision int) *types.PorterApp {
  48. return &types.PorterApp{
  49. ID: a.ID,
  50. ProjectID: a.ProjectID,
  51. ClusterID: a.ClusterID,
  52. Name: a.Name,
  53. ImageRepoURI: a.ImageRepoURI,
  54. GitRepoID: a.GitRepoID,
  55. RepoName: a.RepoName,
  56. GitBranch: a.GitBranch,
  57. BuildContext: a.BuildContext,
  58. Builder: a.Builder,
  59. Buildpacks: a.Buildpacks,
  60. Dockerfile: a.Dockerfile,
  61. PullRequestURL: a.PullRequestURL,
  62. PorterYamlPath: a.PorterYamlPath,
  63. HelmRevisionNumber: revision,
  64. }
  65. }