github_app.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package integrations
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. "gorm.io/gorm"
  5. )
  6. // GithubAppInstallation is an instance of the porter github app
  7. // we need to store account/installation id pairs in order to authenticate as the installation
  8. type GithubAppInstallation struct {
  9. gorm.Model
  10. // Can belong to either a user or an organization
  11. AccountID int64 `json:"account_id" gorm:"unique"`
  12. // Installation ID (used for authentication)
  13. InstallationID int64 `json:"installation_id"`
  14. }
  15. type GithubAppInstallationExternal struct {
  16. ID uint `json:"id"`
  17. // Can belong to either a user or an organization
  18. AccountID int64 `json:"account_id"`
  19. // Installation ID (used for authentication)
  20. InstallationID int64 `json:"installation_id"`
  21. }
  22. func (r *GithubAppInstallation) Externalize() *GithubAppInstallationExternal {
  23. return &GithubAppInstallationExternal{
  24. ID: r.ID,
  25. AccountID: r.AccountID,
  26. InstallationID: r.InstallationID,
  27. }
  28. }
  29. func (r *GithubAppInstallation) ToGitInstallationType() *types.GitInstallation {
  30. return &types.GitInstallation{
  31. ID: r.ID,
  32. AccountID: r.AccountID,
  33. InstallationID: r.InstallationID,
  34. }
  35. }