github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/core/repo.go (about)

     1  package core
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  )
     7  
     8  //go:generate mockgen -package mock -destination ../mock/repo_mock.go . RepoStore,RepoService
     9  
    10  // Repo defined a repository structure
    11  type Repo struct {
    12  	ID        uint
    13  	URL       string
    14  	ReportID  string
    15  	NameSpace string
    16  	Name      string
    17  	Branch    string
    18  	Private   bool
    19  	SCM       SCMProvider
    20  }
    21  
    22  // RepoSetting to customize repository
    23  type RepoSetting struct {
    24  	Filters          FileNameFilters    `json:"filters"`
    25  	MergePullRequest bool               `json:"mergePR"`
    26  	UpdateAction     ReportUpdateAction `json:"updateAction"`
    27  	// Protected project from unauthorized user upload report
    28  	Protected bool `json:"protected"`
    29  }
    30  
    31  // RepoService provides repository opperations
    32  type RepoService interface {
    33  	// Synchronize repositories data from remote and store to database
    34  	Synchronize(ctx context.Context, user *User) error
    35  }
    36  
    37  // RepoStore repository in storage
    38  type RepoStore interface {
    39  	Create(repo *Repo) error
    40  	Update(repo *Repo) error
    41  	UpdateOrCreate(repo *Repo) error
    42  	BatchUpdateOrCreate(repos []*Repo) error
    43  	Find(repo *Repo) (*Repo, error)
    44  	Finds(urls ...string) ([]*Repo, error)
    45  	// Creator is the user activated the repository
    46  	Creator(repo *Repo) (*User, error)
    47  	UpdateCreator(repo *Repo, user *User) error
    48  	Setting(repo *Repo) (*RepoSetting, error)
    49  	UpdateSetting(repo *Repo, setting *RepoSetting) error
    50  	FindHook(repo *Repo) (*Hook, error)
    51  	UpdateHook(repo *Repo, hook *Hook) error
    52  }
    53  
    54  // FullName is namespace+name
    55  func (repo *Repo) FullName() string {
    56  	return fmt.Sprintf("%s/%s", repo.NameSpace, repo.Name)
    57  }