tencentcode

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package tencentcode implements the Tencent 工蜂 Provider for the git-platform-sdk.

Tencent 工蜂 exposes a GitLab-compatible REST API with some platform- specific extensions (native code reviews, branch protection, repository tree/blob). This package implements the cross-platform provider.Provider interface and additionally exposes a TencentCodeExtras interface for the platform-specific capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New builds a Tencent Code Provider from the given config.

Types

type CodeReview

type CodeReview struct {
	ID           int              `json:"id"`
	IID          int              `json:"iid"`
	ProjectID    int              `json:"project_id"`
	Title        string           `json:"title"`
	Description  string           `json:"description"`
	State        string           `json:"state"`
	SourceBranch string           `json:"source_branch"`
	TargetBranch string           `json:"target_branch"`
	SourceCommit string           `json:"source_commit"`
	TargetCommit string           `json:"target_commit"`
	Author       *provider.CRUser `json:"author"`
	Reviewers    []string         `json:"reviewers"`
	WebURL       string           `json:"web_url"`
	CreatedAt    string           `json:"created_at"`
	UpdatedAt    string           `json:"updated_at"`
}

CodeReview represents a Tencent 工蜂 native code review.

type CommitComment

type CommitComment struct {
	ID        int              `json:"id"`
	Body      string           `json:"body"`
	Author    *provider.CRUser `json:"author"`
	Path      string           `json:"path"`
	Line      int              `json:"line"`
	LineType  string           `json:"line_type"`
	CreatedAt string           `json:"created_at"`
}

CommitComment represents a comment on a commit.

type CommitDiffOptions

type CommitDiffOptions struct {
	Path             string
	IgnoreWhiteSpace bool
}

CommitDiffOptions controls a single-commit diff.

type CommitRefType

type CommitRefType string

CommitRefType selects which refs to return for a commit.

const (
	CommitRefAll    CommitRefType = "all"
	CommitRefBranch CommitRefType = "branch"
	CommitRefTag    CommitRefType = "tag"
)

type CommitRefs

type CommitRefs struct {
	Branches []string `json:"branches"`
	Tags     []string `json:"tags"`
}

CommitRefs lists branches and tags containing a commit.

type CreateCodeReviewOptions

type CreateCodeReviewOptions struct {
	Title                 string
	SourceBranch          string
	TargetBranch          string
	SourceCommit          string
	TargetCommit          string
	Description           string
	ReviewerIDs           string // comma-separated reviewer user IDs
	NecessaryReviewerIDs  string // comma-separated necessary reviewer user IDs
	ApproverRule          int    // -1 = all approve, 1 = single, 2+ = N approve
	NecessaryApproverRule int
}

CreateCodeReviewOptions creates a native code review.

type CreateCommitCommentOptions

type CreateCommitCommentOptions struct {
	Note     string
	Path     string
	Line     int
	LineType string // "old" or "new"
}

CreateCommitCommentOptions creates a comment on a commit.

type InviteReviewerOptions

type InviteReviewerOptions struct {
	ReviewerID          string // comma-separated user IDs (code review)
	NecessaryReviewerID string // comma-separated necessary user IDs (code review)
}

InviteReviewerOptions invites one or more reviewers.

type ListCodeReviewsOptions

type ListCodeReviewsOptions struct {
	State    string // approving, change_required, closed
	AuthorID int
	OrderBy  string // created_at, updated_at
	Sort     string // asc, desc
	Page     int
	PerPage  int
}

ListCodeReviewsOptions filters the code review list.

type MRReview

type MRReview struct {
	ID           int              `json:"id"`
	IID          int              `json:"iid"`
	ProjectID    int              `json:"project_id"`
	State        string           `json:"state"`
	Title        string           `json:"title"`
	Description  string           `json:"description"`
	Author       *provider.CRUser `json:"author"`
	SourceBranch string           `json:"source_branch"`
	TargetBranch string           `json:"target_branch"`
	WebURL       string           `json:"web_url"`
	CreatedAt    string           `json:"created_at"`
	UpdatedAt    string           `json:"updated_at"`
}

MRReview represents the review state of a merge request.

