Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): pullrequest branch filter is on target branch #7248

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@angular-devkit/build-angular": "16.2.11",
"@angular/cli": "16.2.11",
"@angular/compiler-cli": "16.2.12",
"@jridgewell/gen-mapping": "0.3.5",
"@types/d3": "5.9.2",
"@types/dagre": "0.7.52",
"@types/dagre-d3": "0.6.6",
Expand Down
4 changes: 2 additions & 2 deletions engine/api/v2_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (api *API) postRetrieveWorkflowToTriggerHandler() ([]service.RbacChecker, s

hooksWithReadRight := make([]sdk.V2WorkflowHook, 0)
for _, h := range filteredWorkflowHooks {
if !hookRequest.AnayzedProjectKeys.Contains(h.ProjectKey) {
if !hookRequest.AnalyzedProjectKeys.Contains(h.ProjectKey) {
// Check project right
vcsClient, err := repositoriesmanager.AuthorizedClient(ctx, db, api.Cache, h.ProjectKey, hookRequest.VCSName)
if err != nil {
Expand Down Expand Up @@ -428,7 +428,7 @@ func LoadWorkflowHooksWithRepositoryWebHooks(ctx context.Context, db gorp.SqlExe
if len(w.Data.TypesFilter) > 0 {
validType = sdk.IsInArray(hookRequest.RepositoryEventType, w.Data.TypesFilter)
}
if w.Data.ValidateRef(ctx, hookRequest.Ref) && validType {
if w.Data.ValidateRef(ctx, hookRequest.PullRequestRefTo) && validType {
filteredWorkflowHooks = append(filteredWorkflowHooks, w)
}
continue
Expand Down
8 changes: 4 additions & 4 deletions engine/api/v2_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestPostRetrieveWorkflowToTriggerHandler_RepositoryWebHooks(t *testing.T) {
RepositoryName: repo.Name,
VCSName: vcs.Name,
RepositoryEventName: sdk.WorkflowHookEventNamePush,
AnayzedProjectKeys: []string{p.Key},
AnalyzedProjectKeys: []string{p.Key},
Ref: "refs/heads/master",
Sha: "123456",
}
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestPostRetrieveWorkflowToTriggerHandler_RepositoryWebHooksPullRequest(t *t
RepositoryEventType: sdk.WorkflowHookEventTypePullRequestOpened,
Ref: "refs/heads/master",
Sha: "123456",
AnayzedProjectKeys: []string{p.Key},
AnalyzedProjectKeys: []string{p.Key},
}

uri := api.Router.GetRouteV2("POST", api.postRetrieveWorkflowToTriggerHandler, nil)
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestPostRetrieveWorkflowToTriggerHandler_RepositoryWebHooksPullRequestFilte
VCSName: vcs.Name,
RepositoryEventName: sdk.WorkflowHookEventNamePullRequest,
RepositoryEventType: sdk.WorkflowHookEventTypePullRequestOpened,
AnayzedProjectKeys: []string{p.Key},
AnalyzedProjectKeys: []string{p.Key},
}

uri := api.Router.GetRouteV2("POST", api.postRetrieveWorkflowToTriggerHandler, nil)
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestPostRetrieveWorkflowToTriggerHandler_WorkerModels(t *testing.T) {
Ref: "refs/heads/master",
Sha: "123456",
RepositoryEventName: sdk.WorkflowHookEventNamePush,
AnayzedProjectKeys: []string{p.Key},
AnalyzedProjectKeys: []string{p.Key},
Models: []sdk.EntityFullName{
{
Name: "MySuperModel",
Expand Down
2 changes: 1 addition & 1 deletion engine/api/v2_repository_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ func manageWorkflowHooks(ctx context.Context, db gorpmapper.SqlExecutorWithTx, c
}
hooks = append(hooks, wh)

if e.Commit == defaultBranch.LatestCommit {
if e.Ref == defaultBranch.ID && e.Commit == defaultBranch.LatestCommit {
// Load existing head hook
existingHook, err := workflow_v2.LoadHookHeadRepositoryWebHookByWorkflowAndEvent(ctx, db, e.ProjectKey, workflowDefVCSName, workflowDefRepositoryName, e.Name, sdk.WorkflowHookEventNamePullRequest, defaultBranch.ID)
if err != nil && !sdk.ErrorIs(err, sdk.ErrNotFound) {
Expand Down
7 changes: 4 additions & 3 deletions engine/hooks/trigger_workflow_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *Service) handleWorkflowHook(ctx context.Context, hre *sdk.HookRepositor
request := sdk.HookListWorkflowRequest{
HookEventUUID: hre.UUID,
Ref: hre.ExtractData.Ref,
PullRequestRefTo: hre.ExtractData.PullRequestRefTo,
Sha: hre.ExtractData.Commit,
Models: hre.ModelUpdated,
Workflows: hre.WorkflowUpdated,
Expand All @@ -87,15 +88,15 @@ func (s *Service) handleWorkflowHook(ctx context.Context, hre *sdk.HookRepositor
RepositoryEventType: hre.EventType,
VCSName: hre.VCSServerName,
RepositoryName: hre.RepositoryName,
AnayzedProjectKeys: sdk.StringSlice{},
AnalyzedProjectKeys: sdk.StringSlice{},
}
for _, a := range hre.Analyses {
// Only retrieve hooks from project where analysis is OK
if a.Status == sdk.RepositoryAnalysisStatusSucceed {
request.AnayzedProjectKeys = append(request.AnayzedProjectKeys, a.ProjectKey)
request.AnalyzedProjectKeys = append(request.AnalyzedProjectKeys, a.ProjectKey)
}
}
request.AnayzedProjectKeys.Unique()
request.AnalyzedProjectKeys.Unique()
workflowHooks, err := s.Client.ListWorkflowToTrigger(ctx, request)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion sdk/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ type HookListWorkflowRequest struct {
VCSName string `json:"vcs_name"`
RepositoryName string `json:"repository_name"`
Ref string `json:"ref"`
PullRequestRefTo string `json:"pullrequest_ref_to"`
Sha string `json:"sha"`
Paths []string `json:"paths"`
RepositoryEventName WorkflowHookEventName `json:"repository_event"`
RepositoryEventType WorkflowHookEventType `json:"repository_event_type"`
AnayzedProjectKeys StringSlice `json:"project_keys"`
AnalyzedProjectKeys StringSlice `json:"project_keys"`
Models []EntityFullName `json:"models"`
Workflows []EntityFullName `json:"workflows"`
}
Expand Down