Compare commits

..

No commits in common. "e4f9743dea35a369db2614609adec3d5b2c4e75e" and "37007956ab0f5846af26b17843658f87d091b79c" have entirely different histories.

27 changed files with 55 additions and 148 deletions

View file

@ -10,7 +10,7 @@ linters-settings:
exclude-functions: exclude-functions:
- github.com/go-chi/render.Render - github.com/go-chi/render.Render
goimports: goimports:
local-prefixes: "code.aides.space/aides-infra/aides-repo-api" local-prefixes: "code.alt-gnome.ru/aides-infra/aides-repo-api"
gofmt: gofmt:
simplify: true simplify: true
gofumpt: gofumpt:

View file

@ -22,13 +22,13 @@ swag:
build: build:
go build \ go build \
-ldflags="-X 'code.aides.space/aides-infra/aides-repo-api/internal/config.Version=$(APP_VERSION)'" \ -ldflags="-X 'code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config.Version=$(APP_VERSION)'" \
-o aides-repo-api \ -o aides-repo-api \
./cmd/aides-repo-api/main.go ./cmd/aides-repo-api/main.go
release: release:
go build \ go build \
-ldflags="-s -w -X 'code.aides.space/aides-infra/aides-repo-api/internal/config.Version=$(APP_VERSION)'" \ -ldflags="-s -w -X 'code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config.Version=$(APP_VERSION)'" \
-o aides-repo-api \ -o aides-repo-api \
./cmd/aides-repo-api/main.go ./cmd/aides-repo-api/main.go

View file

@ -1,3 +1,3 @@
# Aides repo API # Aides repo API
[![Go Report Card](https://goreportcard.com/badge/code.aides.space/aides-infra/aides-repo-api)](https://goreportcard.com/report/code.aides.space/aides-infra/aides-repo-api) ![Coverage](./coverage-badge.svg) [![Go Report Card](https://goreportcard.com/badge/code.alt-gnome.ru/aides-infra/aides-repo-api)](https://goreportcard.com/report/code.alt-gnome.ru/aides-infra/aides-repo-api) ![Coverage](./coverage-badge.svg)

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"code.aides.space/aides-infra/aides-repo-api/internal/app" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/app"
) )
// _ // _

View file

@ -2,5 +2,5 @@
<rect width="1100" height="20" fill="#555"/> <rect width="1100" height="20" fill="#555"/>
<rect x="60" width="50" height="20" fill="#4c1"/> <rect x="60" width="50" height="20" fill="#4c1"/>
<text x="5" y="14" fill="#fff" font-family="Verdana" font-size="11">coverage</text> <text x="5" y="14" fill="#fff" font-family="Verdana" font-size="11">coverage</text>
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">58.4%</text> <text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">58.5%</text>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

2
go.mod
View file

@ -1,4 +1,4 @@
module code.aides.space/aides-infra/aides-repo-api module code.alt-gnome.ru/aides-infra/aides-repo-api
go 1.23.3 go 1.23.3

View file