type ProtectBranchOptions

type ProtectBranchOptions struct {
	MergeAccessLevel          int  `json:"merge_access_level,omitempty"`
	PushAccessLevel           int  `json:"push_access_level,omitempty"`
	AllowForcePush            bool `json:"allow_force_push,omitempty"`
	CodeOwnerApprovalRequired bool `json:"code_owner_approval_required,omitempty"`
}

ProtectBranchOptions configures branch protection rules on Tencent Code (工蜂).

type ProtectedBranchMember

type ProtectedBranchMember struct {
	UserID      int    `json:"user_id"`
	Username    string `json:"username"`
	Name        string `json:"name"`
	AccessLevel int    `json:"access_level"`
}

ProtectedBranchMember represents a member granted access to a protected branch.

type ProtectedBranchMemberOptions

type ProtectedBranchMemberOptions struct {
	UserID      int
	AccessLevel int
}

ProtectedBranchMemberOptions adds/updates a protected branch member.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is the Tencent 工蜂 implementation of provider.Provider.

func (*Provider) AddProtectedBranchMember

func (t *Provider) AddProtectedBranchMember(ctx context.Context, owner, repo, branch string, opts ProtectedBranchMemberOptions) error

func (*Provider) CancelMRReview

func (t *Provider) CancelMRReview(ctx context.Context, owner, repo string, mrNumber int) error

func (*Provider) Capabilities added in v0.38.0

func (p *Provider) Capabilities() provider.CapabilitySet

Capabilities implements provider.Provider. This backend does not yet implement any optional capability interface; flip fields here as capability backends land.

func (*Provider) CloseCR

func (p *Provider) CloseCR(ctx context.Context, owner, repo string, number int) (*provider.ChangeRequest, error)

CloseCR implements provider.ChangeRequestManager.

func (*Provider) CompareCommits

func (p *Provider) CompareCommits(ctx context.Context, owner, repo, base, head string) (*provider.CompareResult, error)

CompareCommits implements provider.CommitManager.

func (*Provider) CreateBranch

func (p *Provider) CreateBranch(ctx context.Context, owner, repo, branch, ref string) (*provider.PlatformBranch, error)

CreateBranch implements provider.BranchManager.

func (*Provider) CreateCR

CreateCR implements provider.ChangeRequestManager.

func (*Provider) CreateCodeReview

func (t *Provider) CreateCodeReview(ctx context.Context, owner, repo string, opts CreateCodeReviewOptions) (*CodeReview, error)

func (*Provider) CreateCommitComment

func (t *Provider) CreateCommitComment(ctx context.Context, owner, repo, sha string, opts CreateCommitCommentOptions) (*CommitComment, error)

func (*Provider) CreateCommitStatus

func (p *Provider) CreateCommitStatus(ctx context.Context, owner, repo, sha string, opts provider.CommitStatusOptions) error

CreateCommitStatus implements provider.CommitManager.

func (*Provider) CreateDiscussion

func (p *Provider) CreateDiscussion(ctx context.Context, owner, repo string, number int, opts provider.DiscussionOptions) (string, error)

CreateDiscussion implements provider.DiffManager. The gongfeng SDK does not expose a discussions endpoint, so we use the SDK client's NewRequest/Do for a raw API call.

func (*Provider) CreateFile

func (p *Provider) CreateFile(ctx context.Context, owner, repo string, opts provider.FileOptions) (*provider.FileResult, error)

CreateFile implements provider.FileManager.

func (*Provider) CreateNote

func (p *Provider) CreateNote(ctx context.Context, owner, repo string, number int, body string) (string, error)

CreateNote implements provider.DiffManager.

func (*Provider) CreateRelease

func (p *Provider) CreateRelease(ctx context.Context, owner, repo string, opts provider.CreateReleaseOptions) (*provider.ReleaseInfo, error)

CreateRelease implements provider.ReleaseManager.

func (*Provider) CreateRepo

func (p *Provider) CreateRepo(ctx context.Context, owner string, opts provider.CreateRepoOptions) (*provider.PlatformRepo, error)

CreateRepo implements provider.RepoManager.

func (*Provider) CreateWebhook

