gitrepo.go 3.1 KB

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