Help us shape the future of Go! Take the 2026 Go Developer Survey

gitea

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPayload

func HashPayload(secret string, payloadBody []byte) string

HashPayload hashes the payload

func IsValidPayload

func IsValidPayload(secret, headerHash string, payload []byte) bool

IsValidPayload validates the webhook payload

func Validate

func Validate(secret, headerHash string, payload []byte) error

Validate validates the webhook payload

Types

type BranchResponse

type BranchResponse struct {
	Name   string `json:"name"`
	Commit struct {
		Sha string `json:"sha"`
	} `json:"commit"`
}

BranchResponse is a respond struct for branch request

type Client

type Client struct {
	IntegrationConfig *cicdv1.IntegrationConfig
	K8sClient         client.Client
	// contains filtered or unexported fields
}

Client is a gitea client struct

func (*Client) CanUserWriteToRepo

func (c *Client) CanUserWriteToRepo(user git.User) (bool, error)

CanUserWriteToRepo decides if the user has write permission on the repo

func (*Client) DeleteLabel

func (c *Client) DeleteLabel(_ git.IssueType, id int, label string) error

DeleteLabel deletes label from the issue id

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(id int) error

DeleteWebhook deletes registered webhook

func (*Client) GetBranch

func (c *Client) GetBranch(branch string) (*git.Branch, error)

GetBranch gets branch info

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(id int) (*git.PullRequest, error)

GetPullRequest gets PR given id

func (*Client) GetPullRequestDiff

func (c *Client) GetPullRequestDiff(id int) (*git.Diff, error)

GetPullRequestDiff gets diff of the pull request

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(userName string) (*git.User, error)

GetUserInfo gets a user's information

func (*Client) Init

func (c *Client) Init() error

Init initiates the Client

func (*Client) ListComments

func (c *Client) ListComments(issueNo int) ([]git.IssueComment, error)

ListComments lists comments of the issue id

func (*Client) ListCommitStatuses

func (c *Client) ListCommitStatuses(ref string) ([]git.CommitStatus, error)

ListCommitStatuses lists commit status of the specific commit

func (*Client) ListLabels

func (c *Client) ListLabels(id int) ([]git.IssueLabel, error)

ListLabels lists labels of pr id

func (*Client) ListPullRequestCommits

func (c *Client) ListPullRequestCommits(id int) ([]git.Commit, error)

ListPullRequestCommits lists commits list of a pull request

func (*Client) ListPullRequests

func (c *Client) ListPullRequests(onlyOpen bool) ([]git.PullRequest, error)

ListPullRequests gets pull request list

func (*Client) ListWebhook

func (c *Client) ListWebhook() ([]git.WebhookEntry, error)

ListWebhook lists registered webhooks

func (*Client) MergePullRequest

func (c *Client) MergePullRequest(id int, sha string, method git.MergeMethod, message string) error

MergePullRequest merges a pull request

func (*Client) ParseWebhook

func (c *Client) ParseWebhook(header http.Header, jsonString []byte) (*git.Webhook, error)

ParseWebhook parses a webhook body for gitea

func (*Client) RegisterComment

func (c *Client) RegisterComment(issueType git.IssueType, issueNo int, sha, body string) error

RegisterComment registers comment to an issue

func (*Client) RegisterWebhook

func (c *Client) RegisterWebhook(url string) error

RegisterWebhook registers our webhook server to the remote git server

func (*Client) SetCommitStatus

func (c *Client) SetCommitStatus(sha string, status git.CommitStatus) error

SetCommitStatus sets commit status for the specific commit

func (*Client) SetLabel

func (c *Client) SetLabel(_ git.IssueType, id int, label string) error

SetLabel sets label to the issue id

type Comment

type Comment struct {
	Body      string       `json:"body"`
	User      User         `json:"user"`
	CreatedAt *metav1.Time `json:"created_at"`
	UpdatedAt *metav1.Time `json:"updated_at"`
	CommitId  string       `json:"commit_id"`
}