CreateWebhook implements provider.WebhookManager.

func (*Provider) DeleteBranch

func (p *Provider) DeleteBranch(ctx context.Context, owner, repo, branch string) error

DeleteBranch implements provider.BranchManager.

func (*Provider) DeleteFile

func (p *Provider) DeleteFile(ctx context.Context, owner, repo string, opts provider.FileDeleteOptions) (*provider.FileResult, error)

DeleteFile implements provider.FileManager.

func (*Provider) DeleteNote

func (p *Provider) DeleteNote(ctx context.Context, owner, repo string, number int, noteID string) error

DeleteNote implements provider.DiffManager. The gongfeng SDK does not expose a delete-note endpoint, so we use the SDK client's NewRequest/Do for a raw API call.

func (*Provider) DeleteRelease added in v0.40.0

func (p *Provider) DeleteRelease(ctx context.Context, owner, repo, tag string) error

DeleteRelease implements provider.ReleaseManager via Gongfeng's tag-addressed delete.

func (*Provider) DeleteRepo

func (p *Provider) DeleteRepo(ctx context.Context, owner, repo string) error

DeleteRepo implements provider.RepoManager.

func (*Provider) DeleteWebhook

func (p *Provider) DeleteWebhook(ctx context.Context, owner, repo string, webhookID int64) error

DeleteWebhook implements provider.WebhookManager.

func (*Provider) ForkRepo

func (p *Provider) ForkRepo(ctx context.Context, owner, repo string, opts provider.ForkRepoOptions) (*provider.PlatformRepo, error)

ForkRepo implements provider.RepoManager.

func (*Provider) GetArchive

func (p *Provider) GetArchive(ctx context.Context, owner, repo, ref, format string) ([]byte, error)

GetArchive implements provider.ReleaseManager.

func (*Provider) GetBlob

func (t *Provider) GetBlob(ctx context.Context, owner, repo, sha string) ([]byte, error)

func (*Provider) GetCR

func (p *Provider) GetCR(ctx context.Context, owner, repo string, number int) (*provider.ChangeRequest, error)

GetCR implements provider.ChangeRequestManager.

func (*Provider) GetCRDiff

func (p *Provider) GetCRDiff(ctx context.Context, owner, repo string, number int) (*provider.MergeDiff, error)

GetCRDiff implements provider.DiffManager.

func (*Provider) GetCRFiles

func (p *Provider) GetCRFiles(ctx context.Context, owner, repo string, number int) ([]*provider.ChangedFile, error)

GetCRFiles implements provider.DiffManager.

func (*Provider) GetCodeReview

func (t *Provider) GetCodeReview(ctx context.Context, owner, repo string, reviewID int) (*CodeReview, error)

func (*Provider) GetCodeReviewChangedFiles

func (t *Provider) GetCodeReviewChangedFiles(ctx context.Context, owner, repo string, reviewID int) ([]*provider.ChangedFile, error)

func (*Provider) GetCommit

func (p *Provider) GetCommit(ctx context.Context, owner, repo, sha string) (*provider.CommitInfo, error)

GetCommit implements provider.CommitManager.

func (*Provider) GetCommitDiff

func (t *Provider) GetCommitDiff(ctx context.Context, owner, repo, sha string, opts CommitDiffOptions) ([]*provider.ChangedFile, error)

func (*Provider) GetCommitRefs

func (t *Provider) GetCommitRefs(ctx context.Context, owner, repo, sha string, refType CommitRefType) (*CommitRefs, error)

func (*Provider) GetFileContent

func (p *Provider) GetFileContent(ctx context.Context, owner, repo, path, ref string) (string, error)

GetFileContent implements provider.FileManager.

func (*Provider) GetMRReview

func (t *Provider) GetMRReview(ctx context.Context, owner, repo string, mrNumber int) (*MRReview, error)

func (*Provider) GetReleaseByTag added in v0.40.0

func (p *Provider) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*provider.ReleaseInfo, error)

GetReleaseByTag implements provider.ReleaseManager. Gongfeng's release endpoints are tag-addressed natively.

func (*Provider) GetRepo

