cibot

package
v0.0.0-...-e91f821 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2022 License: MulanPSL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCode_OK = iota
	ErrorCode_ServerHandleError
	ErrorCode_EmailError
	ErrorCode_TelephoneError
	ErrorCode_EmailNotTheSameError
)
View Source
const (
	PrivilegeManager   = "manager"
	PrivilegeDeveloper = "developer"
	PrivilegeViewer    = "viewer"
	PrivilegeReporter  = "reporter"

	PermissionAdmin = "admin"
	PermissionPush  = "push"
	PermissionPull  = "pull"

	BranchProtected = "protected"
	BranchNormal    = "normal"
	// not supported yet
	BranchReadonly = "readonly"
)
View Source
const (
	RemoveKind             = "/remove-kind"
	AddClaYes              = "/%s-cla yes"
	AddClaNo               = "/%s-cla no"
	RemoveClaYes           = "/remove-%s-cla yes"
	RemoveClaNo            = "/remove-%s-cla no"
	LabelNameLgtm          = "lgtm"
	LabelLgtmWithCommenter = "lgtm-%s"
	LabelNameApproved      = "approved"
	LabelHiddenValue       = "<input type=hidden value=%s />"

	DisplayCommittors = `If you have any questions, please contact the SIG: [%s](%s), and any of the maintainers: `
	SigPath           = `https://gitee.com/openeuler/community/tree/master/sig/%s`
	AutoAddPrjMsg     = `` /* 269-byte string literal not displayed */

)
View Source
const COOKIE_KEY string = "cla-info"

Variables

View Source
var (
	// RegAddLabel
	RegAddLabel = regexp.MustCompile(`(?mi)^/(kind|priority|sig)\s*(.*)$`)
	// RegRemoveLabel
	RegRemoveLabel = regexp.MustCompile(`(?mi)^/remove-(kind|priority|sig)\s*(.*)$`)
	// RegCheckCLA
	RegCheckCLA = regexp.MustCompile(`(?mi)^/check-cla\s*$`)
	// RegAddLgtm
	RegAddLgtm = regexp.MustCompile(`(?mi)^/lgtm\s*$`)
	// RegRemoveLgtm
	RegRemoveLgtm = regexp.MustCompile(`(?mi)^/lgtm cancel\s*$`)
	// RegAddApprove
	RegAddApprove = regexp.MustCompile(`(?mi)^/approve\s*$`)
	// RegRemoveApprove
	RegRemoveApprove = regexp.MustCompile(`(?mi)^/approve cancel\s*$`)
	// RegClose
	RegClose = regexp.MustCompile(`(?mi)^/close\s*$`)
	// RegReOpen
	RegReOpen = regexp.MustCompile(`(?mi)^/reopen\s*$`)
	// RegBotAddLgtm
	RegBotAddLgtm = regexp.MustCompile(fmt.Sprintf(LabelHiddenValue, "(.*)"))
	// RegAssign
	RegAssign = regexp.MustCompile(`(?mi)^/assign(( @?[-\w]+?)*)\s*$`)
	// RegUnAssign
	RegUnAssign = regexp.MustCompile(`(?mi)^/unassign(( @?[-\w]+?)*)\s*$`)
	// RegCheckPr
	RegCheckPr = regexp.MustCompile(`(?mi)^/check-pr\s*$`)
)
View Source
var (
	DefaultOwnerFileName = "OWNERS"
)
View Source
var Endpoint = oauth2.Endpoint{
	AuthURL:  "https://gitee.com/oauth/authorize",
	TokenURL: "https://gitee.com/oauth/token",
}

Functions

func DecodeOwners

func DecodeOwners(content string) []string

func GetChangeLabels

func GetChangeLabels(confDelLabels []string, prLabels []gitee.Label) (delLabels, updateLabels []string)

GetChangeLabels return the exact list of delete and update labels

func GetEmails

func GetEmails(ak string) ([]gitee.Email, error)

func GetLabelsMap

func GetLabelsMap(comment string) map[string]string

GetLabelsMap for add or remove labels

func GetListOfAddLabels

func GetListOfAddLabels(mapOfAddLabels map[string]string, listofRepoLabels []gitee.Label, listofItemLabels []gitee.Label) []string

