mirror of
https://github.com/harness/drone.git
synced 2025-05-04 10:41:37 +08:00
feat: [CODE-2483]: skip permission check for space pullreq API and fix the inner loop (#2791)
* skip permission check for space pullreq API and fix the inner loop
This commit is contained in:
parent
f2e382acbf
commit
c628d3307d
@ -20,7 +20,6 @@ import (
|
|||||||
|
|
||||||
"github.com/harness/gitness/app/auth"
|
"github.com/harness/gitness/app/auth"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListPullReqs returns a list of pull requests from the provided space.
|
// ListPullReqs returns a list of pull requests from the provided space.
|
||||||
@ -31,11 +30,14 @@ func (c *Controller) ListPullReqs(
|
|||||||
includeSubspaces bool,
|
includeSubspaces bool,
|
||||||
filter *types.PullReqFilter,
|
filter *types.PullReqFilter,
|
||||||
) ([]types.PullReqRepo, error) {
|
) ([]types.PullReqRepo, error) {
|
||||||
space, err := c.getSpaceCheckAuth(ctx, session, spaceRef, enum.PermissionSpaceView)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to acquire access to space: %w", err)
|
return nil, fmt.Errorf("space not found: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We deliberately don't check for space permission because the pull request service
|
||||||
|
// will check for repo-view permission for every returned pull request.
|
||||||
|
|
||||||
pullReqs, err := c.prListService.ListForSpace(ctx, session, space, includeSubspaces, filter)
|
pullReqs, err := c.prListService.ListForSpace(ctx, session, space, includeSubspaces, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to fetch pull requests from space: %w", err)
|
return nil, fmt.Errorf("failed to fetch pull requests from space: %w", err)
|
||||||
|
@ -185,8 +185,9 @@ func (c *ListService) streamPullReqs(
|
|||||||
pullReqs := make([]*types.PullReq, 0, opts.Size)
|
pullReqs := make([]*types.PullReq, 0, opts.Size)
|
||||||
ch, chErr := c.pullreqStore.Stream(ctx, opts)
|
ch, chErr := c.pullreqStore.Stream(ctx, opts)
|
||||||
for pr := range ch {
|
for pr := range ch {
|
||||||
if pr == nil {
|
if len(pullReqs) >= pullReqLimit || len(repoUnchecked) >= newRepoLimit {
|
||||||
return pullReqs, repoUnchecked, nil
|
cancelFn() // the loop must be exited by canceling the context
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := repoWhitelist[pr.TargetRepoID]; !ok {
|
if _, ok := repoWhitelist[pr.TargetRepoID]; !ok {
|
||||||
@ -194,13 +195,9 @@ func (c *ListService) streamPullReqs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pullReqs = append(pullReqs, pr)
|
pullReqs = append(pullReqs, pr)
|
||||||
|
|
||||||
if len(pullReqs) >= pullReqLimit || len(repoUnchecked) >= newRepoLimit {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := <-chErr; err != nil {
|
if err := <-chErr; err != nil && !errors.Is(err, context.Canceled) {
|
||||||
return nil, nil, fmt.Errorf("failed to stream pull requests: %w", err)
|
return nil, nil, fmt.Errorf("failed to stream pull requests: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user