Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"fmt"

// "io/ioutil"
"net/http"
"os"
Expand All @@ -20,6 +21,7 @@ import (
oauthGithub "golang.org/x/oauth2/github"

"github.com/kloudlite/api/pkg/errors"
"github.com/kloudlite/api/pkg/logging"
// fn "kloudlite.io/pkg/functions"
"github.com/kloudlite/api/pkg/types"
)
Expand All @@ -30,6 +32,7 @@ type githubOptions interface {
}

type githubI struct {
logger logging.Logger
cfg *oauth2.Config
ghCli *github.Client
ghCliForUser func(ctx context.Context, token *oauth2.Token) *github.Client
Expand Down Expand Up @@ -111,7 +114,6 @@ func (gh *githubI) Callback(ctx context.Context, code string, state string) (*gi
return nil, nil, errors.NewEf(err, "could nog get authenticated user from github")
}
return u, token, nil

}

// CheckWebhookExists implements domain.Github.
Expand All @@ -135,9 +137,7 @@ func (gh *githubI) CheckWebhookExists(ctx context.Context, token *entities.Acces

// DeleteWebhook implements domain.Github.
func (gh *githubI) DeleteWebhook(ctx context.Context, accToken *entities.AccessToken, repoUrl string, hookId entities.GithubWebhookId) error {

owner, repo, err := gh.getOwnerAndRepo(repoUrl)

if err != nil {
return errors.NewE(err)
}
Expand All @@ -147,13 +147,11 @@ func (gh *githubI) DeleteWebhook(ctx context.Context, accToken *entities.AccessT
return nil
}
return errors.NewE(err)

}

// GetInstallationToken implements domain.Github.
func (gh *githubI) GetInstallationToken(ctx context.Context, repoUrl string) (string, error) {
owner, repo, err := gh.getOwnerAndRepo(repoUrl)

if err != nil {
return "", errors.NewE(err)
}
Expand All @@ -168,7 +166,6 @@ func (gh *githubI) GetInstallationToken(ctx context.Context, repoUrl string) (st
return "", errors.NewEf(err, "failed to get installation token")
}
return it.GetToken(), errors.NewE(err)

}

// GetLatestCommit implements domain.Github.
Expand Down Expand Up @@ -246,30 +243,27 @@ func (gh *githubI) ListRepos(ctx context.Context, accToken *entities.AccessToken
return nil, errors.NewEf(err, "could not list user repositories")
}
return repos, nil

}

// SearchRepos implements domain.Github.
func (gh *githubI) SearchRepos(ctx context.Context, accToken *entities.AccessToken, q string, org string, pagination *types.Pagination) (*github.RepositoriesSearchResult, error) {
// TODO: search repos not working at all from the API
searchQ := fmt.Sprintf("%s org:%s", q, org)
searchQ := fmt.Sprintf("%s org:%s fork:true", q, org)
rsr, resp, err := gh.ghCliForUser(ctx, accToken.Token).Search.Repositories(
context.TODO(), searchQ, &github.SearchOptions{
ListOptions: gh.buildListOptions(pagination),
},
)
fmt.Println(resp)
if err != nil {
return nil, errors.NewEf(err, "could not search repositories")
}
gh.logger.Warnf("github rate {limit: %d, remaining: %d}", resp.Rate.Limit, resp.Rate.Remaining)
return rsr, nil
}

func fxGithub[T githubOptions]() fx.Option {

return fx.Module("github-fx",
fx.Provide(
func(env T) (domain.Github, error) {
func(env T, logger logging.Logger) (domain.Github, error) {
clientId, clientSecret, callbackUrl, ghAppId, ghAppPKFile := env.GithubConfig()
cfg := oauth2.Config{
ClientID: clientId,
Expand Down Expand Up @@ -304,6 +298,7 @@ func fxGithub[T githubOptions]() fx.Option {
ghCli := github.NewClient(&http.Client{Transport: itr, Timeout: 30 * time.Second})

return &githubI{
logger: logger,
cfg: &cfg,
ghCli: ghCli,
ghCliForUser: ghCliForUser,
Expand Down
6 changes: 3 additions & 3 deletions apps/container-registry/internal/app/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type CRCheckNameAvailabilityOutput @shareable {
}

type Query {
cr_listRepos(search:SearchRepos, pagination:CursorPaginationIn) : RepositoryPaginatedRecords @isLoggedInAndVerified @hasAccount
cr_listRepos(search: SearchRepos, pagination: CursorPaginationIn): RepositoryPaginatedRecords @isLoggedInAndVerified @hasAccount
cr_listCreds(search:SearchCreds, pagination:CursorPaginationIn) : CredentialPaginatedRecords @isLoggedInAndVerified @hasAccount
cr_listDigests(repoName:String!, search: SearchRepos, pagination:CursorPaginationIn) : DigestPaginatedRecords @isLoggedInAndVerified @hasAccount

Expand All @@ -39,8 +39,8 @@ type Query {
cr_listBuilds(repoName:String!, search:SearchBuilds, pagination:CursorPaginationIn) : BuildPaginatedRecords @isLoggedInAndVerified @hasAccount

cr_listGithubInstallations(pagination:PaginationIn) : [GithubInstallation!] @isLoggedInAndVerified
cr_listGithubRepos(installationId:Int!, pagination:PaginationIn) : GithubListRepository @isLoggedInAndVerified
cr_searchGithubRepos(organization:String!, search:String!, pagination:PaginationIn) : GithubSearchRepository @isLoggedInAndVerified
cr_listGithubRepos(installationId:Int!, pagination:PaginationIn): GithubListRepository @isLoggedInAndVerified
cr_searchGithubRepos(organization:String!, search:String!, pagination:PaginationIn): GithubSearchRepository @isLoggedInAndVerified
cr_listGithubBranches(repoUrl:String!, pagination:PaginationIn) : [GitBranch!] @isLoggedInAndVerified

cr_listGitlabGroups(query:String, pagination:PaginationIn) : [GitlabGroup!] @isLoggedInAndVerified
Expand Down