func (p *Provider) GetRepo(ctx context.Context, owner, repo string) (*provider.PlatformRepo, error)

GetRepo implements provider.RepoManager.

func (*Provider) GetRepoTree

func (t *Provider) GetRepoTree(ctx context.Context, owner, repo, path, ref string, recursive bool) ([]*TreeEntryNode, error)

func (*Provider) InviteCodeReviewer

func (t *Provider) InviteCodeReviewer(ctx context.Context, owner, repo string, reviewID int, opts InviteReviewerOptions) error

func (*Provider) InviteMRReviewer

func (t *Provider) InviteMRReviewer(ctx context.Context, owner, repo string, mrNumber int, opts InviteReviewerOptions) error

func (*Provider) ListBranches

func (p *Provider) ListBranches(ctx context.Context, owner, repo string) ([]*provider.PlatformBranch, error)

ListBranches implements provider.BranchManager.

func (*Provider) ListCRComments

func (p *Provider) ListCRComments(ctx context.Context, owner, repo string, number int) ([]*provider.CRComment, error)

ListCRComments implements provider.ChangeRequestManager.

func (*Provider) ListCRCommits

func (p *Provider) ListCRCommits(ctx context.Context, owner, repo string, number int) ([]*provider.CRCommit, error)

ListCRCommits implements provider.ChangeRequestManager.

func (*Provider) ListCRs

ListCRs implements provider.ChangeRequestManager.

func (*Provider) ListCodeReviews

func (t *Provider) ListCodeReviews(ctx context.Context, owner, repo string, opts ListCodeReviewsOptions) ([]*CodeReview, error)

func (*Provider) ListCommitComments

func (t *Provider) ListCommitComments(ctx context.Context, owner, repo, sha string, page, perPage int) ([]*CommitComment, error)

func (*Provider) ListCommits

func (p *Provider) ListCommits(ctx context.Context, owner, repo string, opts provider.ListCommitsOptions) ([]*provider.CommitInfo, error)

ListCommits implements provider.CommitManager.

func (*Provider) ListProtectedBranchMembers

func (t *Provider) ListProtectedBranchMembers(ctx context.Context, owner, repo, branch string) ([]*ProtectedBranchMember, error)

func (*Provider) ListReleases

func (p *Provider) ListReleases(ctx context.Context, owner, repo string) ([]*provider.ReleaseInfo, error)

ListReleases implements provider.ReleaseManager.

func (*Provider) ListRepos

ListRepos implements provider.RepoManager.

func (*Provider) ListTags

func (p *Provider) ListTags(ctx context.Context, owner, repo string) ([]*provider.TagInfo, error)

ListTags implements provider.ReleaseManager.

func (*Provider) ListWebhooks

func (p *Provider) ListWebhooks(ctx context.Context, owner, repo string) ([]*provider.PlatformWebhook, error)

ListWebhooks implements provider.WebhookManager.

func (*Provider) MergeCR

func (p *Provider) MergeCR(ctx context.Context, owner, repo string, number int, opts provider.MergeCROptions) (*provider.ChangeRequest, error)

MergeCR implements provider.ChangeRequestManager.

func (*Provider) ParseWebhookEvent

func (p *Provider) ParseWebhookEvent(r *http.Request, secret string) (*provider.NormalizedEvent, error)

ParseWebhookEvent implements provider.WebhookManager.

func (*Provider) Platform

func (p *Provider) Platform() provider.Platform

Platform implements provider.Provider.

func (*Provider) ProtectBranch

func (t *Provider) ProtectBranch(ctx context.Context, owner, repo, branch string, opts ProtectBranchOptions) error

func (*Provider) RemoveCodeReviewer

func (t *Provider) RemoveCodeReviewer(ctx context.Context, owner, repo string, reviewID int, reviewerID string) error

func (*Provider) RemoveMRReviewer

func (t *Provider) RemoveMRReviewer(ctx context.Context, owner, repo string, mrNumber int, reviewerID int) error

func (*Provider) RemoveProtectedBranchMember

func (t *Provider) RemoveProtectedBranchMember(ctx context.Context, owner, repo, branch string, userID int) error