@ -9,14 +9,14 @@ import (
gormlogger "gorm.io/gorm/logger" gormlogger "gorm.io/gorm/logger"
"moul.io/zapgorm2" "moul.io/zapgorm2"
"code.aides.space/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.aides.space/aides-infra/aides-repo-api/internal/controllers/taskcontroller" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/router" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/router"
"code.aides.space/aides-infra/aides-repo-api/internal/services/cronservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/cronservice"
"code.aides.space/aides-infra/aides-repo-api/internal/services/reposervice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/reposervice"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
type App struct { type App struct {
@ -121,7 +121,7 @@ func (app *App) Run() {
}, },
) )
err := app.repo.Update(true) err := app.repo.Update(false)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -1,8 +1,8 @@
package taskcontroller package taskcontroller
import ( import (
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
type TaskService interface { type TaskService interface {

View file

@ -3,8 +3,8 @@ package taskcontroller_test
import ( import (
"errors" "errors"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
type TaskServiceMock struct { type TaskServiceMock struct {

View file

@ -6,8 +6,8 @@ import (
"github.com/go-chi/render" "github.com/go-chi/render"
"code.aides.space/aides-infra/aides-repo-api/internal/common/errors" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
type CreateTaskDTO struct { type CreateTaskDTO struct {

View file

@ -10,8 +10,8 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"code.aides.space/aides-infra/aides-repo-api/internal/controllers/taskcontroller" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {

View file

@ -7,10 +7,10 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/render" "github.com/go-chi/render"
commonErrors "code.aides.space/aides-infra/aides-repo-api/internal/common/errors" commonErrors "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
type TaskUploadResponse struct { type TaskUploadResponse struct {

View file

@ -10,8 +10,8 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"code.aides.space/aides-infra/aides-repo-api/internal/controllers/taskcontroller" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
func TestUpload(t *testing.T) { func TestUpload(t *testing.T) {

View file

@ -5,8 +5,8 @@ import (
"github.com/go-chi/render" "github.com/go-chi/render"
"code.aides.space/aides-infra/aides-repo-api/internal/common/errors" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
"code.aides.space/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
) )
func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler { func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler {

View file

@ -3,7 +3,7 @@ package middlewares
import ( import (
"net/http" "net/http"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
) )
// CustomResponseWriter wraps http.ResponseWriter to capture status code and response size // CustomResponseWriter wraps http.ResponseWriter to capture status code and response size

View file

@ -4,11 +4,11 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger" httpSwagger "github.com/swaggo/http-swagger"
docs "code.aides.space/aides-infra/aides-repo-api/docs" docs "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
"code.aides.space/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.aides.space/aides-infra/aides-repo-api/internal/controllers/taskcontroller" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
"code.aides.space/aides-infra/aides-repo-api/internal/middlewares" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
) )
type Router struct { type Router struct {

View file

@ -3,7 +3,7 @@ package cronservice
import ( import (
"github.com/go-co-op/gocron/v2" "github.com/go-co-op/gocron/v2"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
) )
type RepoService interface { type RepoService interface {

View file

@ -7,8 +7,8 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
type Config interface { type Config interface {
@ -106,7 +106,7 @@ func (s *Service) Update(force bool) error {
Model(&models.GitRepoAltRepoTask{}). Model(&models.GitRepoAltRepoTask{}).
Select("1"). Select("1").
Where("alt_repo_id = ?", altRepo.ID). Where("alt_repo_id = ?", altRepo.ID).
Where("last_task_id != current_task_id OR current_task_id IS NULL"). Where("last_task_id != current_task_id").
Limit(1). Limit(1).
Scan(&exists).Error; err != nil { Scan(&exists).Error; err != nil {
return err return err

View file

@ -6,7 +6,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
) )
func createRepoDirs(repoDir, repoName, arch string) error { func createRepoDirs(repoDir, repoName, arch string) error {

View file

@ -1,7 +1,7 @@
package taskservice package taskservice
import ( import (
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
func (s *Service) Create(repo string) (*models.Task, error) { func (s *Service) Create(repo string) (*models.Task, error) {

View file

@ -7,7 +7,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
type Config interface { type Config interface {

View file

@ -13,8 +13,8 @@ import (
"github.com/cavaliergopher/rpm" "github.com/cavaliergopher/rpm"
"gorm.io/gorm" "gorm.io/gorm"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
type TaskUploadInput struct { type TaskUploadInput struct {

View file

@ -1,6 +1,6 @@
package taskservice package taskservice
import "code.aides.space/aides-infra/aides-repo-api/internal/models" import "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
type WrapperRpmVersion struct { type WrapperRpmVersion struct {
file *models.RPMFile file *models.RPMFile

View file

@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/services/reposervice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/reposervice"
) )
func TestRepoService_ForceUpdate(t *testing.T) { func TestRepoService_ForceUpdate(t *testing.T) {
@ -118,99 +118,6 @@ func TestRepoService_ForceUpdate(t *testing.T) {
assert.Equal(t, path.Join("../../../../tasks/1", fileName), linkDest) assert.Equal(t, path.Join("../../../../tasks/1", fileName), linkDest)
}) })
t.Run("Correct update (update)", func(t *testing.T) {
// PREPARE
db := prepareDb(t)
config := prepareConfig()
os.MkdirAll(config.GetUploadDir(), os.ModePerm)
taskPath := path.Join(config.GetUploadDir(), "tasks/1")
os.MkdirAll(taskPath, os.ModePerm)
defer os.RemoveAll(config.GetUploadDir())
fileName := "example-foo-1.0.0-alt1.x86_64.rpm"
source, err := os.Open(path.Join("./test_rpms", fileName))
assert.NoError(t, err)
destination, err := os.Create(path.Join(taskPath, fileName))
assert.NoError(t, err)
defer destination.Close()
_, err = io.Copy(destination, source)
assert.NoError(t, err)
source.Close()
destination.Close()
gitRepo := &models.GitRepo{
Name: "example-foo",
}
altRepo := &models.ALTRepo{
Name: "Sisyphus",
}
db.Create(&models.GitRepoAltRepoTask{
Repo: gitRepo,
ALTRepo: altRepo,
CurrentTask: nil,
LastTask: &models.Task{
Status: models.StatusCompleted,
Files: []models.RPMFile{
{
Filename: fileName,
Name: "example-foo",
Version: "1.0.0",
Release: "1",
Arch: "x86_64",
Epoch: 0,
},
},
},
})
service := reposervice.New(
db,
config,
)
// EXECUTE
err = service.Update(false)
// CHECK
assert.NoError(t, err)
// TODO: check db
repoBasePath := path.Join(config.GetUploadDir(), "repo", "Sisyphus")
x86_64BasePath := path.Join(repoBasePath, "x86_64", "base")
x86_64RPMSPath := path.Join(repoBasePath, "x86_64", "RPMS.aides")
noarchBasePath := path.Join(repoBasePath, "noarch", "base")
expectedFiles := []string{
path.Join(x86_64BasePath, "pkglist.aides"),
path.Join(x86_64BasePath, "pkglist.aides.bz2"),
path.Join(x86_64BasePath, "pkglist.aides.xz"),
path.Join(x86_64BasePath, "release"),
path.Join(x86_64BasePath, "release.aides"),
path.Join(x86_64RPMSPath, fileName),
path.Join(noarchBasePath, "pkglist.aides"),
path.Join(noarchBasePath, "pkglist.aides.bz2"),
path.Join(noarchBasePath, "pkglist.aides.xz"),
path.Join(noarchBasePath, "release"),
path.Join(noarchBasePath, "release.aides"),
}
for _, filePath := range expectedFiles {
_, err := os.Stat(filePath)
assert.NoErrorf(t, err, "Файл %s не найден", filePath)
}
rpmPath := path.Join(x86_64RPMSPath, fileName)
linkDest, err := os.Readlink(rpmPath)
assert.NoError(t, err)
assert.Equal(t, path.Join("../../../../tasks/1", fileName), linkDest)
})
t.Run("Do not do anything if no updates", func(t *testing.T) { t.Run("Do not do anything if no updates", func(t *testing.T) {
// PREPARE // PREPARE
db := prepareDb(t) db := prepareDb(t)

View file

@ -5,8 +5,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
func TestTaskService_Create(t *testing.T) { func TestTaskService_Create(t *testing.T) {

View file

@ -13,8 +13,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
"code.aides.space/aides-infra/aides-repo-api/internal/services/taskservice" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
) )
func createMultipartFileHeader(filePath string) *multipart.FileHeader { func createMultipartFileHeader(filePath string) *multipart.FileHeader {

View file

@ -7,8 +7,8 @@ import (
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
"code.aides.space/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.aides.space/aides-infra/aides-repo-api/internal/models" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
) )
func prepareDb(t *testing.T) *gorm.DB { func prepareDb(t *testing.T) *gorm.DB {