Documentation
¶
Index ¶
- type AzureReposExtra
- type BitbucketExtra
- type Comment
- type CommentHandler
- func NewAzureReposPRHandler(ctx context.Context, repoURL string, targetRef string, extra AzureReposExtra) (*CommentHandler, error)
- func NewBitbucketCommitHandler(ctx context.Context, repo string, targetRef string, extra BitbucketExtra) (*CommentHandler, error)
- func NewBitbucketPRHandler(ctx context.Context, repo string, targetRef string, extra BitbucketExtra) (*CommentHandler, error)
- func NewCommentHandler(ctx context.Context, platformHandler PlatformHandler, tag string) *CommentHandler
- func NewGitHubCommitHandler(ctx context.Context, project, targetRef string, extra GitHubExtra) (*CommentHandler, error)
- func NewGitHubPRHandler(ctx context.Context, project, targetRef string, extra GitHubExtra) (*CommentHandler, error)
- func NewGitLabCommitHandler(ctx context.Context, project string, targetRef string, extra GitLabExtra) (*CommentHandler, error)
- func NewGitLabPRHandler(ctx context.Context, project string, targetRef string, extra GitLabExtra) (*CommentHandler, error)
- func (h *CommentHandler) CommentWithBehavior(ctx context.Context, behavior, body string, opts *CommentOpts) (PostResult, error)
- func (h *CommentHandler) DeleteAndNewComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
- func (h *CommentHandler) HideAndNewComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
- func (h *CommentHandler) NewComment(ctx context.Context, body string, opts *CommentOpts) error
- func (h *CommentHandler) UpdateComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
- type CommentOpts
- type CommentTag
- type GitHubExtra
- type GitLabExtra
- type PlatformHandler
- type PostResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AzureReposExtra ¶
type AzureReposExtra struct {
// Token is the Azure DevOps access token.
Token string
// Tag is used to identify the C3X comment.
Tag string
InitActive bool
// TLSConfig is the TLS configuration to use when connecting to the Azure Repos API.
TLSConfig *tls.Config
}
AzureReposExtra contains any extra inputs that can be passed to the Azure Repos comment handlers.
type BitbucketExtra ¶
type BitbucketExtra struct {
// ServerURL is the URL of the Bitbucket server. This can be set to a custom URL if
// using Bitbucket Server/Data Center. If not set, the default Bitbucket server URL will be used.
ServerURL string
// OmitDetails is used to specify a format that excludes details output.
OmitDetails bool
// Tag is used to identify the C3X comment.
Tag string
// Token is the Bitbucket access token.
Token string
// TLSConfig is the TLS configuration to use when connecting to the Bitbucket API.
TLSConfig *tls.Config
}
BitbucketExtra contains any extra inputs that can be passed to the Bitbucket comment handlers.
type Comment ¶
type Comment interface {
// Body returns the body of the comment.
Body() string
// Ref returns the reference of the comment, this can be a URL to the HTML page of the comment.
Ref() string
// Less compares the comment to another comment and returns true if this
// comment should be sorted before the other comment.
Less(c Comment) bool
// IsHidden returns true if the comment is hidden or minimized.
IsHidden() bool
// ValidAt returns the time at which the comment is valid.
// This is used to determine if a comment should be updated or not.
ValidAt() *time.Time
}
Comment is an interface that represents a comment on any platform. It wraps the platform specific comment structures and is used to abstract the logic for finding, creating, updating, and deleting the comments.
type CommentHandler ¶
type CommentHandler struct {
PlatformHandler PlatformHandler
Tag string
}
CommentHandler contains the logic for finding, creating, updating and deleting comments on any platform. It uses a PlatformHandler to call the platform-specific APIs.
func NewAzureReposPRHandler ¶
func NewAzureReposPRHandler(ctx context.Context, repoURL string, targetRef string, extra AzureReposExtra) (*CommentHandler, error)
NewAzureReposPRHandler creates a new PlatformHandler for Azure Repos pull requests.
func NewBitbucketCommitHandler ¶
func NewBitbucketCommitHandler(ctx context.Context, repo string, targetRef string, extra BitbucketExtra) (*CommentHandler, error)
NewBitbucketCommitHandler creates a new PlatformHandler for Bitbucket commits.
func NewBitbucketPRHandler ¶
func NewBitbucketPRHandler(ctx context.Context, repo string, targetRef string, extra BitbucketExtra) (*CommentHandler, error)
NewBitbucketPRHandler creates a new PlatformHandler for Bitbucket pull requests.
func NewCommentHandler ¶
func NewCommentHandler(ctx context.Context, platformHandler PlatformHandler, tag string) *CommentHandler
NewCommentHandler creates a new CommentHandler.
func NewGitHubCommitHandler ¶
func NewGitHubCommitHandler(ctx context.Context, project, targetRef string, extra GitHubExtra) (*CommentHandler, error)
NewGitHubCommitHandler creates a new PlatformHandler for GitHub commits.
func NewGitHubPRHandler ¶
func NewGitHubPRHandler(ctx context.Context, project, targetRef string, extra GitHubExtra) (*CommentHandler, error)
NewGitHubPRHandler creates a new CommentHandler for GitHub pull requests.
func NewGitLabCommitHandler ¶
func NewGitLabCommitHandler(ctx context.Context, project string, targetRef string, extra GitLabExtra) (*CommentHandler, error)
NewGitLabCommitHandler creates a new PlatformHandler for GitLab commits.
func NewGitLabPRHandler ¶
func NewGitLabPRHandler(ctx context.Context, project string, targetRef string, extra GitLabExtra) (*CommentHandler, error)
NewGitLabPRHandler creates a new PlatformHandler for GitLab merge requests.
func (*CommentHandler) CommentWithBehavior ¶
func (h *CommentHandler) CommentWithBehavior(ctx context.Context, behavior, body string, opts *CommentOpts) (PostResult, error)
CommentWithBehavior parses the behavior and calls the corresponding *Comment method. Returns boolean indicating if the comment was actually posted.
func (*CommentHandler) DeleteAndNewComment ¶
func (h *CommentHandler) DeleteAndNewComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
DeleteAndNewComment deletes all existing matching comments and creates a new one with the given body. Returns a PostResult indicating if the comment was actually posted and the reason why it was not posted.
func (*CommentHandler) HideAndNewComment ¶
func (h *CommentHandler) HideAndNewComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
HideAndNewComment hides/minimizes all existing matching comment and creates a new one with the given body. Returns a PostResult indicating if the comment was actually posted and the reason why it was not posted.
func (*CommentHandler) NewComment ¶
func (h *CommentHandler) NewComment(ctx context.Context, body string, opts *CommentOpts) error
NewComment creates a new comment with the given body.
func (*CommentHandler) UpdateComment ¶
func (h *CommentHandler) UpdateComment(ctx context.Context, body string, opts *CommentOpts) (PostResult, error)
UpdateComment updates the comment with the given body. Returns a PostResult indicating if the comment was actually posted and the reason why it was not posted.
type CommentOpts ¶
type CommentTag ¶
type GitHubExtra ¶
type GitHubExtra struct {
// APIURL is the URL of the GitHub API. This can be set to a custom URL if
// using GitHub Enterprise. If not set, the default GitHub API URL will be used.
APIURL string
// Token is the GitHub API token.
Token string
// Tag used to identify the C3X comment
Tag string
// TLSConfig is the TLS configuration to use when connecting to the GitHub API.
TLSConfig *tls.Config
}
GitHubExtra contains any extra inputs that can be passed to the GitHub comment handlers.
type GitLabExtra ¶
type GitLabExtra struct {
// ServerURL is the URL of the GitLab server. This can be set to a custom URL if
// using GitLab enterprise. If not set, the default GitLab server URL will be used.
ServerURL string
// Token is the GitLab API token.
Token string
// Tag used to identify the C3X comment
Tag string
// TLSConfig is the TLS configuration to use when connecting to the GitLab API.
TLSConfig *tls.Config
}
GitLabExtra contains any extra inputs that can be passed to the GitLab comment handlers.
type PlatformHandler ¶
type PlatformHandler interface {
// CallFindMatchingComments calls the platform-specific API to find
// comments that match the given tag, which has been embedded at the beginning
// of the comment.
CallFindMatchingComments(ctx context.Context, tag string) ([]Comment, error)
// CallCreateComment calls the platform-specific API to create a new comment.
CallCreateComment(ctx context.Context, body string) (Comment, error)
// CallUpdateComment calls the platform-specific API to update the body of a comment.
CallUpdateComment(ctx context.Context, comment Comment, body string) error
// CallDeleteComment calls the platform-specific API to delete the comment.
CallDeleteComment(ctx context.Context, comment Comment) error
// CallHideComment calls the platform-specific API to minimize the comment.
// This functionality is not supported by all platforms, in which case this
// will throw a NotImplemented error.
CallHideComment(ctx context.Context, comment Comment) error
// AddMarkdownTag adds a tag to the given string.
AddMarkdownTags(s string, tags []CommentTag) (string, error)
}
PlatformHandler is an interface that represents a platform specific handler. It is used to call the platform-specific APIs for finding, creating, updating and deleting comments.
type PostResult ¶
type PostResult = struct {
// Posted is true if the comment was actually posted.
Posted bool
// SkipReason is the reason why the comment was not posted.
SkipReason string
}
PostResult is a struct that contains the result of posting a comment.