gitrepo.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. "github.com/porter-dev/porter/internal/models/integrations"
  5. "gorm.io/gorm"
  6. )
  7. // GitRepo is an integration that can connect to a remote git repo via an auth
  8. // mechanism (currently only oauth)
  9. type GitRepo struct {
  10. gorm.Model
  11. // The project that this integration belongs to
  12. ProjectID uint `json:"project_id"`
  13. // The username/organization that this repo integration is linked to
  14. RepoEntity string `json:"repo_entity"`
  15. // The various auth mechanisms available to the integration
  16. OAuthIntegrationID uint
  17. }
  18. // GitRepoExternal is a repository to be shared over REST
  19. type GitRepoExternal struct {
  20. ID uint `json:"id"`
  21. // The project that this integration belongs to
  22. ProjectID uint `json:"project_id"`
  23. // The username/organization that this repo integration is linked to
  24. RepoEntity string `json:"repo_entity"`
  25. // The integration service for this git repo
  26. Service integrations.IntegrationService `json:"service"`
  27. }
  28. // Externalize generates an external Repo to be shared over REST
  29. func (r *GitRepo) Externalize() *GitRepoExternal {
  30. return &GitRepoExternal{
  31. ID: r.Model.ID,
  32. ProjectID: r.ProjectID,
  33. RepoEntity: r.RepoEntity,
  34. Service: integrations.Github,
  35. }
  36. }
  37. // GitActionConfig is a configuration for release's CI integration via
  38. // Github Actions
  39. type GitActionConfig struct {
  40. gorm.Model
  41. // The ID of the release that this is linked to
  42. ReleaseID uint `json:"release_id"`
  43. // The git repo in ${owner}/${repo} form
  44. GitRepo string `json:"git_repo"`
  45. // The git branch to use
  46. GitBranch string `json:"git_branch"`
  47. // The complete image repository uri to pull from
  48. ImageRepoURI string `json:"image_repo_uri"`
  49. // The git installation ID
  50. GithubInstallationID uint `json:"git_installation_id"`
  51. // The git repo ID (legacy field)
  52. GitRepoID uint `json:"git_repo_id"`
  53. // The path to the dockerfile in the git repo
  54. DockerfilePath string `json:"dockerfile_path"`
  55. // The build context
  56. FolderPath string `json:"folder_path"`
  57. // Determines on how authentication is performed on this action
  58. IsInstallation bool `json:"is_installation"`
  59. Version string `json:"version" gorm:"default:v0.0.1"`
  60. }
  61. // GitActionConfigExternal is an external GitActionConfig to be shared over REST
  62. type GitActionConfigExternal struct {
  63. // The git repo in ${owner}/${repo} form
  64. GitRepo string `json:"git_repo"`
  65. // The git branch to use
  66. GitBranch string `json:"git_branch"`
  67. // The complete image repository uri to pull from
  68. ImageRepoURI string `json:"image_repo_uri"`
  69. // The git integration id
  70. GitRepoID uint `json:"git_repo_id"`
  71. // The path to the dockerfile in the git repo
  72. DockerfilePath string `json:"dockerfile_path" form:"required"`
  73. // The build context
  74. FolderPath string `json:"folder_path"`
  75. }
  76. // Externalize generates an external GitActionConfig to be shared over REST
  77. func (r *GitActionConfig) Externalize() *GitActionConfigExternal {
  78. return &GitActionConfigExternal{
  79. GitRepo: r.GitRepo,
  80. GitBranch: r.GitBranch,
  81. ImageRepoURI: r.ImageRepoURI,
  82. GitRepoID: r.GithubInstallationID,
  83. DockerfilePath: r.DockerfilePath,
  84. FolderPath: r.FolderPath,
  85. }
  86. }
  87. // ToGitActionConfigType generates an external GitActionConfig to be shared over REST
  88. func (r *GitActionConfig) ToGitActionConfigType() *types.GitActionConfig {
  89. return &types.GitActionConfig{
  90. GitRepo: r.GitRepo,
  91. GitBranch: r.GitBranch,
  92. ImageRepoURI: r.ImageRepoURI,
  93. GitRepoID: r.GithubInstallationID,
  94. DockerfilePath: r.DockerfilePath,
  95. FolderPath: r.FolderPath,
  96. }
  97. }