Skip to content

Commit

Permalink
feat(api,hooks): add commit message of hook filter + rework changesets (
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jul 12, 2024
1 parent fb4c8a8 commit 46b3c37
Show file tree
Hide file tree
Showing 31 changed files with 231 additions and 82 deletions.
1 change: 1 addition & 0 deletions contrib/grpcplugins/action/plugin-archive/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions contrib/grpcplugins/action/plugin-archive/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Cl
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0=
github.com/mitchellh/hashstructure v1.1.0/go.mod h1:xUDAozZz0Wmdiufv0uyhnHkUTN6/6d8ulp4AwfLKrmA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mholt/archiver/v3 v3.5.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssn
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
Expand Down
1 change: 1 addition & 0 deletions contrib/grpcplugins/action/plugin-tmpl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions contrib/grpcplugins/action/plugin-tmpl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0=
github.com/mitchellh/hashstructure v1.1.0/go.mod h1:xUDAozZz0Wmdiufv0uyhnHkUTN6/6d8ulp4AwfLKrmA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 h1:hOY53G+kBFhbYFpRVxHl5eS7laP6B1+Cq+Z9Dry1iMU=
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 h1:hOY53G+kBFhbYFpRVxHl5eS7laP6B1+Cq+Z9Dry1iMU=
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
18 changes: 8 additions & 10 deletions engine/api/v2_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ func (api *API) postHookEventRetrieveSignKeyHandler() ([]service.RbacChecker, se
}

opts := sdk.OperationCheckout{
Commit: commit,
CheckSignature: hookRetrieveSignKey.GetSigninKey,
ProcessSemver: hookRetrieveSignKey.GetSemver,
GetChangeSet: hookRetrieveSignKey.GetChangesets,
Commit: commit,
CheckSignature: hookRetrieveSignKey.GetSigninKey,
ProcessSemver: hookRetrieveSignKey.GetSemver,
GetChangeSet: hookRetrieveSignKey.GetChangesets,
ChangeSetCommitSince: hookRetrieveSignKey.ChangesetsCommitSince,
GetMessage: hookRetrieveSignKey.GetCommitMessage,
}
ope, err := operation.CheckoutAndAnalyzeOperation(ctx, api.mustDB(), *proj, *vcsProjectWithSecret, repo.Fullname, cloneURL, refToClone, opts)
if err != nil {
Expand Down Expand Up @@ -315,20 +317,16 @@ func LoadWorkflowHooksWithRepositoryWebHooks(ctx context.Context, db gorp.SqlExe
// Check configuration : branch filter + path filter
switch hookRequest.RepositoryEventName {
case sdk.WorkflowHookEventPush:
validBranch := sdk.IsValidHookRefs(ctx, w.Data.BranchFilter, strings.TrimPrefix(hookRequest.Ref, sdk.GitRefBranchPrefix))
validTag := sdk.IsValidHookRefs(ctx, w.Data.TagFilter, strings.TrimPrefix(hookRequest.Ref, sdk.GitRefTagPrefix))
if validBranch && validTag {
if w.Data.ValidateRef(ctx, hookRequest.Ref) {
filteredWorkflowHooks = append(filteredWorkflowHooks, w)
}
continue
case sdk.WorkflowHookEventPullRequest, sdk.WorkflowHookEventPullRequestComment:
validBranch := sdk.IsValidHookRefs(ctx, w.Data.BranchFilter, strings.TrimPrefix(hookRequest.Ref, sdk.GitRefBranchPrefix))
validTag := sdk.IsValidHookRefs(ctx, w.Data.TagFilter, strings.TrimPrefix(hookRequest.Ref, sdk.GitRefTagPrefix))
validType := true
if len(w.Data.TypesFilter) > 0 {
validType = sdk.IsInArray(hookRequest.RepositoryEventType, w.Data.TypesFilter)
}
if validBranch && validTag && validType {
if w.Data.ValidateRef(ctx, hookRequest.Ref) && validType {
filteredWorkflowHooks = append(filteredWorkflowHooks, w)
}
continue
Expand Down
3 changes: 3 additions & 0 deletions engine/api/v2_repository_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ func manageWorkflowHooks(ctx context.Context, db gorpmapper.SqlExecutorWithTx, e
RepositoryEvent: sdk.WorkflowHookEventPush,
VCSServer: targetVCS,
RepositoryName: targetRepository,
CommitFilter: e.Workflow.On.Push.Commit,
BranchFilter: e.Workflow.On.Push.Branches,
TagFilter: e.Workflow.On.Push.Tags,
PathFilter: e.Workflow.On.Push.Paths,
Expand All @@ -890,6 +891,7 @@ func manageWorkflowHooks(ctx context.Context, db gorpmapper.SqlExecutorWithTx, e
RepositoryEvent: sdk.WorkflowHookEventPush,
VCSServer: targetVCS,
RepositoryName: targetRepository,
CommitFilter: e.Workflow.On.Push.Commit,
BranchFilter: e.Workflow.On.Push.Branches,
TagFilter: e.Workflow.On.Push.Tags,
PathFilter: e.Workflow.On.Push.Paths,
Expand All @@ -913,6 +915,7 @@ func manageWorkflowHooks(ctx context.Context, db gorpmapper.SqlExecutorWithTx, e
RepositoryEvent: sdk.WorkflowHookEventPush,
VCSServer: targetVCS,
RepositoryName: targetRepository,
CommitFilter: e.Workflow.On.Push.Commit,
BranchFilter: e.Workflow.On.Push.Branches,
TagFilter: e.Workflow.On.Push.Tags,
PathFilter: e.Workflow.On.Push.Paths,
Expand Down
1 change: 1 addition & 0 deletions engine/api/v2_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ func (api *API) postWorkflowRunFromHookV2Handler() ([]service.RbacChecker, servi
EventName: runRequest.EventName,
Ref: runRequest.Ref,
Sha: runRequest.Sha,
CommitMessage: runRequest.CommitMessage,
SemverCurrent: runRequest.SemverCurrent,
SemverNext: runRequest.SemverNext,
ChangeSets: runRequest.ChangeSets,
Expand Down
1 change: 1 addition & 0 deletions engine/api/v2_workflow_run_craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ func buildRunContext(ctx context.Context, db *gorp.DbMap, store cache.Store, wr
RefName: strings.TrimPrefix(strings.TrimPrefix(ref, sdk.GitRefBranchPrefix), sdk.GitRefTagPrefix),
RefType: refType,
Sha: commit,
CommitMessage: wr.RunEvent.CommitMessage,
SemverCurrent: semverCurrent,
SemverNext: semverNext,
ChangeSets: wr.RunEvent.ChangeSets,
Expand Down
38 changes: 38 additions & 0 deletions engine/hooks/hook_repository_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/ovh/cds/sdk"
)

const (
NoCommit = "0000000000000000000000000000000000000000"
)

func (s *Service) extractDataFromPayload(headers http.Header, vcsServerType string, body []byte, eventName string) (string, sdk.HookRepositoryEventExtractData, error) {
switch vcsServerType {
case sdk.VCSTypeBitbucketServer:
Expand Down Expand Up @@ -41,9 +45,13 @@ func (s *Service) extractDataFromGiteaRequest(body []byte, eventName string) (st
extractedData.CDSEventType = "" // nothing here
extractedData.Ref = request.Ref
extractedData.Commit = request.After
if request.Before != NoCommit {
extractedData.CommitFrom = request.Before
}
case "pull_request":
extractedData.Ref = sdk.GitRefBranchPrefix + request.PullRequest.Head.Ref
extractedData.Commit = request.PullRequest.Head.Sha
extractedData.CommitFrom = request.PullRequest.Base.Sha
switch request.Action {
case "opened":
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
Expand Down Expand Up @@ -77,6 +85,9 @@ func (s *Service) extractDataFromGitlabRequest(body []byte, eventName string) (s
}
extractedData.Ref = request.Ref
extractedData.Commit = request.After
if request.Before != NoCommit {
extractedData.CommitFrom = request.Before
}

for _, c := range request.Commits {
extractedData.Paths = append(extractedData.Paths, c.Added...)
Expand Down Expand Up @@ -108,6 +119,9 @@ func (s *Service) extractDataFromGithubRequest(body []byte, eventName string) (s
}
extractedData.Ref = request.Ref
extractedData.Commit = request.After
if request.Before != NoCommit {
extractedData.CommitFrom = request.Before
}

var repoName string
if request.Repository != nil {
Expand All @@ -127,9 +141,23 @@ func (s *Service) extractDataFromGithubRequest(body []byte, eventName string) (s
case "pull_request":
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventType = request.Action
if request.Head != nil {
extractedData.Commit = request.Head.Sha
extractedData.Ref = sdk.GitRefBranchPrefix + request.Head.Ref
}
if request.Base != nil {
extractedData.CommitFrom = request.Base.Sha
}
case "pull_request_comment":
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequestComment
extractedData.CDSEventType = request.Action
if request.Head != nil {
extractedData.Commit = request.Head.Sha
extractedData.Ref = sdk.GitRefBranchPrefix + request.Head.Ref
}
if request.Base != nil {
extractedData.CommitFrom = request.Base.Sha
}
}
return repoName, extractedData, nil
}
Expand All @@ -148,44 +176,54 @@ func (s *Service) extractDataFromBitbucketRequest(body []byte) (string, sdk.Hook
case "repo:refs_changed":
extractedData.Ref = request.Changes[0].RefID
extractedData.Commit = request.Changes[0].ToHash
if request.Changes[0].FromHash != NoCommit {
extractedData.CommitFrom = request.Changes[0].FromHash
}
extractedData.CDSEventName = sdk.WorkflowHookEventPush
extractedData.CDSEventType = "" // no type here
case "pr:opened":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestTypeOpened
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:reopened":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestTypeReopened
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:declined":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestTypeClosed
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:from_ref_updated":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequest
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestTypeEdited
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:comment:added":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequestComment
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestCommentTypeCreated
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:comment:edited":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequestComment
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestCommentTypeEdited
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
case "pr:comment:deleted":
extractedData.Ref = request.PullRequest.FromRef.ID
extractedData.Commit = request.PullRequest.FromRef.LatestCommit
extractedData.CDSEventName = sdk.WorkflowHookEventPullRequestComment
extractedData.CDSEventType = sdk.WorkflowHookEventPullRequestCommentTypeDeleted
extractedData.CommitFrom = request.PullRequest.ToRef.LatestCommit
}

if extractedData.Ref == "" {
Expand Down
21 changes: 11 additions & 10 deletions engine/hooks/trigger_git_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ func (s *Service) triggerGetGitInfo(ctx context.Context, hre *sdk.HookRepository
}

ope, err := s.Client.RetrieveHookEventSigningKey(ctx, sdk.HookRetrieveSignKeyRequest{
HookEventUUID: hre.UUID,
HookEventKey: cache.Key(repositoryEventRootKey, s.Dao.GetRepositoryMemberKey(hre.VCSServerName, hre.RepositoryName), hre.UUID),
ProjectKey: hre.WorkflowHooks[0].ProjectKey,
VCSServerName: wh.Data.VCSServer,
RepositoryName: wh.Data.RepositoryName,
Commit: wh.TargetCommit,
Ref: ref,
GetSigninKey: false,
GetChangesets: withChangeSet,
GetSemver: true,
HookEventUUID: hre.UUID,
HookEventKey: cache.Key(repositoryEventRootKey, s.Dao.GetRepositoryMemberKey(hre.VCSServerName, hre.RepositoryName), hre.UUID),
ProjectKey: hre.WorkflowHooks[0].ProjectKey,
VCSServerName: wh.Data.VCSServer,
RepositoryName: wh.Data.RepositoryName,
Commit: wh.TargetCommit,
Ref: ref,
GetSigninKey: false,
GetChangesets: withChangeSet,
GetSemver: true,
GetCommitMessage: true,
})
if err != nil {
return err
Expand Down
34 changes: 22 additions & 12 deletions engine/hooks/trigger_signingkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (s *Service) triggerGetSigningKey(ctx context.Context, hre *sdk.HookReposit
changesets := false
semver := false
signinkey := true
commitMessage := false

for _, wh := range hre.WorkflowHooks {
switch wh.Type {
Expand All @@ -35,6 +36,7 @@ func (s *Service) triggerGetSigningKey(ctx context.Context, hre *sdk.HookReposit
changesets = true
semver = true
signinkey = true
commitMessage = true
}
}

Expand All @@ -50,18 +52,23 @@ func (s *Service) triggerGetSigningKey(ctx context.Context, hre *sdk.HookReposit
repo = hre.ExtractData.Scheduler.TargetRepo
}

ope, err := s.Client.RetrieveHookEventSigningKey(ctx, sdk.HookRetrieveSignKeyRequest{
HookEventUUID: hre.UUID,
HookEventKey: cache.Key(repositoryEventRootKey, s.Dao.GetRepositoryMemberKey(hre.VCSServerName, hre.RepositoryName), hre.UUID),
ProjectKey: hre.WorkflowHooks[0].ProjectKey,
VCSServerName: vcs,
RepositoryName: repo,
Commit: hre.ExtractData.Commit,
Ref: hre.ExtractData.Ref,
GetSigninKey: signinkey,
GetChangesets: changesets,
GetSemver: semver,
})
req := sdk.HookRetrieveSignKeyRequest{
HookEventUUID: hre.UUID,
HookEventKey: cache.Key(repositoryEventRootKey, s.Dao.GetRepositoryMemberKey(hre.VCSServerName, hre.RepositoryName), hre.UUID),
ProjectKey: hre.WorkflowHooks[0].ProjectKey,
VCSServerName: vcs,
RepositoryName: repo,
Commit: hre.ExtractData.Commit,
Ref: hre.ExtractData.Ref,
GetSigninKey: signinkey,
GetChangesets: changesets,
GetSemver: semver,
GetCommitMessage: commitMessage,
}
if changesets {
req.ChangesetsCommitSince = hre.ExtractData.CommitFrom
}
ope, err := s.Client.RetrieveHookEventSigningKey(ctx, req)
if err != nil {
return err
}
Expand Down Expand Up @@ -136,6 +143,9 @@ func (s *Service) manageRepositoryOperationCallback(ctx context.Context, ope sdk
for _, v := range ope.Setup.Checkout.Result.Files {
computeChangeSets = append(computeChangeSets, v.Filename)
}
if hre.ExtractData.CommitMessage == "" {
hre.ExtractData.CommitMessage = ope.Setup.Checkout.Result.CommitMessage
}

// Update repository hook status
for i := range hre.WorkflowHooks {
Expand Down
Loading

0 comments on commit 46b3c37

Please sign in to comment.