client

package
v0.4.3-beta Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ErrorMessageReadRequestBodyFail = "Failed to read request body"
	HeaderUserAgent                 = "User-Agent"
	UserAgentGithub                 = "GitHub-Hookshot"
	UserAgentGitCode                = "git-gitcode-hook"
	UserAgentGitee                  = "git-oschina-hook"

	HeaderContentTypeName      = "Content-Type"
	HeaderContentTypeJsonValue = "application/json"
)
View Source
const (
	HeaderRobotChain       = "Robot-Chain"
	HeaderRobotChainAuthed = "Request-Authenticated"
	CommentOnIssue         = "Issue"
	CommentOnPR            = "MergeRequest"
)
View Source
const (
	Read                = "read"
	Write               = "write"
	Admin               = "admin"
	CLASignStateYes     = "yes"
	CLASignStateNo      = "no"
	CLASignStateUnknown = "unknown"
)
View Source
const (
	CommunityOpenGauss = "opengauss"
	CommunityOpenFuyao = "openfuyao"
	CommunityOpenUBMC  = "openubmc"
)

Variables

View Source
var (
	ErrorMessageRequestMethodNoSupport        = http.StatusText(http.StatusMethodNotAllowed)
	ErrorMessageRequestContentTypeNoSupported = http.StatusText(http.StatusUnsupportedMediaType)
)

Functions

func ParseSigInfo

func ParseSigInfo(list []SigInfo, org, repo string)

func ReadPayload

func ReadPayload(w http.ResponseWriter, r *http.Request) (*bytes.Buffer, error)

func SetCommunityName added in v0.2.0

func SetCommunityName(name string)

func SetSigInfoBaseURL added in v0.2.0

func SetSigInfoBaseURL(uri string)

Types

type Authenticate

type Authenticate interface {
	Auth(w http.ResponseWriter, r *http.Request) error
	GetEventType() string
	GetEventGUID() string
}

type Authentication

type Authentication struct {
	Secret []byte
	// contains filtered or unexported fields
}

func (*Authentication) CheckRequest

func (a *Authentication) CheckRequest(w http.ResponseWriter, r *http.Request) error

func (*Authentication) DoAuthentication

func (a *Authentication) DoAuthentication(w http.ResponseWriter, r *http.Request) (error, *bytes.Buffer, string, string)

func (*Authentication) Validate

func (a *Authentication) Validate() error

type Branch

type Branch struct {
	Name      string
	Commit    Commit
	Protected bool
}

type BranchAttr

type BranchAttr struct {
	Name       string `yaml:"name,omitempty" json:"name,omitempty"`
	Type       string `yaml:"type,omitempty" json:"type,omitempty"`
	CreateFrom string `yaml:"create_from,omitempty" json:"create_from,omitempty"`
	Keeper     string `yaml:"-" json:"keeper,omitempty"`
}

type CLASignature added in v0.2.0

type CLASignature struct {
	Type           string `json:"type"`
	Signed         bool   `json:"signed"`
	VersionMatched bool   `json:"version_matched"`
}

type Client

type Client interface {
	ListRepoAllMember(org, repo string) (result []User, success bool)
	ListOrgMember(org, role string) (result []User, success bool)
	ListSigInfo(org, repo string) (result []SigInfo, success bool)
	ListPullRequestComments(org, repo, number string) (result []PRComment, success bool)
	ListPullRequestOperationLogs(org, repo, number string) (result []PullRequestOperationLog, success bool)
	ListOrgRepo(org, repo string) (result []Repository, success bool)
	ListFileOwner(repo, version string) (result []RepoFileManage, retVersion string, success bool)

	GetIssue(org, repo, number string) (result Issue, success bool)
	GetIssueLinkedPRNumber(org, repo, number string) (num int, success bool)
	GetPullRequestCommits(org, repo, number string) (result []PRCommit, success bool)
	GetPathContent(org, repo, path, ref string) (result RepoContent, success bool)
	GetPullRequestChanges(org, repo, number string) (result []CommitFile, success bool)
	GetPullRequestLabels(org, repo, number string) (result []string, success bool)
	GetIssueLabels(org, issueID string) (result []string, success bool)
	GetRepoIssueLabels(org, repo string) (result []string, success bool)
	GetRepoWithBranch(org, repo, branch string) (result Branch, success bool)
	GetPRLinkedIssue(org, repo, number string) (result []Issue, success bool)
	GetUserByUsername(username string) (result User, success bool)
	GetRepoCustomRoles(org, repo string) (result []CustomRole, success bool)
	GetRepoAllBranch(org, repo string) (result []Branch, success bool)
	GetRepoTrees(org, repo, sha, recursive string) (result []RepoContent, success bool)
	GetRepoFileList(org, repo, refName, fileName string) (result []string, success bool)

	CreateRepoIssueLabel(org, repo, name, color string) (success bool)
	CreatePRComment(org, repo, number, comment string) (success bool)
	CreateIssueComment(org, repo, number, comment string) (success bool)
	AddOrgMember(org, username, permission, roleID string) (success bool)
	AddIssueLabels(org, repo, number string, labels []string) (success bool)
	AddPRLabels(org, repo, number string, labels []string) (success bool)
	CreateOrgRepo(org, repo, description, branch, public string) (success bool)
	CreateRepoBranch(org, repo, createFrom, branch string) (success bool)
	CreateProtectedBranch(org, repo, branch string) (success bool)

	UpdateIssue(org, repo, number string, data Issue) (success bool)
	UpdatePR(org, repo, number, state string) (success bool)
	MergePullRequest(org, repo, number, mergeMethod string) (success bool, err error)
	UpdatePRSetting(org, repo string) (success bool)

	RemoveOrgMember(org, username string) (success bool)
	RemoveIssueLabels(org, repo, number string, labels []string) (success bool)
	RemovePRLabels(org, repo, number string, labels []string) (success bool)
	DeleteRepoIssueLabel(org, repo, name string) (success bool)
	DeletePRComment(org, repo, commentID string) (success bool)

	CheckPermission(org, repo, username string) (pass, success bool)
	CheckCLASignature(urlStr string) (signState string, success bool)
	CheckCLAResult(urlStr string) (CLASignature, bool)
	CheckRepoMemberPermission(org, repo, username string) (pass, success bool)
	CheckSigPermission(org, repo, username string) (pass, success bool)

	CheckIfPRCreateEvent(evt *GenericEvent) (yes bool)
	CheckIfIssueCreateEvent(evt *GenericEvent) (yes bool)
	CheckIfPRSourceCodeUpdateEvent(evt *GenericEvent) (yes bool)
	CheckIfPRReopenEvent(evt *GenericEvent) (yes bool)
	CheckIfPRLabelsUpdateEvent(evt *GenericEvent) (yes bool)
	CheckIfPRSelfUpdateEvent(evt *GenericEvent) (yes bool)
	CheckIfPRLinkIssueUpdateEvent(evt *GenericEvent) (yes bool)
}

func NewClient

func NewClient(token []byte, logger *logrus.Entry) Client

NewClient 通过 token 请求每个代码平台的接口,来确定使用哪个平台的 OpenAPI。也有可能返回 nil

type Commit

type Commit struct {
	ID      string
	Title   string
	Message string
	SHA     string
	Detail  CommitDetail
}

type CommitDetail

type CommitDetail struct {
	SHA       string
	Author    PRCommit
	Committer PRCommit
	Message   string
}

type CommitFile added in v0.2.0

type CommitFile struct {
	SHA              *string
	Filename         *string
	Additions        *int
	Deletions        *int
	Changes          *int
	Status           *string
	Patch            *CommitPatch
	BlobURL          *string
	RawURL           *string
	ContentsURL      *string
	PreviousFilename *string
}

type CommitPatch added in v0.2.0

type CommitPatch struct {
	Diff        *string
	OldPath     *string
	NewPath     *string
	NewFile     *bool
	RenamedFile *bool
	DeletedFile *bool
	TooLarge    *bool
}

type CustomRole

type CustomRole struct {
	ID   string
	Name string
}

type Dataset

type Dataset struct {
	StatusCode int              `json:"code"`
	Message    string           `json:"msg"`
	Version    string           `json:"version,omitempty"`
	Data       []SigInfo        `json:"data,omitempty"`
	File       []RepoFileManage `json:"file,omitempty"`
}

type GenericEvent

type GenericEvent struct {
	EventType      *string `json:"eventType" log:"event-type"`
	EventGUID      *string `json:"eventGUID" log:"event-guid"`
	Action         *string `json:"action" log:"action"`
	ActionDetail   *string `json:"actionDetail" log:"action-detail"`
	Org            *string `json:"org" log:"org"`
	Repo           *string `json:"repo" log:"repo"`
	HtmlURL        *string `json:"htmlURL" log:"html-url"`
	Base           *string `json:"base"`
	Head           *string `json:"head"`
	State          *string `json:"state" log:"state"`
	ID             *string `json:"id" log:"id"`         // issues or pull requests id
	Number         *string `json:"number" log:"number"` // issues or pull requests number
	Author         *string `json:"author"`
	CommentID      *string `json:"commentID" log:"comment-id"`
	CommentKind    *string `json:"commentKind" log:"comment-kind"`
	Comment        *string `json:"comment" log:"comment"`
	Commenter      *string `json:"commenter" log:"commenter"`
	CreateTime     *string `json:"createTime" log:"create-time"`
	UpdateTime     *string `json:"updateTime" log:"update-time"`
	RepoVisibility *string `json:"repoVisibility"`
	// contains filtered or unexported fields
}

func NewGenericEvent

func NewGenericEvent(w http.ResponseWriter, r *http.Request, l *logrus.Entry) *GenericEvent

func (*GenericEvent) CollectLoggingFields

func (e *GenericEvent) CollectLoggingFields() *map[string]interface{}

func (*GenericEvent) GetMetaPayload added in v0.2.0

func (e *GenericEvent) GetMetaPayload() *bytes.Buffer

type Issue

type Issue struct {
	Number          *string
	State           *string
	IssueState      *string
	Priority        *int
	Title           *string
	Body            *string
	User            *string
	Assignee        *string
	MilestoneNumber *int
}

type PRComment added in v0.2.0

type PRComment struct {
	ID         string
	Body       string
	Commenter  string
	CreateTime time.Time
	UpdateTime time.Time
}

type PRCommit added in v0.2.0

type PRCommit struct {
	SHA            string
	HTMLURL        string
	Message        string
	AuthorName     string
	AuthorEmail    string
	CommitterName  string
	CommitterEmail string
	CommitTime     time.Time
}

type PullRequestOperationLog added in v0.2.0

type PullRequestOperationLog struct {
	CreatedAt time.Time
	Content   string
	Action    string
	UpdatedAt time.Time
	UserName  string
}

type RepoContent added in v0.2.0

type RepoContent struct {
	Type            *string
	Target          *string
	Encoding        *string
	Size            *int64
	Name            *string
	Path            *string
	Content         *string
	SHA             *string
	URL             *string
	HTMLURL         *string
	DownloadURL     *string
	SubmoduleGitURL *string
}

type RepoFileManage

type RepoFileManage struct {
	File  []string    `yaml:"file,omitempty" json:"file,omitempty"`
	Owner []*UserInfo `yaml:"owner,omitempty" json:"owner,omitempty"`
}

type Repository

type Repository struct {
	Name        string            `yaml:"name,omitempty" json:"name,omitempty"`
	Description string            `yaml:"description,omitempty" json:"description,omitempty"`
	Type        string            `yaml:"type,omitempty" json:"type,omitempty"`
	Upstream    string            `yaml:"upstream,omitempty" json:"upstream,omitempty"`
	Platform    string            `yaml:"platform,omitempty" json:"platform,omitempty"`
	Branches    []*BranchAttr     `yaml:"branches,omitempty" json:"branches,omitempty"`
	FilesManage []*RepoFileManage `yaml:"files,omitempty" json:"files,omitempty"`
}

type RepositoryInfo

type RepositoryInfo struct {
	Committers     []*UserInfo `yaml:"committers,omitempty" json:"committers,omitempty"`
	RepositoryList []string    `yaml:"repo,omitempty" json:"repo,omitempty"`
	RepoDetail     *Repository `yaml:"-" json:"repo_detail,omitempty"`
}

type RepositoryRequest

type RepositoryRequest struct {
	Path          string
	Name          string
	Description   string
	Private       bool
	Public        int
	AutoInit      bool
	DefaultBranch string
}

type SigInfo added in v0.2.0

type SigInfo struct {
	SigName        string            `json:"sig_name,omitempty"`
	Maintainers    []string          `json:"maintainers,omitempty"`
	Committers     []string          `json:"committers,omitempty"`
	RepositoryList []string          `json:"repos,omitempty"`
	RepositoryInfo []*RepositoryInfo `json:"repositories,omitempty"`
}

type User added in v0.2.0

type User struct {
	UserName   string
	NickName   string
	Role       string
	Permission string
}

type UserInfo

type UserInfo struct {
	GiteeID      string `yaml:"gitee_id,omitempty" json:"gitee_id,omitempty"`
	GitCodeID    string `yaml:"gitcode_id,omitempty" json:"gitcode_id,omitempty"`
	Name         string `yaml:"name,omitempty" json:"name,omitempty"`
	Organization string `yaml:"organization,omitempty" json:"organization,omitempty"`
	Email        string `yaml:"email,omitempty" json:"email,omitempty"`
}

Jump to

Keyboard shortcuts

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