@@ -10,10 +10,60 @@ import (
1010 "go.uber.org/zap"
1111)
1212
13- type RepoInteractor service
13+ type (
14+ // RepoInteractor provides application logic for interacting with repos.
15+ RepoInteractor struct {
16+ * service
1417
15- func (i * RepoInteractor ) ActivateRepo (ctx context.Context , u * ent.User , r * ent.Repo , c * extent.WebhookConfig ) (* ent.Repo , error ) {
16- hid , err := i .scm .CreateWebhook (ctx , u , r , c )
18+ WebhookURL string
19+ WebhookSSL bool
20+ WebhookSecret string
21+ }
22+
23+ // RepoStore defines operations for working with repos.
24+ RepoStore interface {
25+ CountActiveRepos (ctx context.Context ) (int , error )
26+ CountRepos (ctx context.Context ) (int , error )
27+ ListReposOfUser (ctx context.Context , u * ent.User , opt * ListReposOfUserOptions ) ([]* ent.Repo , error )
28+ FindRepoOfUserByID (ctx context.Context , u * ent.User , id int64 ) (* ent.Repo , error )
29+ FindRepoOfUserByNamespaceName (ctx context.Context , u * ent.User , opt * FindRepoOfUserByNamespaceNameOptions ) (* ent.Repo , error )
30+ FindRepoByID (ctx context.Context , id int64 ) (* ent.Repo , error )
31+ SyncRepo (ctx context.Context , r * extent.RemoteRepo ) (* ent.Repo , error )
32+ UpdateRepo (ctx context.Context , r * ent.Repo ) (* ent.Repo , error )
33+ Activate (ctx context.Context , r * ent.Repo ) (* ent.Repo , error )
34+ Deactivate (ctx context.Context , r * ent.Repo ) (* ent.Repo , error )
35+ }
36+
37+ // ListReposOfUser specifies the optional parameters that
38+ // search repos.
39+ ListReposOfUserOptions struct {
40+ ListOptions
41+
42+ // Query search the repos contains the query in the namespace or name.
43+ Query string
44+ // Sorted instructs the system to sort by the 'deployed_at' field.
45+ Sorted bool
46+ }
47+
48+ // FindRepoOfUserByNamespaceName specifies the parameters to get the repository.
49+ FindRepoOfUserByNamespaceNameOptions struct {
50+ Namespace , Name string
51+ }
52+
53+ // RepoSCM defines operations for working with remote repos.
54+ RepoSCM interface {
55+ ListRemoteRepos (ctx context.Context , u * ent.User ) ([]* extent.RemoteRepo , error )
56+ }
57+ )
58+
59+ // ActivateRepo create a new hook to listen events, and saves
60+ // the hook ID.
61+ func (i * RepoInteractor ) ActivateRepo (ctx context.Context , u * ent.User , r * ent.Repo ) (* ent.Repo , error ) {
62+ hid , err := i .scm .CreateWebhook (ctx , u , r , & extent.WebhookConfig {
63+ URL : i .WebhookURL ,
64+ InsecureSSL : i .WebhookSSL ,
65+ Secret : i .WebhookSecret ,
66+ })
1767 if err != nil {
1868 return nil , fmt .Errorf ("failed to create a webhook: %s" , err )
1969 }
@@ -29,6 +79,7 @@ func (i *RepoInteractor) ActivateRepo(ctx context.Context, u *ent.User, r *ent.R
2979 return r , nil
3080}
3181
82+ // DeactivateRepo removes the webhook.
3283func (i * RepoInteractor ) DeactivateRepo (ctx context.Context , u * ent.User , r * ent.Repo ) (* ent.Repo , error ) {
3384 err := i .scm .DeleteWebhook (ctx , u , r , r .WebhookID )
3485 if e .HasErrorCode (err , e .ErrorCodeEntityNotFound ) {
0 commit comments