func (*Provider) ReopenCR

func (p *Provider) ReopenCR(ctx context.Context, owner, repo string, number int) (*provider.ChangeRequest, error)

ReopenCR implements provider.ChangeRequestManager.

func (*Provider) ReopenCodeReview

func (t *Provider) ReopenCodeReview(ctx context.Context, owner, repo string, reviewID int) error

func (*Provider) ReopenMRReview

func (t *Provider) ReopenMRReview(ctx context.Context, owner, repo string, mrNumber int) error

func (*Provider) SubmitCodeReview

func (t *Provider) SubmitCodeReview(ctx context.Context, owner, repo string, reviewID int, opts SubmitReviewOptions) error

func (*Provider) SubmitMRReview

func (t *Provider) SubmitMRReview(ctx context.Context, owner, repo string, mrNumber int, opts SubmitReviewOptions) error

func (*Provider) TestConnection

func (p *Provider) TestConnection(ctx context.Context) (*provider.TestConnectionResult, error)

TestConnection implements provider.Provider.

func (*Provider) UnprotectBranch

func (t *Provider) UnprotectBranch(ctx context.Context, owner, repo, branch string) error

func (*Provider) UpdateCR

func (p *Provider) UpdateCR(ctx context.Context, owner, repo string, number int, opts provider.UpdateCROptions) (*provider.ChangeRequest, error)

UpdateCR implements provider.ChangeRequestManager.

func (*Provider) UpdateCRLabels

func (p *Provider) UpdateCRLabels(ctx context.Context, owner, repo string, number int, labels []string) error

UpdateCRLabels implements provider.ChangeRequestManager.

Tencent Code's API no longer supports setting labels via UpdateMergeRequest.

func (*Provider) UpdateCodeReview

func (t *Provider) UpdateCodeReview(ctx context.Context, owner, repo string, reviewID int, opts UpdateCodeReviewOptions) (*CodeReview, error)

func (*Provider) UpdateFile

func (p *Provider) UpdateFile(ctx context.Context, owner, repo string, opts provider.FileOptions) (*provider.FileResult, error)

UpdateFile implements provider.FileManager.

func (*Provider) UpdateProtectedBranchMember

func (t *Provider) UpdateProtectedBranchMember(ctx context.Context, owner, repo, branch string, userID int, opts ProtectedBranchMemberOptions) error

func (*Provider) UpdateRelease added in v0.40.0

func (p *Provider) UpdateRelease(ctx context.Context, owner, repo, tag string, opts provider.UpdateReleaseOptions) (*provider.ReleaseInfo, error)

UpdateRelease implements provider.ReleaseManager via Gongfeng's tag-addressed update (PUT). Registration: the platform's update surface accepts only a description, so UpdateReleaseOptions.Name, .Draft, and .Prerelease are ignored on this platform — only Body is carried.

func (*Provider) UpdateRepo

func (p *Provider) UpdateRepo(ctx context.Context, owner, repo string, opts provider.UpdateRepoOptions) (*provider.PlatformRepo, error)

UpdateRepo implements provider.RepoManager.

func (*Provider) ValidateWebhookSignature

func (p *Provider) ValidateWebhookSignature(r *http.Request, secret string) error

ValidateWebhookSignature implements provider.WebhookManager. Tencent 工蜂 uses a static token comparison against the X-Token header.

type ReviewerEvent

type ReviewerEvent string

ReviewerEvent is the verdict a reviewer submits for a code review or MR review.

const (
	ReviewEventComment       ReviewerEvent = "comment"
	ReviewEventApprove       ReviewerEvent = "approve"
	ReviewEventRequireChange ReviewerEvent = "require_change"
	ReviewEventDeny          ReviewerEvent = "deny"
)

type SubmitReviewOptions

type SubmitReviewOptions struct {
	Event   ReviewerEvent
	Summary string
}

SubmitReviewOptions submits a reviewer verdict with a summary.

type TencentCodeExtras

type TencentCodeExtras interface {
	// --- Native code review (/review) ---
	CreateCodeReview(ctx context.Context, owner, repo string, opts CreateCodeReviewOptions) (*CodeReview, error)
	ListCodeReviews(ctx context.Context, owner, repo string, opts ListCodeReviewsOptions) ([]*CodeReview, error)
	GetCodeReview(ctx context.Context, owner, repo string, reviewID int) (*CodeReview, error)
	UpdateCodeReview(ctx context.Context, owner, repo string, reviewID int, opts UpdateCodeReviewOptions) (*CodeReview, error)
	InviteCodeReviewer(ctx context.Context, owner, repo string, reviewID int, opts InviteReviewerOptions) error
	RemoveCodeReviewer(ctx context.Context, owner, repo string, reviewID int, reviewerID string) error
	SubmitCodeReview(ctx context.Context, owner, repo string, reviewID int, opts SubmitReviewOptions) error
	ReopenCodeReview(ctx context.Context, owner, repo string, reviewID int) error
	GetCodeReviewChangedFiles(ctx context.Context, owner, repo string, reviewID int) ([]*provider.ChangedFile, error)

	// --- MR review workflow (/merge_request/{iid}/review*) ---
	GetMRReview(ctx context.Context, owner, repo string, mrNumber int) (*MRReview, error)
	InviteMRReviewer(ctx context.Context, owner, repo string, mrNumber int, opts InviteReviewerOptions) error
	RemoveMRReviewer(ctx context.Context, owner, repo string, mrNumber int, reviewerID int) error
	CancelMRReview(ctx context.Context, owner, repo string, mrNumber int) error
	SubmitMRReview(ctx context.Context, owner, repo string, mrNumber int, opts SubmitReviewOptions) error
	ReopenMRReview(ctx context.Context, owner, repo string, mrNumber int) error

	// --- Commit-level ops (/repository/commits/{sha}) ---
	GetCommitDiff(ctx context.Context, owner, repo, sha string, opts CommitDiffOptions) ([]*provider.ChangedFile, error)
	ListCommitComments(ctx context.Context, owner, repo, sha string, page, perPage int) ([]*CommitComment, error)
	CreateCommitComment(ctx context.Context, owner, repo, sha string, opts CreateCommitCommentOptions) (*CommitComment, error)
	GetCommitRefs(ctx context.Context, owner, repo, sha string, refType CommitRefType) (*CommitRefs, error)

	// --- Repository tree & blob ---
	GetRepoTree(ctx context.Context, owner, repo, path, ref string, recursive bool) ([]*TreeEntryNode, error)
	GetBlob(ctx context.Context, owner, repo, sha string) ([]byte, error)

	// --- Branch protection ---
	ProtectBranch(ctx context.Context, owner, repo, branch string, opts ProtectBranchOptions) error
	UnprotectBranch(ctx context.Context, owner, repo, branch string) error
	ListProtectedBranchMembers(ctx context.Context, owner, repo, branch string) ([]*ProtectedBranchMember, error)
	AddProtectedBranchMember(ctx context.Context, owner, repo, branch string, opts ProtectedBranchMemberOptions) error
	UpdateProtectedBranchMember(ctx context.Context, owner, repo, branch string, userID int, opts ProtectedBranchMemberOptions) error
	RemoveProtectedBranchMember(ctx context.Context, owner, repo, branch string, userID int) error
}

TencentCodeExtras exposes Tencent 工蜂-specific capabilities that are not part of the cross-platform Provider interface (native code reviews, MR review workflow, commit-level comments/diff, repository tree/blob and branch protection). Obtain it via type assertion:

p, _ := provider.NewProvider(provider.Config{Platform: provider.PlatformTencentCode, Token: t})
if tc, ok := p.(provider.TencentCodeExtras); ok {
    tc.SubmitCodeReview(ctx, owner, repo, reviewID, opts)
}

type TreeEntryNode

type TreeEntryNode struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"` // "tree" or "blob"
	Mode string `json:"mode"`
	Path string `json:"path"`
}

TreeEntryNode represents a single entry in a repository tree listing.

type UpdateCodeReviewOptions

type UpdateCodeReviewOptions struct {
	Title       string
	Description string
}

UpdateCodeReviewOptions updates a code review's title/description.

Jump to

Keyboard shortcuts

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