2
0

gitrepo.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package models
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  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. // }
  25. // // Externalize generates an external Repo to be shared over REST
  26. // func (r *GitRepo) Externalize() *GitRepoExternal {
  27. // return &GitRepoExternal{
  28. // ID: r.Model.ID,
  29. // ProjectID: r.ProjectID,
  30. // RepoEntity: r.RepoEntity,
  31. // }
  32. // }
  33. // GitActionConfig is a configuration for release's CI integration via
  34. // Github Actions
  35. type GitActionConfig struct {
  36. gorm.Model
  37. // The ID of the release that this is linked to
  38. ReleaseID uint `json:"release_id"`
  39. // The git repo in ${owner}/${repo} form
  40. GitRepo string `json:"git_repo"`
  41. // The git branch to use
  42. GitBranch string `json:"git_branch"`
  43. // The complete image repository uri to pull from
  44. ImageRepoURI string `json:"image_repo_uri"`
  45. // The git installation ID
  46. GithubInstallationID uint `json:"git_installation_id"`
  47. // The git repo ID (legacy field)
  48. GitRepoID uint `json:"git_repo_id"`
  49. // The path to the dockerfile in the git repo
  50. DockerfilePath string `json:"dockerfile_path"`
  51. // The build context
  52. FolderPath string `json:"folder_path"`
  53. // Determines on how authentication is performed on this action
  54. IsInstallation bool `json:"is_installation"`
  55. Version string `json:"version" gorm:"default:v0.0.1"`
  56. }
  57. // GitActionConfigExternal is an external GitActionConfig to be shared over REST
  58. type GitActionConfigExternal struct {
  59. // The git repo in ${owner}/${repo} form
  60. GitRepo string `json:"git_repo"`
  61. // The git branch to use
  62. GitBranch string `json:"git_branch"`
  63. // The complete image repository uri to pull from
  64. ImageRepoURI string `json:"image_repo_uri"`
  65. // The git integration id
  66. GitRepoID uint `json:"git_repo_id"`
  67. // The path to the dockerfile in the git repo
  68. DockerfilePath string `json:"dockerfile_path" form:"required"`
  69. // The build context
  70. FolderPath string `json:"folder_path"`
  71. }
  72. // Externalize generates an external GitActionConfig to be shared over REST
  73. func (r *GitActionConfig) Externalize() *GitActionConfigExternal {
  74. return &GitActionConfigExternal{
  75. GitRepo: r.GitRepo,
  76. GitBranch: r.GitBranch,
  77. ImageRepoURI: r.ImageRepoURI,
  78. GitRepoID: r.GithubInstallationID,
  79. DockerfilePath: r.DockerfilePath,
  80. FolderPath: r.FolderPath,
  81. }
  82. }
  83. // ToGitActionConfigType generates an external GitActionConfig to be shared over REST
  84. func (r *GitActionConfig) ToGitActionConfigType() *types.GitActionConfig {
  85. return &types.GitActionConfig{
  86. GitRepo: r.GitRepo,
  87. GitBranch: r.GitBranch,
  88. ImageRepoURI: r.ImageRepoURI,
  89. GitRepoID: r.GithubInstallationID,
  90. DockerfilePath: r.DockerfilePath,
  91. FolderPath: r.FolderPath,
  92. }
  93. }