Documentation
¶
Index ¶
- Constants
- Variables
- func CheckSecret(secret string) error
- func CheckTriggers(triggers []enum.WebhookTrigger) error
- func CheckURL(rawURL string, allowLoopback bool, allowPrivateNetwork bool, internal bool) error
- func ConvertTriggers(vals []string) []enum.WebhookTrigger
- func DeduplicateTriggers(in []enum.WebhookTrigger) []enum.WebhookTrigger
- type BaseSegment
- type CodeCommentInfo
- type CommentInfo
- type CommitInfo
- type Config
- type GitnessURLProvider
- type IdentityInfo
- type LabelInfo
- type PrincipalInfo
- type PullReqBranchUpdatedPayload
- type PullReqClosedPayload
- type PullReqCommentPayload
- type PullReqCommentSegment
- type PullReqCommentUpdatedPayload
- type PullReqCommentUpdatedSegment
- type PullReqCreatedPayload
- type PullReqInfo
- type PullReqLabelAssignedPayload
- type PullReqLabelSegment
- type PullReqMergedPayload
- type PullReqReopenedPayload
- type PullReqReviewSegment
- type PullReqReviewSubmittedPayload
- type PullReqReviewerChangedPayload
- type PullReqSegment
- type PullReqTargetReferenceSegment
- type PullReqUpdateSegment
- type PullReqUpdatedPayload
- type ReferenceDetailsSegment
- type ReferenceInfo
- type ReferencePayload
- type ReferenceSegment
- type ReferenceUpdateSegment
- type RepositoryInfo
- type ReviewerSegment
- type Service
- func (s *Service) Create(ctx context.Context, principalID int64, parentID int64, ...) (*types.Webhook, error)
- func (s *Service) Delete(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) error
- func (s *Service) Find(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) (*types.Webhook, error)
- func (s *Service) FindExecution(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) (*types.WebhookExecution, error)
- func (s *Service) GetWebhookExecutionVerifyOwnership(ctx context.Context, webhookID int64, webhookExecutionID int64) (*types.WebhookExecution, error)
- func (s *Service) GetWebhookVerifyOwnership(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) (*types.Webhook, error)
- func (s *Service) List(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) ([]*types.Webhook, int64, error)
- func (s *Service) ListExecutions(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) ([]*types.WebhookExecution, int64, error)
- func (s *Service) RetriggerExecution(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) (*types.WebhookExecution, error)
- func (s *Service) RetriggerWebhookExecution(ctx context.Context, webhookExecutionID int64) (*TriggerResult, error)
- func (s *Service) Update(ctx context.Context, parentID int64, parentType enum.WebhookParent, ...) (*types.Webhook, error)
- type SignatureInfo
- type TriggerResult
- type URLProvider
Constants ¶
const ( CodeReviewTemplate = `` /* 302-byte string literal not displayed */ DefaultDiffUnified = 3 MaxCommentLength = 64 << 10 DefaultAITimeout = 30 * time.Second )
const MaxWebhookCommitFileStats = 20
Variables ¶
var ErrInternalWebhookOperationNotAllowed = errors.Forbidden("changes to internal webhooks are not allowed")
var ( // ErrWebhookNotRetriggerable is returned in case the webhook can't be retriggered due to an incomplete execution. // This should only occur if we failed to generate the request body (most likely out of memory). ErrWebhookNotRetriggerable = errors.New("webhook execution is incomplete and can't be retriggered") )
var WireSet = wire.NewSet( ProvideService, ProvideURLProvider, )
WireSet provides a wire set for this package.
Functions ¶
func CheckSecret ¶
checkSecret validates the secret of a webhook.
func CheckTriggers ¶
func CheckTriggers(triggers []enum.WebhookTrigger) error
CheckTriggers validates the triggers of a webhook.
func ConvertTriggers ¶
func ConvertTriggers(vals []string) []enum.WebhookTrigger
func DeduplicateTriggers ¶
func DeduplicateTriggers(in []enum.WebhookTrigger) []enum.WebhookTrigger
DeduplicateTriggers de-duplicates the triggers provided by the user.
Types ¶
type BaseSegment ¶
type BaseSegment struct {
Trigger enum.WebhookTrigger `json:"trigger"`
Repo RepositoryInfo `json:"repo"`
Principal PrincipalInfo `json:"principal"`
}
BaseSegment contains base info of all payloads for webhooks.
type CodeCommentInfo ¶
type CommentInfo ¶
type CommitInfo ¶
type CommitInfo struct {
SHA string `json:"sha"`
Message string `json:"message"`
Author SignatureInfo `json:"author"`
Committer SignatureInfo `json:"committer"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}
CommitInfo describes the commit related info for a webhook payload. NOTE: don't use types package as we want webhook payload to be independent from API calls.
type Config ¶
type Config struct {
// UserAgentIdentity specifies the identity used for the user agent header
// IMPORTANT: do not include version.
UserAgentIdentity string
// HeaderIdentity specifies the identity used for headers in webhook calls (e.g. X-Gitness-Trigger, ...).
// NOTE: If no value is provided, the UserAgentIdentity will be used.
HeaderIdentity string
EventReaderName string
Concurrency int
MaxRetries int
AllowPrivateNetwork bool
AllowLoopback bool
// InternalWebhooksURL specifies the internal webhook URL which will be used if webhook is marked internal
InternalWebhooksURL string
}
type GitnessURLProvider ¶
type GitnessURLProvider struct{}
func NewURLProvider ¶
func NewURLProvider(_ context.Context) *GitnessURLProvider
func (*GitnessURLProvider) GetWebhookURL ¶
type IdentityInfo ¶
IdentityInfo describes the signature identity related info for a webhook payload. NOTE: don't use types package as we want webhook payload to be independent from API calls.
type PrincipalInfo ¶
type PrincipalInfo struct {
ID int64 `json:"id"`
UID string `json:"uid"`
DisplayName string `json:"display_name"`
Email string `json:"email"`
Type enum.PrincipalType `json:"type"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
}
PrincipalInfo describes the principal related info for a webhook payload. NOTE: don't use types package as we want webhook payload to be independent from API calls.
type PullReqBranchUpdatedPayload ¶
type PullReqBranchUpdatedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
ReferenceDetailsSegment
ReferenceUpdateSegment
}
PullReqBranchUpdatedPayload describes the body of the pullreq branch updated trigger. TODO: move in separate package for small import?
type PullReqClosedPayload ¶
type PullReqClosedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
ReferenceDetailsSegment
}
PullReqClosedPayload describes the body of the pullreq closed trigger.
type PullReqCommentPayload ¶
type PullReqCommentPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
ReferenceDetailsSegment
PullReqCommentSegment
}
PullReqCommentPayload describes the body of the pullreq comment create trigger.
type PullReqCommentSegment ¶
type PullReqCommentSegment struct {
CommentInfo CommentInfo `json:"comment"`
*CodeCommentInfo
}
PullReqCommentSegment contains details for all pull req comment related payloads for webhooks.
type PullReqCommentUpdatedPayload ¶
type PullReqCommentUpdatedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
PullReqCommentSegment
}
PullReqCommentUpdatedPayload describes the body of the pullreq comment create trigger.
type PullReqCommentUpdatedSegment ¶
type PullReqCommentUpdatedSegment struct {
CommentInfo
*CodeCommentInfo
}
PullReqCommentUpdatedSegment contains details for pullreq text comment edited payloads for webhooks.
type PullReqCreatedPayload ¶
type PullReqCreatedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
ReferenceDetailsSegment
}
PullReqCreatedPayload describes the body of the pullreq created trigger. TODO: move in separate package for small import?
type PullReqInfo ¶
type PullReqInfo struct {
Number int64 `json:"number"`
State enum.PullReqState `json:"state"`
IsDraft bool `json:"is_draft"`
Title string `json:"title"`
Description string `json:"description"`
SourceRepoID int64 `json:"source_repo_id"`
SourceBranch string `json:"source_branch"`
TargetRepoID int64 `json:"target_repo_id"`
TargetBranch string `json:"target_branch"`
MergeStrategy *enum.MergeMethod `json:"merge_strategy,omitempty"`
Author PrincipalInfo `json:"author"`
PrURL string `json:"pr_url"`
}
PullReqInfo describes the pullreq related info for a webhook payload. NOTE: don't use types package as we want pullreq payload to be independent from API calls.
type PullReqLabelAssignedPayload ¶
type PullReqLabelAssignedPayload struct {
BaseSegment
PullReqSegment
PullReqLabelSegment
}
PullReqLabelAssignedPayload describes the body of the pullreq label assignment trigger.
type PullReqLabelSegment ¶
type PullReqLabelSegment struct {
LabelInfo LabelInfo `json:"label"`
}
PullReqLabelSegment contains details for all pull req label related payloads for webhooks.
type PullReqMergedPayload ¶
type PullReqMergedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
ReferenceDetailsSegment
}
PullReqMergedPayload describes the body of the pullreq merged trigger.
type PullReqReopenedPayload ¶
type PullReqReopenedPayload PullReqCreatedPayload
PullReqReopenedPayload describes the body of the pullreq reopened trigger. Note: same as payload for created.
type PullReqReviewSegment ¶
type PullReqReviewSegment struct {
ReviewDecision enum.PullReqReviewDecision `json:"review_decision"`
ReviewerInfo PrincipalInfo `json:"reviewer"`
}
type PullReqReviewSubmittedPayload ¶
type PullReqReviewSubmittedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
PullReqReviewSegment
}
PullReqReviewSubmittedPayload describes the body of the pullreq review submitted trigger.
type PullReqReviewerChangedPayload ¶
type PullReqReviewerChangedPayload struct {
BaseSegment
PullReqSegment
ReviewerSegment
}
type PullReqSegment ¶
type PullReqSegment struct {
PullReq PullReqInfo `json:"pull_req"`
}
PullReqSegment contains details for all pull req related payloads for webhooks.
type PullReqTargetReferenceSegment ¶
type PullReqTargetReferenceSegment struct {
TargetRef ReferenceInfo `json:"target_ref"`
}
PullReqTargetReferenceSegment contains details for the pull req target reference for webhooks.
type PullReqUpdateSegment ¶
type PullReqUpdateSegment struct {
TitleChanged bool `json:"title_changed"`
TitleOld string `json:"title_old"`
TitleNew string `json:"title_new"`
DescriptionChanged bool `json:"description_changed"`
DescriptionOld string `json:"description_old"`
DescriptionNew string `json:"description_new"`
}
PullReqUpdateSegment contains details what has been updated in the pull request.
type PullReqUpdatedPayload ¶
type PullReqUpdatedPayload struct {
BaseSegment
PullReqSegment
PullReqTargetReferenceSegment
ReferenceSegment
PullReqUpdateSegment
}
PullReqUpdatedPayload describes the body of the pullreq updated trigger.
type ReferenceDetailsSegment ¶
type ReferenceDetailsSegment struct {
SHA string `json:"sha"`
HeadCommit *CommitInfo `json:"head_commit,omitempty"`
Commits *[]CommitInfo `json:"commits,omitempty"`
TotalCommitsCount int `json:"total_commits_count,omitempty"`
// Deprecated
Commit *CommitInfo `json:"commit,omitempty"`
}
ReferenceDetailsSegment contains extra details for reference related payloads for webhooks.
type ReferenceInfo ¶
type ReferenceInfo struct {
Name string `json:"name"`
Repo RepositoryInfo `json:"repo"`
}
ReferenceInfo describes a unique reference in Harness. It contains both the reference name as well as the repo the reference belongs to.
type ReferencePayload ¶
type ReferencePayload struct {
BaseSegment
ReferenceSegment
ReferenceDetailsSegment
ReferenceUpdateSegment
}
ReferencePayload describes the payload of Reference related webhook triggers. Note: Use same payload for all reference operations to make it easier for consumers.
type ReferenceSegment ¶
type ReferenceSegment struct {
Ref ReferenceInfo `json:"ref"`
}
ReferenceSegment contains the reference info for webhooks.
type ReferenceUpdateSegment ¶
ReferenceUpdateSegment contains extra details for reference update related payloads for webhooks.
type RepositoryInfo ¶
type RepositoryInfo struct {
ID int64 `json:"id"`
Path string `json:"path"`
Identifier string `json:"identifier"`
Description string `json:"description"`
DefaultBranch string `json:"default_branch"`
URL string `json:"url"`
GitURL string `json:"git_url"`
GitSSHURL string `json:"git_ssh_url"`
}
RepositoryInfo describes the repo related info for a webhook payload. NOTE: don't use types package as we want webhook payload to be independent from API calls.
func (RepositoryInfo) MarshalJSON ¶
func (r RepositoryInfo) MarshalJSON() ([]byte, error)
TODO [CODE-1363]: remove after identifier migration.
type ReviewerSegment ¶
type ReviewerSegment struct {
Reviewer PrincipalInfo `json:"reviewer"`
}
ReviewerSegment contains details for all reviewer related payloads for webhooks.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is responsible for processing webhook events.
func NewService ¶
func NewService( ctx context.Context, config Config, tx dbtx.Transactor, gitReaderFactory *events.ReaderFactory[*gitevents.Reader], prReaderFactory *events.ReaderFactory[*pullreqevents.Reader], webhookStore store.WebhookStore, webhookExecutionStore store.WebhookExecutionStore, spaceStore store.SpaceStore, aiStore store.AIStore, repoStore store.RepoStore, pullreqStore store.PullReqStore, activityStore store.PullReqActivityStore, urlProvider url.Provider, principalStore store.PrincipalStore, git git.Interface, encrypter encrypt.Encrypter, labelStore store.LabelStore, settings *settings.Service, webhookURLProvider URLProvider, labelValueStore store.LabelValueStore, ) (*Service, error)
func ProvideService ¶
func ProvideService( ctx context.Context, config Config, tx dbtx.Transactor, gitReaderFactory *events.ReaderFactory[*gitevents.Reader], prReaderFactory *events.ReaderFactory[*pullreqevents.Reader], webhookStore store.WebhookStore, webhookExecutionStore store.WebhookExecutionStore, spaceStore store.SpaceStore, aiStore store.AIStore, repoStore store.RepoStore, pullreqStore store.PullReqStore, activityStore store.PullReqActivityStore, urlProvider url.Provider, principalStore store.PrincipalStore, git git.Interface, encrypter encrypt.Encrypter, labelStore store.LabelStore, settings *settings.Service, webhookURLProvider URLProvider, labelValueStore store.LabelValueStore, ) (*Service, error)
func (*Service) Delete ¶
func (s *Service) Delete( ctx context.Context, parentID int64, parentType enum.WebhookParent, webhookIdentifier string, allowDeletingInternal bool, ) error
Delete deletes an existing webhook.
func (*Service) FindExecution ¶
func (s *Service) FindExecution( ctx context.Context, parentID int64, parentType enum.WebhookParent, webhookIdentifier string, webhookExecutionID int64, ) (*types.WebhookExecution, error)
FindExecution finds a webhook execution.
func (*Service) GetWebhookExecutionVerifyOwnership ¶
func (s *Service) GetWebhookExecutionVerifyOwnership( ctx context.Context, webhookID int64, webhookExecutionID int64, ) (*types.WebhookExecution, error)
GetWebhookExecutionVerifyOwnership gets the webhook execution and ensures it belongs to the webhook with the specified id.
func (*Service) GetWebhookVerifyOwnership ¶
func (s *Service) GetWebhookVerifyOwnership( ctx context.Context, parentID int64, parentType enum.WebhookParent, webhookIdentifier string, ) (*types.Webhook, error)
GetWebhookVerifyOwnership gets the webhook and ensures it belongs to the scope with the specified id and type.
func (*Service) List ¶
func (s *Service) List( ctx context.Context, parentID int64, parentType enum.WebhookParent, inherited bool, filter *types.WebhookFilter, ) ([]*types.Webhook, int64, error)
Listreturns the webhooks from the provided scope.
func (*Service) ListExecutions ¶
func (s *Service) ListExecutions( ctx context.Context, parentID int64, parentType enum.WebhookParent, webhookIdentifier string, filter *types.WebhookExecutionFilter, ) ([]*types.WebhookExecution, int64, error)
ListExecutions returns the executions of the webhook.
func (*Service) RetriggerExecution ¶
func (s *Service) RetriggerExecution( ctx context.Context, parentID int64, parentType enum.WebhookParent, webhookIdentifier string, webhookExecutionID int64, ) (*types.WebhookExecution, error)
RetriggerExecution retriggers an existing webhook execution.
func (*Service) RetriggerWebhookExecution ¶
type SignatureInfo ¶
type SignatureInfo struct {
Identity IdentityInfo `json:"identity"`
When time.Time `json:"when"`
}
SignatureInfo describes the commit signature related info for a webhook payload. NOTE: don't use types package as we want webhook payload to be independent from API calls.
type TriggerResult ¶
type TriggerResult struct {
TriggerID string
TriggerType enum.WebhookTrigger
Webhook *types.Webhook
Execution *types.WebhookExecution
Err error
}
func (*TriggerResult) Skipped ¶
func (r *TriggerResult) Skipped() bool
type URLProvider ¶
type URLProvider interface {
GetWebhookURL(ctx context.Context, webhook *types.Webhook) (string, error)
}
func ProvideURLProvider ¶
func ProvideURLProvider(ctx context.Context) URLProvider