@@ -18,6 +18,7 @@ import (
1818
1919 "github.com/codeGROOVE-dev/fido"
2020 "github.com/codeGROOVE-dev/fido/pkg/store/localfs"
21+ "github.com/codeGROOVE-dev/prx/pkg/prx/types"
2122)
2223
2324const (
@@ -29,13 +30,13 @@ const (
2930
3031// PRStore is the interface for PR cache storage backends.
3132// This is an alias for fido.Store with the appropriate type parameters.
32- type PRStore = fido.Store [string , PullRequestData ]
33+ type PRStore = fido.Store [string , types. PullRequestData ]
3334
3435// Client provides methods to fetch pull request events from various platforms.
3536type Client struct {
36- platform Platform
37+ platform types. Platform
3738 logger * slog.Logger
38- prCache * fido.TieredCache [string , PullRequestData ]
39+ prCache * fido.TieredCache [string , types. PullRequestData ]
3940}
4041
4142// Option is a function that configures a Client.
@@ -67,13 +68,13 @@ func WithCacheStore(store PRStore) Option {
6768// For GitHub: NewClientWithPlatform(github.NewPlatform(token), opts...)
6869// For GitLab: NewClientWithPlatform(gitlab.NewPlatform(token), opts...)
6970// For Gitea: NewClientWithPlatform(gitea.NewPlatform(token), opts...)
70- func NewClient (platform Platform , opts ... Option ) * Client {
71+ func NewClient (platform types. Platform , opts ... Option ) * Client {
7172 return NewClientWithPlatform (platform , opts ... )
7273}
7374
7475// NewClientWithPlatform creates a new Client with the given platform.
7576// Use this to create clients for GitLab, Codeberg, or other platforms.
76- func NewClientWithPlatform (platform Platform , opts ... Option ) * Client {
77+ func NewClientWithPlatform (platform types. Platform , opts ... Option ) * Client {
7778 c := & Client {
7879 platform : platform ,
7980 logger : slog .Default (),
@@ -90,7 +91,7 @@ func NewClientWithPlatform(platform Platform, opts ...Option) *Client {
9091 return c
9192}
9293
93- func createDefaultCache (log * slog.Logger ) * fido.TieredCache [string , PullRequestData ] {
94+ func createDefaultCache (log * slog.Logger ) * fido.TieredCache [string , types. PullRequestData ] {
9495 dir , err := os .UserCacheDir ()
9596 if err != nil {
9697 dir = os .TempDir ()
@@ -100,7 +101,7 @@ func createDefaultCache(log *slog.Logger) *fido.TieredCache[string, PullRequestD
100101 log .Warn ("failed to create cache directory, caching disabled" , "error" , err )
101102 return nil
102103 }
103- store , err := localfs .New [string , PullRequestData ]("prx-pr" , dir )
104+ store , err := localfs .New [string , types. PullRequestData ]("prx-pr" , dir )
104105 if err != nil {
105106 log .Warn ("failed to create cache store, caching disabled" , "error" , err )
106107 return nil
@@ -114,7 +115,7 @@ func createDefaultCache(log *slog.Logger) *fido.TieredCache[string, PullRequestD
114115}
115116
116117// PullRequest fetches a pull request with all its events and metadata.
117- func (c * Client ) PullRequest (ctx context.Context , owner , repo string , prNumber int ) (* PullRequestData , error ) {
118+ func (c * Client ) PullRequest (ctx context.Context , owner , repo string , prNumber int ) (* types. PullRequestData , error ) {
118119 return c .PullRequestWithReferenceTime (ctx , owner , repo , prNumber , time .Now ())
119120}
120121
@@ -124,7 +125,7 @@ func (c *Client) PullRequestWithReferenceTime(
124125 owner , repo string ,
125126 pr int ,
126127 refTime time.Time ,
127- ) (* PullRequestData , error ) {
128+ ) (* types. PullRequestData , error ) {
128129 if c .prCache == nil {
129130 return c .platform .FetchPR (ctx , owner , repo , pr , refTime )
130131 }
@@ -150,10 +151,10 @@ func (c *Client) PullRequestWithReferenceTime(
150151 "platform" , c .platform .Name (), "owner" , owner , "repo" , repo , "pr" , pr )
151152 }
152153
153- result , err := c .prCache .Fetch (ctx , key , func (ctx context.Context ) (PullRequestData , error ) {
154+ result , err := c .prCache .Fetch (ctx , key , func (ctx context.Context ) (types. PullRequestData , error ) {
154155 data , err := c .platform .FetchPR (ctx , owner , repo , pr , refTime )
155156 if err != nil {
156- return PullRequestData {}, err
157+ return types. PullRequestData {}, err
157158 }
158159 data .CachedAt = time .Now ()
159160 return * data , nil
@@ -182,7 +183,7 @@ func NewCacheStore(dir string) (PRStore, error) {
182183 if err := os .MkdirAll (dir , 0o700 ); err != nil {
183184 return nil , fmt .Errorf ("creating cache directory: %w" , err )
184185 }
185- store , err := localfs .New [string , PullRequestData ]("prx-pr" , dir )
186+ store , err := localfs .New [string , types. PullRequestData ]("prx-pr" , dir )
186187 if err != nil {
187188 return nil , fmt .Errorf ("creating PR cache store: %w" , err )
188189 }
@@ -205,3 +206,15 @@ func collaboratorsCacheKey(owner, repo string) string {
205206func rulesetsCacheKey (owner , repo string ) string {
206207 return fmt .Sprintf ("%s/%s" , owner , repo )
207208}
209+
210+ // isHexString returns true if the string contains only hex characters.
211+ func isHexString (s string ) bool {
212+ for i := range s {
213+ c := s [i ]
214+ if (c >= '0' && c <= '9' ) || (c >= 'a' && c <= 'f' ) || (c >= 'A' && c <= 'F' ) {
215+ continue
216+ }
217+ return false
218+ }
219+ return true
220+ }
0 commit comments