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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ https://gitlab.com/Gasoid/sugar-test
- `!update`: updates the branch from destination branch (e.g. master) changes

### Use-cases
Given a lot of repos, therefore we require to set up various rules for each of them. It is complicated and tedious to run as many bot instances as teams.
The Merge-bot checks whether MRs meet rules of the repository (.mrbot.yaml file). Owner of repo can create his own set of rules.
- Given a lot of repos, therefore we require to set up various rules for each of them. It is complicated and tedious to run as many bot instances as teams. The Merge-bot checks whether MRs meet rules of the repository (.mrbot.yaml file). Owner of repo can create his own set of rules.

- Opensource solution to get premium features

## Installation
The Bot could be run within your infrastructure as container.
Expand Down Expand Up @@ -110,7 +111,7 @@ Usage of merge-bot:
-gitlab-url string
in case of self-hosted gitlab, you need to set this var up (also via GITLAB_URL)
-gitlab-max-repo-size string
max size of repo in bytes, default is 500Mb (also via GITLAB_MAX_REPO_SIZE)
max size of repo in in Gb/Mb/Kb, default is 500Mb (also via GITLAB_MAX_REPO_SIZE)
-tls-domain string
which domain is used for ssl certificate (also via TLS_DOMAIN)
-tls-enabled
Expand Down
6 changes: 3 additions & 3 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func StringVar(p *string, name string, value string, usage string) {
fs.StringVar(p, name, value, usage)
}

func IntVar(p *int, name string, value int, usage string) {
fs.IntVar(p, name, value, usage)
}
// func IntVar(p *int, name string, value int, usage string) {
// fs.IntVar(p, name, value, usage)
// }

func BoolVar(p *bool, name string, value bool, usage string) {
fs.BoolVar(p, name, value, usage)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module mergebot
go 1.24.1

require (
github.com/dustin/go-humanize v1.0.1
github.com/getsentry/sentry-go v0.33.0
github.com/getsentry/sentry-go/echo v0.33.0
github.com/getsentry/sentry-go/slog v0.33.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/getsentry/sentry-go v0.33.0 h1:YWyDii0KGVov3xOaamOnF0mjOrqSjBqwv48UEzn7QFg=
github.com/getsentry/sentry-go v0.33.0/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE=
github.com/getsentry/sentry-go/echo v0.33.0 h1:wizehrPbzUUooTLcxB0XUnlAoP7reSy4GQvH4zdY+xA=
Expand Down
12 changes: 9 additions & 3 deletions handlers/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"mergebot/logger"
"net/http"

"github.com/dustin/go-humanize"
"github.com/xanzy/go-gitlab"
)

Expand All @@ -17,13 +18,13 @@ func init() {

config.StringVar(&gitlabToken, "gitlab-token", "", "in order to communicate with gitlab api, bot needs token (also via GITLAB_TOKEN)")
config.StringVar(&gitlabURL, "gitlab-url", "", "in case of self-hosted gitlab, you need to set this var up (also via GITLAB_URL)")
config.IntVar(&maxRepoSize, "gitlab-max-repo-size", 1000*1000*500, "max size of repo in bytes, default is 500Mb (also via GITLAB_MAX_REPO_SIZE)")
config.StringVar(&maxRepoSize, "gitlab-max-repo-size", "500Mb", "max size of repo in Gb/Mb/Kb, default is 500Mb (also via GITLAB_MAX_REPO_SIZE)")
}

var (
gitlabToken string
gitlabURL string
maxRepoSize int
maxRepoSize string
)

const (
Expand Down Expand Up @@ -62,7 +63,12 @@ func (g *GitlabProvider) UpdateFromMaster(projectId, mergeId int) error {
return err
}

if project.Statistics.RepositorySize > int64(maxRepoSize) {
bytes, err := humanize.ParseBytes(maxRepoSize)
if err != nil {
return err
}

if uint64(project.Statistics.RepositorySize) > bytes {
return handlers.RepoSizeError
}

Expand Down
Loading