GetListOfAddLabels return the exact list of add labels

func GetListOfRemoveLabels

func GetListOfRemoveLabels(mapOfRemoveLabels map[string]string, listofItemLabels []gitee.Label) []string

GetListOfRemoveLabels return the exact list of remove labels

func GetToken

func GetToken(code string) (*oauth2.Token, error)

func GetUser

func GetUser(ak string) (gitee.User, error)

func IsBranchFrozen

func IsBranchFrozen(branch string, community string) (owner []string, isFrozen bool)

IsBranchFrozen Check if the branch is frozen

func ParseDiffInfoAndGetProjectName

func ParseDiffInfoAndGetProjectName(diff string) (prjnames []string)

parse diff info

func Setup

func Setup(client, redirect, secret string) *oauth2.Config

func UrlEncode

func UrlEncode(str string) string

UrlEncode replcae special chars in url

Types

type Branch

type Branch struct {
	Name       *string `yaml:"name"`
	Type       *string `yaml:"type"`
	CreateFrom *string `yaml:"create_from"`
}

type CLAHandler

type CLAHandler struct {
	Context context.Context
}

func (*CLAHandler) HandleClaCheck

func (s *CLAHandler) HandleClaCheck(w http.ResponseWriter, r *http.Request, code string)

func (*CLAHandler) HandleRequest

func (s *CLAHandler) HandleRequest(w http.ResponseWriter, request CLARequest, accesskey string)

HandleRequest handles the cla request

func (*CLAHandler) HandleResult

func (s *CLAHandler) HandleResult(w http.ResponseWriter, r CLAResult)

HandleResult output result to client

func (*CLAHandler) ServeHTTP

