client

package
v0.2.10-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 16 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 (
	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"
)

Variables

This section is empty.

Functions

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, bool)
	GetPayload() *bytes.Buffer
	GetEventType() string
	GetEventGUID() string
}

type Authentication

type Authentication struct {
	Secret []byte
}

func (*Authentication) DoAuthentication

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

type Branch

type Branch struct {
	Name      string
	Commit    Commit
	Protected bool
}

type BranchAttr

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

type CLASignature added in v0.2.0

type CLASignature struct {
	Signed bool `json:"signed"`
}

type Client

type Client interface {
	CreatePRComment(org, repo, number, comment string) (success bool)
	CreateIssueComment(org, repo, number, comment string) (success bool)
	ListRepoAllMember(org, repo string) (result []User, success bool)
	ListSigAllMember(org, repo string) (result []SigInfo, success bool)
	CheckPermission(org, repo, username string) (pass, success bool)
	UpdateIssue(org, repo, number, state string) (success bool)
	UpdatePR(org, repo, number, state string) (success bool)
	GetIssueLinkedPRNumber(org, repo, number string) (num int, success bool)
	CreateRepoIssueLabel(org, repo, name, color string) (success bool)
	DeleteRepoIssueLabel(org, repo, name string) (success bool)
	AddIssueLabels(org, repo, number string, labels []string) (success bool)
	RemoveIssueLabels(org, repo, number string, labels []string) (success bool)
	AddPRLabels(org, repo, number string, labels []string) (success bool)
	RemovePRLabels(org, repo, number string, labels []string) (success bool)
	GetPullRequestCommits(org, repo, number string) (result []PRCommit, success bool)
	ListPullRequestComments(org, repo, number string) (result []PRComment, success bool)
	DeletePRComment(org, repo, commentID string) (success bool)
	CheckCLASignature(urlStr string) (signState string, success bool)
	CheckIfPRCreateEvent(evt *GenericEvent) (yes bool)
	CheckIfIssueCreateEvent(evt *GenericEvent) (yes bool)
	CheckIfPRSourceCodeUpdateEvent(evt *GenericEvent) (yes bool)
	CheckRepoMemberPermission(org, repo, username string) (pass, success bool)
	CheckSigPermission(org, repo, username string) (pass, success bool)
	GetPathContent(org, repo, path, ref string) (result RepoContent, success bool)
	GetPullRequestChanges(org, repo, number string) (result []CommitFile, success bool)
	MergePullRequest(org, repo, number, mergeMethod string) (success bool)
	GetPullRequestLabels(org, repo, number string) (result []string, success bool)
	ListPullRequestOperationLogs(org, repo, number string) (result []PullRequestOperationLog, success bool)
	CheckIfPRReopenEvent(evt *GenericEvent) (yes bool)
	CheckIfPRLabelsUpdateEvent(evt *GenericEvent) (yes 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)
}

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
}

type CommitFile added in v0.2.0

type CommitFile struct {
	SHA              *string      `json:"sha,omitempty"`
	Filename         *string      `json:"filename,omitempty"`
	Additions        *int         `json:"additions,omitempty"`
	Deletions        *int         `json:"deletions,omitempty"`
	Changes          *int         `json:"changes,omitempty"`
	Status           *string      `json:"status,omitempty"`
	Patch            *CommitPatch `json:"patch,omitempty"`
	BlobURL          *string      `json:"blob_url,omitempty"`
	RawURL           *string      `json:"raw_url,omitempty"`
	ContentsURL      *string      `json:"contents_url,omitempty"`
	PreviousFilename *string      `json:"previous_filename,omitempty"`
}

type CommitPatch added in v0.2.0

type CommitPatch struct {
	Diff        *string `json:"diff,omitempty"`
	OldPath     *string `json:"old_path,omitempty"`
	NewPath     *string `json:"new_path,omitempty"`
	NewFile     *bool   `json:"new_file,omitempty"`
	RenamedFile *bool   `json:"renamed_file,omitempty"`
	DeletedFile *bool   `json:"deleted_file,omitempty"`
	TooLarge    *bool   `json:"too_large,omitempty"`
}

type Dataset

type Dataset struct {
	StatusCode int       `json:"code"`
	Message    string    `json:"msg"`
	Data       []SigInfo `json:"data"`
}

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"`
	// 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 PRComment added in v0.2.0

type PRComment struct {
	ID   string
	Body string
}

type PRCommit added in v0.2.0

type PRCommit struct {
	AuthorName     string
	AuthorEmail    string
	CommitterName  string
	CommitterEmail string
}

type PullRequestOperationLog added in v0.2.0

type PullRequestOperationLog struct {
	CreatedAt time.Time `json:"created_at,omitempty"`
	Content   string    `json:"content,omitempty"`
	Action    string    `json:"action,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	UserName  string    `json:"username,omitempty"`
}

type RepoContent added in v0.2.0

type RepoContent struct {
	Type            *string `json:"type,omitempty"`
	Target          *string `json:"target,omitempty"`
	Encoding        *string `json:"encoding,omitempty"`
	Size            *int64  `json:"size,omitempty"`
	Name            *string `json:"name,omitempty"`
	Path            *string `json:"path,omitempty"`
	Content         *string `json:"content,omitempty"`
	SHA             *string `json:"sha,omitempty"`
	URL             *string `json:"url,omitempty"`
	HTMLURL         *string `json:"html_url,omitempty"`
	DownloadURL     *string `json:"download_url,omitempty"`
	SubmoduleGitURL *string `json:"submodule_git_url,omitempty"`
}

type Repository

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

type RepositoryInfo

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

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:"repository_list,omitempty"`
	RepositoryInfo []*RepositoryInfo `yaml:"repository_info,omitempty"`
}

type User added in v0.2.0

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

Jump to

Keyboard shortcuts

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