-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chmouel Boudjnah <[email protected]>
- Loading branch information
Showing
4 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package gosmee | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/go-github/v57/github" | ||
"golang.org/x/exp/slog" | ||
) | ||
|
||
type GHOp interface { | ||
ListHooks(ctx context.Context, org, repo string, opt *github.ListOptions) ([]*github.Hook, *github.Response, error) | ||
ListHookDeliveries(ctx context.Context, org, repo string, hookID int64, opt *github.ListCursorOptions) ([]*github.HookDelivery, *github.Response, error) | ||
GetHookDelivery(ctx context.Context, org, repo string, hookID, deliveryID int64) (*github.HookDelivery, *github.Response, error) | ||
Starting() | ||
} | ||
|
||
var _ GHOp = (*RepoOP)(nil) | ||
var _ GHOp = (*OrgOP)(nil) | ||
|
||
type RepoOP struct { | ||
client *github.Client | ||
logger *slog.Logger | ||
org, repo string | ||
} | ||
|
||
func NewRepoLister(client *github.Client, logger *slog.Logger, org, repo string) *RepoOP { | ||
return &RepoOP{client: client, logger: logger, org: repo, repo: repo} | ||
} | ||
|
||
func (r *RepoOP) Starting() { | ||
r.logger.Info("watching deliveries on", "org", r.org, "repo", r.repo) | ||
} | ||
|
||
func (r *RepoOP) ListHooks(ctx context.Context, org, repo string, opt *github.ListOptions) ([]*github.Hook, *github.Response, error) { | ||
return r.client.Repositories.ListHooks(ctx, org, repo, opt) | ||
} | ||
|
||
func (r *RepoOP) ListHookDeliveries(ctx context.Context, org, repo string, hookID int64, opt *github.ListCursorOptions) ([]*github.HookDelivery, *github.Response, error) { | ||
return r.client.Repositories.ListHookDeliveries(ctx, org, repo, hookID, opt) | ||
} | ||
|
||
func (r *RepoOP) GetHookDelivery(ctx context.Context, org, repo string, hookID, deliveryID int64) (*github.HookDelivery, *github.Response, error) { | ||
return r.client.Repositories.GetHookDelivery(ctx, org, repo, hookID, deliveryID) | ||
} | ||
|
||
var _ GHOp = (*RepoOP)(nil) | ||
|
||
type OrgOP struct { | ||
client *github.Client | ||
logger *slog.Logger | ||
org, repo string | ||
} | ||
|
||
func NewOrgLister(client *github.Client, logger *slog.Logger, org, repo string) *OrgOP { | ||
return &OrgOP{client: client, logger: logger, org: org, repo: repo} | ||
} | ||
|
||
func (r *OrgOP) ListHooks(ctx context.Context, org, _ string, opt *github.ListOptions) ([]*github.Hook, *github.Response, error) { | ||
return r.client.Organizations.ListHooks(ctx, org, opt) | ||
} | ||
|
||
func (r *OrgOP) ListHookDeliveries(ctx context.Context, org, _ string, hookID int64, opt *github.ListCursorOptions) ([]*github.HookDelivery, *github.Response, error) { | ||
return r.client.Organizations.ListHookDeliveries(ctx, org, hookID, opt) | ||
} | ||
|
||
func (r *OrgOP) GetHookDelivery(ctx context.Context, org, _ string, hookID, deliveryID int64) (*github.HookDelivery, *github.Response, error) { | ||
return r.client.Organizations.GetHookDelivery(ctx, org, hookID, deliveryID) | ||
} | ||
|
||
func (r *OrgOP) Starting() { | ||
r.logger.Info("watching deliveries on", "org", r.org) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters