Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/bin
/dist
# .vscode
cmd/gitfusion-api/*_debug_*

# Test binary, built with `go test -c`
*.test
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ require (
github.com/go-chi/chi/v5 v5.2.1
github.com/go-chi/httplog/v2 v2.1.1
github.com/google/go-github/v72 v72.0.0
github.com/ktrysmt/go-bitbucket v0.9.85
github.com/oapi-codegen/runtime v1.1.1
github.com/stretchr/testify v1.10.0
gitlab.com/gitlab-org/api/client-go v0.128.0
k8s.io/api v0.32.1
k8s.io/apimachinery v0.32.1
Expand Down Expand Up @@ -42,13 +44,13 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/ktrysmt/go-bitbucket v0.9.85 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down
18 changes: 12 additions & 6 deletions internal/api/bitbucket_respositories_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

gferrors "github.com/KubeRocketCI/gitfusion/internal/errors"
"github.com/KubeRocketCI/gitfusion/internal/models"
"github.com/KubeRocketCI/gitfusion/internal/services"
)

Expand Down Expand Up @@ -38,11 +37,11 @@ func (r *BitbucketRepositoryHandler) ListBitbucketRepositories(
ctx context.Context,
request ListBitbucketRepositoriesRequestObject,
) (ListBitbucketRepositoriesResponseObject, error) {
repositories, err := r.repositoriesService.ListOrganizationsRepositories(
repositories, err := r.repositoriesService.ListRepositories(
ctx,
request.GitServer,
request.Org,
getListOptions(request.Params.Page, request.Params.PerPage),
request.Owner,
r.getListOptions(request),
)
if err != nil {
return ListBitbucketRepositories400JSONResponse{
Expand All @@ -52,11 +51,18 @@ func (r *BitbucketRepositoryHandler) ListBitbucketRepositories(
}

return ListBitbucketRepositories200JSONResponse{
Repositories: repositories,
Pagination: models.Pagination{}, // TODO: implement pagination after all rit providers are implemented
Data: repositories,
}, nil
}

func (r *BitbucketRepositoryHandler) getListOptions(
request ListBitbucketRepositoriesRequestObject,
) services.ListOptions {
return services.ListOptions{
Name: request.Params.RepoName,
}
}

func (r *BitbucketRepositoryHandler) errResponse(err error) GetBitbucketRepositoryResponseObject {
if err == nil {
return GetBitbucketRepository200JSONResponse{}
Expand Down
26 changes: 9 additions & 17 deletions internal/api/github_repositories_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

gferrors "github.com/KubeRocketCI/gitfusion/internal/errors"
"github.com/KubeRocketCI/gitfusion/internal/models"
"github.com/KubeRocketCI/gitfusion/internal/services"
)

Expand Down Expand Up @@ -39,11 +38,11 @@ func (r *GitHubRepositoryHandler) ListGitHubRepositories(
ctx context.Context,
request ListGitHubRepositoriesRequestObject,
) (ListGitHubRepositoriesResponseObject, error) {
repositories, err := r.repositoriesService.ListOrganizationsRepositories(
repositories, err := r.repositoriesService.ListRepositories(
ctx,
request.GitServer,
request.Org,
getListOptions(request.Params.Page, request.Params.PerPage),
request.Owner,
r.getListOptions(request),
)
if err != nil {
return ListGitHubRepositories400JSONResponse{
Expand All @@ -53,8 +52,7 @@ func (r *GitHubRepositoryHandler) ListGitHubRepositories(
}

return ListGitHubRepositories200JSONResponse{
Repositories: repositories,
Pagination: models.Pagination{}, // TODO: implement pagination after all rit providers are implemented
Data: repositories,
}, nil
}

Expand All @@ -76,16 +74,10 @@ func (r *GitHubRepositoryHandler) errResponse(err error) GetGitHubRepositoryResp
}
}

func getListOptions(page, perPage *int) services.ListOptions {
listOptions := services.ListOptions{}

if page != nil {
listOptions.Page = page
}

if perPage != nil {
listOptions.PerPage = perPage
func (r *GitHubRepositoryHandler) getListOptions(
request ListGitHubRepositoriesRequestObject,
) services.ListOptions {
return services.ListOptions{
Name: request.Params.RepoName,
}

return listOptions
}
16 changes: 10 additions & 6 deletions internal/api/gitlab_repositories_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

gferrors "github.com/KubeRocketCI/gitfusion/internal/errors"
"github.com/KubeRocketCI/gitfusion/internal/models"
"github.com/KubeRocketCI/gitfusion/internal/services"
)

Expand Down Expand Up @@ -39,11 +38,11 @@ func (r *GitlabRepositoryHandler) ListGitlabRepositories(
ctx context.Context,
request ListGitlabRepositoriesRequestObject,
) (ListGitlabRepositoriesResponseObject, error) {
repositories, err := r.repositoriesService.ListOrganizationsRepositories(
repositories, err := r.repositoriesService.ListRepositories(
ctx,
request.GitServer,
request.Org,
getListOptions(request.Params.Page, request.Params.PerPage),
request.Owner,
r.getListOptions(request),
)
if err != nil {
return ListGitlabRepositories400JSONResponse{
Expand All @@ -53,11 +52,16 @@ func (r *GitlabRepositoryHandler) ListGitlabRepositories(
}

return ListGitlabRepositories200JSONResponse{
Repositories: repositories,
Pagination: models.Pagination{}, // TODO: implement pagination after all rit providers are implemented
Data: repositories,
}, nil
}

func (r *GitlabRepositoryHandler) getListOptions(request ListGitlabRepositoriesRequestObject) services.ListOptions {
return services.ListOptions{
Name: request.Params.RepoName,
}
}

func (r *GitlabRepositoryHandler) gitlabErrResponse(err error) GetGitlabRepositoryResponseObject {
if err == nil {
return GetGitlabRepository200JSONResponse{}
Expand Down
74 changes: 27 additions & 47 deletions internal/api/oapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ info:
version: 1.0.0
title: GitFusion API server
paths:
/api/v1/providers/github/{git-server}/{org}/repositories:
/api/v1/providers/github/{gitServer}/{owner}/repositories:
get:
summary: List organization repositories
operationId: listGitHubRepositories
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/orgParam'
- $ref: '#/components/parameters/pageParam'
- $ref: '#/components/parameters/perPageParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameQueryParam'
responses:
'200':
description: A list of repositories
Expand All @@ -40,16 +39,16 @@ paths:
schema:
$ref: '#/components/schemas/Error'

/api/v1/providers/github/{git-server}/repositories/{owner}/{repo}:
/api/v1/providers/github/{gitServer}/repositories/{owner}/{repo}:
get:
summary: Get detailed information for a specific GitHub repository
operationId: getGitHubRepository
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/ownerParam'
- $ref: '#/components/parameters/repoParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameParam'
responses:
'200':
description: Detailed information about a repository
Expand All @@ -69,17 +68,16 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/v1/providers/gitlab/{git-server}/{org}/repositories:
/api/v1/providers/gitlab/{gitServer}/{owner}/repositories:
get:
summary: List repositories
operationId: listGitlabRepositories
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/orgParam'
- $ref: '#/components/parameters/pageParam'
- $ref: '#/components/parameters/perPageParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameQueryParam'
responses:
'200':
description: A list of repositories
Expand All @@ -94,16 +92,16 @@ paths:
schema:
$ref: '#/components/schemas/Error'

/api/v1/providers/gitlab/{git-server}/repositories/{owner}/{repo}:
/api/v1/providers/gitlab/{gitServer}/repositories/{owner}/{repo}:
get:
summary: Get detailed information for a specific Gitlab repository
operationId: getGitlabRepository
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/ownerParam'
- $ref: '#/components/parameters/repoParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameParam'
responses:
'200':
description: Detailed information about a repository
Expand All @@ -123,17 +121,16 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/api/v1/providers/bitbucket/{git-server}/{org}/repositories:
/api/v1/providers/bitbucket/{gitServer}/{owner}/repositories:
get:
summary: List repositories
operationId: listBitbucketRepositories
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/orgParam'
- $ref: '#/components/parameters/pageParam'
- $ref: '#/components/parameters/perPageParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameQueryParam'
responses:
'200':
description: A list of repositories
Expand All @@ -160,16 +157,16 @@ paths:
schema:
$ref: '#/components/schemas/Error'

/api/v1/providers/bitbucket/{git-server}/repositories/{owner}/{repo}:
/api/v1/providers/bitbucket/{gitServer}/repositories/{owner}/{repo}:
get:
summary: Get detailed information for a specific Bitbucket repository
operationId: getBitbucketRepository
tags:
- Repositories
parameters:
- $ref: '#/components/parameters/gitServerParam'
- $ref: '#/components/parameters/ownerParam'
- $ref: '#/components/parameters/repoParam'
- $ref: '#/components/parameters/repoOwnerParam'
- $ref: '#/components/parameters/repoNameParam'
responses:
'200':
description: Detailed information about a repository
Expand All @@ -192,42 +189,28 @@ paths:

components:
parameters:
pageParam:
name: page
repoNameQueryParam:
name: repoName
in: query
required: false
description: The page number for pagination.
description: The name of the repository to search for.
schema:
type: integer
perPageParam:
name: per_page
in: query
required: false
description: The number of items per page for pagination.
schema:
type: integer
type: string
gitServerParam:
name: git-server
name: gitServer
in: path
required: true
description: The Git server name.
schema:
type: string
orgParam:
name: org
in: path
required: true
description: The organization name in the Git server.
schema:
type: string
ownerParam:
repoOwnerParam:
name: owner
in: path
required: true
description: The owner of the repository.
schema:
type: string
repoParam:
repoNameParam:
name: repo
in: path
required: true
Expand Down Expand Up @@ -319,15 +302,12 @@ components:
RepositoriesResponse:
type: object
properties:
repositories:
data:
type: array
items:
$ref: '#/components/schemas/Repository'
pagination:
$ref: '#/components/schemas/Pagination'
required:
- repositories
- pagination
- data
Error:
type: object
properties:
Expand Down
Loading