Skip to content
Open
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
35 changes: 0 additions & 35 deletions rules/empty_repository.go

This file was deleted.

34 changes: 0 additions & 34 deletions rules/fast-forward-merge.go

This file was deleted.

37 changes: 0 additions & 37 deletions rules/has_open_issues.go

This file was deleted.

41 changes: 0 additions & 41 deletions rules/last_activity.go

This file was deleted.

19 changes: 0 additions & 19 deletions rules/my_registry.go

This file was deleted.

6 changes: 6 additions & 0 deletions rules/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/xanzy/go-gitlab"
)

var MyRegistry = &Registry{
Projects: map[string]Project{},
Rules: []Rule{},
RulesFn: map[string]Ruler{},
}

type Registry struct {
mu sync.Mutex
Projects map[string]Project
Expand Down
25 changes: 25 additions & 0 deletions rules/rule/empty_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type EmptyRepository struct {
rules.RulerImpl
}

func (e *EmptyRepository) Run(c *gitlab.Client, p *gitlab.Project) bool {
return p.EmptyRepo
}

func NewEmptyRepository() rules.Ruler {
e := new(EmptyRepository)
e.ID = "empty-repository"
e.Name = "Empty Repository"
e.Level = rules.LevelError
return e
}
25 changes: 25 additions & 0 deletions rules/rule/fast-forward-merge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type NonFastForwardMerge struct {
rules.RulerImpl
}

func (w *NonFastForwardMerge) Run(c *gitlab.Client, p *gitlab.Project) bool {
return p.MergeMethod != gitlab.FastForwardMerge
}

func NewNonFastForwardMerge() rules.Ruler {
w := new(NonFastForwardMerge)
w.ID = "non-fast-forward-merge"
w.Name = "Non Fast-forward Merge"
w.Level = rules.LevelPedantic
return w
}
25 changes: 25 additions & 0 deletions rules/rule/has_open_issues.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type HasOpenIssues struct {
rules.RulerImpl
}

func (h *HasOpenIssues) Run(c *gitlab.Client, p *gitlab.Project) bool {
return p.OpenIssuesCount > 0
}

func NewHasOpenIssues() rules.Ruler {
h := new(HasOpenIssues)
h.ID = "has-open-issues"
h.Name = "Has Open Issues"
h.Level = rules.LevelPedantic
return h
}
29 changes: 29 additions & 0 deletions rules/rule/last_activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"time"

"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type LastActivity struct {
rules.RulerImpl
}

func (l *LastActivity) Run(c *gitlab.Client, p *gitlab.Project) bool {
t2 := time.Now()
days := t2.Sub(*p.LastActivityAt).Hours() / 24
return days > 365
}

func NewLastActivity() rules.Ruler {
l := new(LastActivity)
l.ID = "last-activity-1-year"
l.Name = "Last Activity > 1 year"
l.Level = rules.LevelWarning
return l
}
17 changes: 17 additions & 0 deletions rules/rule/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
)

func init() {
rules.MyRegistry.AddRule(NewEmptyRepository())
rules.MyRegistry.AddRule(NewHasOpenIssues())
rules.MyRegistry.AddRule(NewLastActivity())
rules.MyRegistry.AddRule(NewNonFastForwardMerge())
rules.MyRegistry.AddRule(NewWithoutGitlabCI())
rules.MyRegistry.AddRule(NewWithoutReadme())
}
32 changes: 32 additions & 0 deletions rules/rule/without_gitlab_ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type WithoutGitlabCI struct {
rules.RulerImpl
}

func (w *WithoutGitlabCI) Run(c *gitlab.Client, p *gitlab.Project) bool {
gf := &gitlab.GetFileOptions{
Ref: gitlab.String(p.DefaultBranch),
}
_, _, err := c.RepositoryFiles.GetFile(
p.PathWithNamespace, ".gitlab-ci.yml", gf,
)
// 404
return err != nil
}

func NewWithoutGitlabCI() rules.Ruler {
w := new(WithoutGitlabCI)
w.ID = "without-gitlab-ci"
w.Name = "Without Gitlab CI"
w.Level = rules.LevelInfo
return w
}
25 changes: 25 additions & 0 deletions rules/rule/without_readme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021, Marcelo Jorge Vieira
// Licensed under the BSD 3-Clause License

package ruler

import (
"github.com/globocom/gitlab-lint/rules"
"github.com/xanzy/go-gitlab"
)

type WithoutReadme struct {
rules.RulerImpl
}

func (w *WithoutReadme) Run(c *gitlab.Client, p *gitlab.Project) bool {
return p.ReadmeURL == ""
}

func NewWithoutReadme() rules.Ruler {
w := new(WithoutReadme)
w.ID = "without-readme"
w.Name = "Without Readme"
w.Level = rules.LevelError
return w
}
15 changes: 15 additions & 0 deletions rules/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ type Ruler interface {
GetSlug() string
GetLevel() string
}

type RulerImpl struct {
ID string `json:"ruleId"`
Name string `json:"name"`
Description string `json:"description"`
Level string `json:"level"`
}

func (e RulerImpl) GetSlug() string {
return e.ID
}

func (e RulerImpl) GetLevel() string {
return e.Level
}
Loading