func (s *CLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP validates an incoming cla request.

type CLARequest

type CLARequest struct {
	Type        int     `json:"type,omitempty"`
	Name        *string `json:"name,omitempty"`
	Title       *string `json:"title,omitempty"`
	Corporation *string `json:"corporation,omitempty"`
	Address     *string `json:"address,omitempty"`
	Date        *string `json:"date,omitempty"`
	Email       *string `json:"email,omitempty"`
	Telephone   *string `json:"telephone,omitempty"`
	Fax         *string `json:"fax,omitempty"`
}

type CLAResult

type CLAResult struct {
	IsSuccess   bool   `json:"isSuccess"`
	ErrorCode   int    `json:"errorCode"`
	Description string `json:"description,omitempty"`
}

type Community

type Community struct {
	Name              *string  `yaml:"name"`
	ProtectedBranches []string `yaml:"protected_branches"`
	Managers          []string `yaml:"managers"`
	Developers        []string `yaml:"developers"`
	Viewers           []string `yaml:"viewers"`
	Reporters         []string `yaml:"reporters"`
}

type FrozenBranchYaml

type FrozenBranchYaml struct {
	Branch    string   `yaml:"branch"`
	Frozen    bool     `yaml:"frozen"`
	Owner     []string `yaml:"owner"`
	Communtiy []string `yaml:"community"`
}

FrozenBranchYaml Branch freeze configuration

type FrozenHandler

type FrozenHandler struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

FrozenHandler Handling frozen branches

func (*FrozenHandler) Server

func (fh *FrozenHandler) Server()

type FrozenYaml

type FrozenYaml struct {
	Release []FrozenBranchYaml `yaml:"release"`
}

FrozenYaml freeze configuration

type InitHandler

type InitHandler struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

func (*InitHandler) Serve

func (handler *InitHandler) Serve()

Serve

type OwnerHandler

type OwnerHandler struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

func (*OwnerHandler) Serve

func (handler *OwnerHandler) Serve()

Serve

type OwnersFile

type OwnersFile struct {
	Maintainers []string `yaml:"maintainers"`
}

type Projects

type Projects struct {
	Community    Community    `yaml:"community"`
	Repositories []Repository `yaml:"repositories"`
}

type RepoHandler

type RepoHandler struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

func (*RepoHandler) Serve

func (handler *RepoHandler) Serve()

Serve

type Repos

type Repos struct {
	Version      string       `yaml:"version"`
	Community    string       `yaml:"community"`
	Repositories []Repository `yaml:"repositories"`
}

type Repository

type Repository struct {
	Name              *string  `yaml:"name"`
	Description       *string  `yaml:"description"`
	ProtectedBranches []string `yaml:"protected_branches"`
	Commentable       *bool    `yaml:"commentable"`
	Type              *string  `yaml:"type"`
	RenameFrom        *string  `yaml:"rename_from"`
	Managers          []string `yaml:"managers"`
	Developers        []string `yaml:"developers"`
	Viewers           []string `yaml:"viewers"`
	Reporters         []string `yaml:"reporters"`
	Branches          []Branch `yaml:"branches"`
}

func (Repository) IsCommentable

func (r Repository) IsCommentable() bool

IsCommentable returns if contributors are able to comment to the repository. It will be true only if Commentable is explicitly sepecified as true

type Server

type Server struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

func (*Server) AddApprove

func (s *Server) AddApprove(event *gitee.NoteEvent) error

AddApprove adds approved label

func (*Server) AddLabel

func (s *Server) AddLabel(event *gitee.NoteEvent) error

AddLabel adds label

func (*Server) AddLabelInIssue

func (s *Server) AddLabelInIssue(event *gitee.NoteEvent) error

AddLabelInIssue adds label in issue

func (*Server) AddLabelInPulRequest

func (s *Server) AddLabelInPulRequest(event *gitee.NoteEvent) error

AddLabelInPulRequest adds label in pull request

func (*Server) AddLgtm

func (s *Server) AddLgtm(event *gitee.NoteEvent) error

AddLgtm adds lgtm label

func (*Server) AddSpecifyLabelsInPulRequest

func (s *Server) AddSpecifyLabelsInPulRequest(event *gitee.NoteEvent, newLabels []string, createNew bool) error

AddSpecifyLabelInPulRequest adds specify labels in pull request

func (*Server) Assign

func (s *Server) Assign(event *gitee.NoteEvent) error

Assign a collaborator for issue

func (*Server) CheckCLAByNoteEvent

func (s *Server) CheckCLAByNoteEvent(event *gitee.NoteEvent) error

CheckCLAByNoteEvent check cla by NoteEvent

func (*Server) CheckCLAByPullRequestEvent

func (s *Server) CheckCLAByPullRequestEvent(event *gitee.PullRequestEvent) error

CheckCLAByPullRequestEvent check cla by PullRequestEvent

func (*Server) CheckIsOwner

func (s *Server) CheckIsOwner(event *gitee.NoteEvent, author string) bool

CheckIsOwner checks the author is owner in repository

func (*Server) CheckLgtmByPullRequestUpdate

func (s *Server) CheckLgtmByPullRequestUpdate(event *gitee.PullRequestEvent) error

CheckLgtmByPullRequestUpdate checks lgtm when received the pull request update event

func (*Server) CheckPr

func (s *Server) CheckPr(event *gitee.NoteEvent) (err error)

CheckPr Check whether the pull request can be merged

func (*Server) CheckSpecialFileHasModified

func (s *Server) CheckSpecialFileHasModified(event *gitee.PullRequestEvent, specialfile string) (diff string)

Get the diff info with merge and choose projects to be added

func (*Server) CheckWetherNewItemInObsProjects

func (s *Server) CheckWetherNewItemInObsProjects(event *gitee.PullRequestEvent, prjname string, branch string, repo string, owner string) (exist bool)

Check whether the new item in src-openeuler.yaml is in project

func (*Server) Close

func (s *Server) Close(event *gitee.NoteEvent) error

Close closes pr or issue

func (*Server) FillServicePathAndContentWithProjectName

func (s *Server) FillServicePathAndContentWithProjectName(prjname string) (_servicepath string, _service string)

Fill file _service path and content

func (*Server) GetOwners

func (s *Server) GetOwners(event *gitee.NoteEvent) []string

GetOwners gets owners from owners file in repository

func (*Server) HandleIssueEvent

func (s *Server) HandleIssueEvent(event *gitee.IssueEvent)

HandleIssueEvent handles issue event

func (*Server) HandleNoteEvent

func (s *Server) HandleNoteEvent(event *gitee.NoteEvent)

HandleNoteEvent handles note event

func (*Server) HandlePullRequestEvent

func (s *Server) HandlePullRequestEvent(actionDesc string, event *gitee.PullRequestEvent)

HandlePullRequestEvent handles pull request event

func (*Server) HandlePushEvent

func (s *Server) HandlePushEvent(event *gitee.PushEvent)

HandlePushEvent handles push event

func (*Server) HandleWatchProjectFiles

func (s *Server) HandleWatchProjectFiles(event *gitee.PushEvent)

HandleWatchProjectFiles

func (*Server) HandleWatchSigFiles

func (s *Server) HandleWatchSigFiles(event *gitee.PushEvent)

HandleWatchSigFiles

func (*Server) MergePullRequest

func (s *Server) MergePullRequest(event *gitee.NoteEvent) error

MergePullRequest with lgtm and approved label

func (*Server) NewFileWithPathAndContentInPullRequest

func (s *Server) NewFileWithPathAndContentInPullRequest(event *gitee.PullRequestEvent, path string, content string, branch string, repo string, owner string)

New project with name in pull

func (*Server) ReOpen

func (s *Server) ReOpen(event *gitee.NoteEvent) error

ReOpen reopens pr or issue

func (*Server) RemoveApprove

func (s *Server) RemoveApprove(event *gitee.NoteEvent) error

RemoveApprove removes approved label

func (*Server) RemoveAssigneesInPullRequest

func (s *Server) RemoveAssigneesInPullRequest(event *gitee.NoteEvent) error

RemoveAssigneesInPullRequest remove assignees in pull request

func (*Server) RemoveLabel

func (s *Server) RemoveLabel(event *gitee.NoteEvent) error

RemoveLabel removes label

func (*Server) RemoveLabelInIssue

func (s *Server) RemoveLabelInIssue(event *gitee.NoteEvent) error

RemoveLabelInIssue removes label in issue

func (*Server) RemoveLabelInPullRequest

func (s *Server) RemoveLabelInPullRequest(event *gitee.NoteEvent) error

RemoveLabelInPullRequest removes label in pull request

func (*Server) RemoveLgtm

func (s *Server) RemoveLgtm(event *gitee.NoteEvent) error

RemoveLgtm removes lgtm label

func (*Server) RemoveSpecifyLabelsInPulRequest

func (s *Server) RemoveSpecifyLabelsInPulRequest(event *gitee.NoteEvent, mapOfRemoveLabels map[string]string) error

RemoveSpecifyLabelsInPulRequest removes specify labels in pull request

func (*Server) RemoveTestersInPullRequest

func (s *Server) RemoveTestersInPullRequest(event *gitee.NoteEvent) error

RemoveTestersInPullRequest remove testers in pull request

func (*Server) SendNote4AutomaticNewFile

func (s *Server) SendNote4AutomaticNewFile(event *gitee.PullRequestEvent)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP validates an incoming webhook and invoke its handler.

func (*Server) UnAssign

func (s *Server) UnAssign(event *gitee.NoteEvent) error

UnAssign a collaborator for issue

func (*Server) UpdateLabelsBySourceBranchChange

func (s *Server) UpdateLabelsBySourceBranchChange(delLabels, updateLabels []string, event *gitee.PullRequestEvent) error

func (*Server) ValidateCommits

func (s *Server) ValidateCommits(event *gitee.PullRequestEvent) error

type Sig

type Sig struct {
	Name         string   `yaml:"name"`
	Repositories []string `yaml:"repositories"`
}

type SigHandler

type SigHandler struct {
	Config      config.Config
	Context     context.Context
	GiteeClient *gitee.APIClient
}

func (*SigHandler) Serve

func (handler *SigHandler) Serve()

Serve

type SigsYaml

type SigsYaml struct {
	Sigs []Sig `yaml:"sigs"`
}

type Webhook

type Webhook struct {
	Address    string
	Port       int64
	ConfigFile string
}

func NewWebHook

func NewWebHook() *Webhook

func (*Webhook) AddFlags

func (s *Webhook) AddFlags(fs *pflag.FlagSet)

func (*Webhook) Run

func (s *Webhook) Run()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL