Compare commits

..

10 commits
v1.0.0 ... main

Author SHA1 Message Date
Ada
d87201e851 Merge pull request 'Update module golang.org/x/sys to v0.22.0' (#17) from renovate/golang.org-x-sys-0.x into main
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
Reviewed-on: #17
2024-07-24 17:39:25 +02:00
dba2d01230 Update module golang.org/x/sys to v0.22.0
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
2024-07-24 15:37:21 +00:00
Ada
372cd70a31 Merge pull request 'Update golang Docker tag to v1.22.5' (#16) from renovate/golang-1.x into main
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
Reviewed-on: #16
2024-07-24 17:35:27 +02:00
9763152554 Update golang Docker tag to v1.22.5
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
2024-07-24 15:30:25 +00:00
Ada
b6313f8bf8 Merge pull request 'Update module golang.org/x/sys to v0.21.0' (#13) from renovate/golang.org-x-sys-0.x into main
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
Reviewed-on: #13
2024-06-05 20:01:48 +02:00
6a21bcdbd1 Update module golang.org/x/sys to v0.21.0
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
2024-06-05 17:57:22 +00:00
Ada
9587627a2d Merge pull request 'Update golang Docker tag to v1.22.4' (#14) from renovate/golang-1.x into main
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
Reviewed-on: #14
2024-06-05 19:55:38 +02:00
f916746a49 Update golang Docker tag to v1.22.4
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
2024-06-04 20:40:09 +00:00
Ada
5b67a66d74
Support clone of archived repo via /git/<name>
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
2024-05-26 22:00:55 +02:00
Ada
099419bbbd
Run ci only when needed
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
2024-05-25 14:36:20 +02:00
12 changed files with 95 additions and 12 deletions

View file

@ -4,3 +4,9 @@ steps:
commands: commands:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- golangci-lint run - golangci-lint run
when:
- event: pull_request
repo: ada/spiegel
- event: push
branch: main
repo: ada/spiegel

View file

@ -1,11 +1,11 @@
steps: steps:
- name: Release - name: Release
image: golang:1.22.3 image: golang:1.22.5
commands: commands:
- go install github.com/goreleaser/goreleaser@latest - go install github.com/goreleaser/goreleaser@latest
- goreleaser release - goreleaser release
secrets: [ gitea_token ] secrets: [ gitea_token ]
when: when:
event: tag event: tag
repo: ada/spiegel repo: ada/spiegel
depends_on: [] depends_on: []

View file

@ -3,3 +3,10 @@ steps:
image: golang:1.22 image: golang:1.22
commands: commands:
- go test ./... - go test ./...
when:
- event: pull_request
repo: ada/spiegel
- event: push
branch: main
repo: ada/spiegel

2
go.mod
View file

@ -6,7 +6,7 @@ require (
github.com/go-git/go-git/v5 v5.12.0 github.com/go-git/go-git/v5 v5.12.0
github.com/pelletier/go-toml/v2 v2.2.2 github.com/pelletier/go-toml/v2 v2.2.2
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
golang.org/x/sys v0.20.0 golang.org/x/sys v0.22.0
) )
require ( require (

4
go.sum
View file

@ -117,6 +117,10 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=

View file

@ -9,5 +9,5 @@ type Config struct {
CloneDirectory string // Repository where gir-mirror keep repository CloneDirectory string // Repository where gir-mirror keep repository
Log log.Config Log log.Config
Interval int // Update interval in minute Interval int // Update interval in minute
RepoList []git.RepoConfig RepoList []git.Config
} }

View file

@ -0,0 +1,7 @@
package constant
import "time"
const (
HTTPTimeout = 3 * time.Second
)

View file

@ -18,7 +18,7 @@ func start(duration time.Duration, fn func(), name string) {
} }
// Launch all repo update background tasks. // Launch all repo update background tasks.
func Launch(duration time.Duration, config []git.RepoConfig) { func Launch(duration time.Duration, config []git.Config) {
var counter int var counter int
for _, content := range config { for _, content := range config {
counter++ counter++

View file

@ -1,6 +1,6 @@
package git package git
type RepoConfig struct { type Config struct {
URL string // Source url URL string // Source url
FullPath string // Full clone directory FullPath string // Full clone directory
Name string // Name of clone (directory name) Name string // Name of clone (directory name)

View file

@ -8,11 +8,13 @@ import (
"git.gnous.eu/ada/spiegel/internal/utils" "git.gnous.eu/ada/spiegel/internal/utils"
goGit "github.com/go-git/go-git/v5" goGit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/serverinfo"
"github.com/go-git/go-git/v5/plumbing/transport/ssh" "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func StartClone(repoList []RepoConfig) { func StartClone(repoList []Config) {
logrus.Debug("Start first repository clone") logrus.Debug("Start first repository clone")
for _, content := range repoList { for _, content := range repoList {
_, err := os.Stat(content.FullPath) _, err := os.Stat(content.FullPath)
@ -22,7 +24,7 @@ func StartClone(repoList []RepoConfig) {
} }
} }
func (c RepoConfig) fullClone() { func (c Config) fullClone() {
logrus.Debug("Clone ", c.Name, "...") logrus.Debug("Clone ", c.Name, "...")
logger := logrus.New() logger := logrus.New()
w := logger.Writer() w := logger.Writer()
@ -66,9 +68,14 @@ func (c RepoConfig) fullClone() {
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
err = c.UpdateInfo()
if err != nil {
logrus.Error(err)
}
} }
func (c RepoConfig) Update() { func (c Config) Update() {
repo, err := goGit.PlainOpen(c.FullPath) repo, err := goGit.PlainOpen(c.FullPath)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
@ -117,4 +124,23 @@ func (c RepoConfig) Update() {
logrus.Error(err) logrus.Error(err)
} }
} }
err = c.UpdateInfo()
if err != nil {
logrus.Error(err)
}
}
func (c Config) UpdateInfo() error {
r, err := goGit.PlainOpen(c.FullPath)
if err != nil {
return err
}
err = serverinfo.UpdateServerInfo(r.Storer, r.Storer.(*filesystem.Storage).Filesystem()) //nolint: forcetypeassert
if err != nil {
return err
}
return nil
} }

29
internal/router/init.go Normal file
View file

@ -0,0 +1,29 @@
package router
import (
"net/http"
"git.gnous.eu/ada/spiegel/internal/constant"
"github.com/sirupsen/logrus"
)
type Config struct {
Listen string
Archive string
}
func (c Config) Router() {
mux := http.NewServeMux()
fs := http.FileServer(http.Dir(c.Archive))
mux.Handle("/git/", http.StripPrefix("/git/", fs))
server := &http.Server{
Addr: c.Listen,
Handler: mux,
ReadHeaderTimeout: constant.HTTPTimeout,
}
logrus.Info("HTTP listen on :5000")
logrus.Fatal(server.ListenAndServe())
}

View file

@ -9,6 +9,7 @@ import (
"git.gnous.eu/ada/spiegel/internal/config" "git.gnous.eu/ada/spiegel/internal/config"
"git.gnous.eu/ada/spiegel/internal/cron" "git.gnous.eu/ada/spiegel/internal/cron"
"git.gnous.eu/ada/spiegel/internal/git" "git.gnous.eu/ada/spiegel/internal/git"
"git.gnous.eu/ada/spiegel/internal/router"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -38,6 +39,9 @@ func main() {
logrus.Info("Config loaded") logrus.Info("Config loaded")
logrus.Debug("Config: ", initConfig) logrus.Debug("Config: ", initConfig)
routerConfig := router.Config{Listen: ":3000", Archive: initConfig.CloneDirectory}
go routerConfig.Router()
git.StartClone(initConfig.RepoList) git.StartClone(initConfig.RepoList)
duration := time.Duration(initConfig.Interval) * time.Minute duration := time.Duration(initConfig.Interval) * time.Minute