Comment is a comment payload

type CommentBody

type CommentBody struct {
	Body string `json:"body"`
}

CommentBody is a body structure for creating new comment

type CommentResponse

type CommentResponse struct {
	Body      string   `json:"body"`
	CreatedAt *v1.Time `json:"created_at"`
}

CommentResponse is a comment list response

type CommitCommentWebhook

type CommitCommentWebhook struct {
	Action  string  `json:"action"`
	Comment Comment `json:"comment"`
	Repo    Repo    `json:"repository"`
	Sender  User    `json:"sender"`
}

CommitCommentWebhook is a gitea-specific commit_comment webhook body

type CommitResponse

type CommitResponse struct {
	SHA    string `json:"sha"`
	Commit struct {
		Message string `json:"message"`
		Author  struct {
			Name  string `json:"name"`
			Email string `json:"email"`
		} `json:"author"`
		Committer struct {
			Name  string `json:"name"`
			Email string `json:"email"`
		} `json:"committer"`
	} `json:"commit"`
}

CommitResponse is a commits list response

type CommitStatusRequest

type CommitStatusRequest struct {
	State       string `json:"state"`
	TargetURL   string `json:"target_url"`
	Description string `json:"description"`
	Context     string `json:"context"`
}

CommitStatusRequest is an API body for setting commits' status

type CommitStatusResponse

type CommitStatusResponse struct {
	Context     string `json:"context"`
	State       string `json:"state"`
	Description string `json:"description"`
	TargetURL   string `json:"target_url"`
}

CommitStatusResponse is a response body of getting commit status

type DiffFile

type DiffFile struct {
	Filename     string `json:"filename"`
	PrevFilename string `json:"previous_filename"`
	Additions    int    `json:"additions"`
	Deletions    int    `json:"deletions"`
	Changes      int    `json:"changes"`
}

DiffFile is a

type DiffFiles

type DiffFiles []DiffFile

DiffFiles is a list of DiffFile

type HookType

type HookType string
const (
	// HookTypeDingtalk webhook that dingtalk understand
	HookTypeDingtalk HookType = "dingtalk"
	// HookTypeDiscord webhook that discord understand
	HookTypeDiscord HookType = "discord"
	// HookTypeGitea webhook that gitea understand
	HookTypeGitea HookType = "gitea"
	// HookTypeGogs webhook that gogs understand
	HookTypeGogs HookType = "gogs"
	// HookTypeMsteams webhook that msteams understand
	HookTypeMsteams HookType = "msteams"
	// HookTypeSlack webhook that slack understand
	HookTypeSlack HookType = "slack"
	// HookTypeTelegram webhook that telegram understand
	HookTypeTelegram HookType = "telegram"
	// HookTypeFeishu webhook that feishu understand
	HookTypeFeishu HookType = "feishu"
)

type IssueCommentWebhook

type IssueCommentWebhook struct {
	Action  string  `json:"action"`
	Comment Comment `json:"comment"`
	Issue   struct {
		PullRequest struct {
			URL string `json:"url"`
		} `json:"pull_request"`
	} `json:"issue"`
	Repo   Repo `json:"repository"`
	Sender User `json:"sender"`
}

IssueCommentWebhook is a gitea-specific issue_comment webhook body

type LabelBody

type LabelBody struct {
	Name string `json:"name"`
}

LabelBody is a body structure for setting a label to issues/prs

type MergeRequest

type MergeRequest struct {
	CommitTitle   string `json:"commit_title,omitempty"`
	CommitMessage string `json:"commit_message,omitempty"`
	MergeMethod   string `json:"merge_method"`
	Sha           string `json:"sha"`
}

MergeRequest is a request struct to merge a pull request

type PullRequest

type PullRequest struct {
	Title     string `json:"title"`
	Number    int    `json:"number"`
	State     string `json:"state"`
	URL       string `json:"html_url"`
	Mergeable bool   `json:"mergeable"`
	User      User   `json:"user"`
	Draft     bool   `json:"draft"`
	Head      struct {
		Ref string `json:"ref"`
		Sha string `json:"sha"`
	} `json:"head"`
	Base struct {
		Ref string `json:"ref"`
		Sha string `json:"sha"`
	} `json:"base"`
	Labels []struct {
		Name string `json:"name"`
	} `json:"labels"`
}

PullRequest is a pull request info

type PullRequestReviewCommentWebhook

type PullRequestReviewCommentWebhook struct {
	Action      string      `json:"action"`
	Comment     Comment     `json:"comment"`
	PullRequest PullRequest `json:"pull_request"`
	Repo        Repo        `json:"repository"`
	Sender      User        `json:"sender"`
}

PullRequestReviewCommentWebhook is a gitea-specific pull_request_review_comment webhook body

type PullRequestReviewWebhook

type PullRequestReviewWebhook struct {
	Action string `json:"action"`
	Review struct {
		Body        string       `json:"body"`
		SubmittedAt *metav1.Time `json:"submitted_at"`
		State       string       `json:"state"`
		User        User         `json:"user"`
	} `json:"review"`
	PullRequest PullRequest `json:"pull_request"`
	Repo        Repo        `json:"repository"`
	Sender      User        `json:"sender"`
}

PullRequestReviewWebhook is a gitea-specific pull_request_review webhook body

type PullRequestWebhook

type PullRequestWebhook struct {
	Action string `json:"action"`
	Number int    `json:"number"`
	Sender User   `json:"sender"`

	PullRequest PullRequest `json:"pull_request"`

	Repo Repo `json:"repository"`

	// Changed label
	Label LabelBody `json:"label"`
}

PullRequestWebhook is a gitea-specific pull-request event webhook body

type PushWebhook

type PushWebhook struct {
	Ref    string `json:"ref"`
	Repo   Repo   `json:"repository"`
	Sender User   `json:"sender"`
	Sha    string `json:"after"`
}

PushWebhook is a gitea-specific push event webhook body

type RegistrationWebhookBody

type RegistrationWebhookBody struct {
	Type         HookType                      `json:"type"`
	Config       RegistrationWebhookBodyConfig `json:"config"`
	Events       []string                      `json:"events"`
	BranchFilter string                        `json:"branch_filter"`
	Active       bool                          `json:"active"`
}

RegistrationWebhookBody is a request body for registering webhook to remote git server

type RegistrationWebhookBodyConfig

type RegistrationWebhookBodyConfig struct {
	URL         string `json:"url"`
	ContentType string `json:"content_type"`
	InsecureSsl string `json:"insecure_ssl"`
	Secret      string `json:"secret"`
}

RegistrationWebhookBodyConfig is a config for the webhook

type Repo

type Repo struct {
	Name  string `json:"full_name"`
	URL   string `json:"html_url"`
	Owner struct {
		ID string `json:"login"`
	} `json:"owner"`
	Private bool `json:"private"`
}

Repo structure for webhook event

type ReviewResponse

type ReviewResponse struct {
	Body        string                     `json:"body"`
	SubmittedAt *v1.Time                   `json:"submitted_at"`
	State       git.PullRequestReviewState `json:"state"`
}

ReviewResponse is a review list response

type User

type User struct {
	Name string `json:"login"`
	ID   int    `json:"id"`
}

User is a sender of the event

type UserInfo

type UserInfo struct {
	ID       int    `json:"id"`
	UserName string `json:"login"`
	Email    string `json:"email"`
}

UserInfo is a body of user get API

type UserPermission

type UserPermission struct {
	Permission string `json:"permission"`
}

UserPermission is a user's permission on a repository

type WebhookEntry

type WebhookEntry struct {
	ID     int `json:"id"`
	Config struct {
		URL string `json:"url"`
	} `json:"config"`
}

WebhookEntry is a body of list of registered webhooks

Jump to

Keyboard shortcuts

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