Skip to content

Commit

Permalink
feat(bitbucket): Server-side filtering of PR list response (#26336)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Dec 16, 2023
1 parent b528b8c commit e80b882
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/modules/platform/bitbucket/index.spec.ts
Expand Up @@ -3,6 +3,7 @@ import type { logger as _logger } from '../../../logger';
import type * as _git from '../../../util/git';
import { setBaseUrl } from '../../../util/http/bitbucket';
import type { Platform, PlatformResult, RepoParams } from '../types';
import { prFieldsFilter } from './utils';

jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');
Expand Down Expand Up @@ -235,7 +236,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock();
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, { values: [pr] })
.get('/2.0/repositories/some/repo/pullrequests/5')
Expand All @@ -248,7 +249,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock();
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, { values: [pr] });

Expand Down Expand Up @@ -753,7 +754,7 @@ describe('modules/platform/bitbucket/index', () => {
await initRepoMock(undefined, null, scope);
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&q=author.uuid="12345"&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&q=author.uuid="12345"&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, {
values: [
Expand All @@ -779,7 +780,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock();
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, { values: [pr] });
expect(
Expand All @@ -805,7 +806,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock();
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, {
values: [
Expand Down Expand Up @@ -843,7 +844,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock({}, { is_private: true });
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, {
values: [
Expand Down Expand Up @@ -883,7 +884,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock({}, { is_private: false });
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, {
values: [
Expand Down Expand Up @@ -927,7 +928,7 @@ describe('modules/platform/bitbucket/index', () => {
const scope = await initRepoMock({}, { is_private: false });
scope
.get(
'/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&pagelen=50',
`/2.0/repositories/some/repo/pullrequests?state=OPEN&state=MERGED&state=DECLINED&state=SUPERSEDED&fields=${prFieldsFilter}&pagelen=50`,
)
.reply(200, {
values: [
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/platform/bitbucket/index.ts
Expand Up @@ -44,7 +44,7 @@ import type {
RepoInfoBody,
} from './types';
import * as utils from './utils';
import { mergeBodyTransformer } from './utils';
import { mergeBodyTransformer, prFieldsFilter } from './utils';

export const id = 'bitbucket';

Expand Down Expand Up @@ -282,6 +282,7 @@ export async function getPrList(): Promise<Pr[]> {
if (renovateUserUuid && !config.ignorePrAuthor) {
querySearchParams.append('q', `author.uuid="${renovateUserUuid}"`);
}
querySearchParams.append('fields', prFieldsFilter);
const query = querySearchParams.toString();
const url = `/2.0/repositories/${config.repository}/pullrequests?${query}`;
const prs = (
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/bitbucket/types.ts
Expand Up @@ -89,7 +89,7 @@ export interface PrResponse {
name: string;
};
};
reviewers: Array<Account>;
reviewers: Account[];
created_on: string;
}

Expand Down
15 changes: 15 additions & 0 deletions lib/modules/platform/bitbucket/utils.ts
Expand Up @@ -72,3 +72,18 @@ export function prInfo(pr: PrResponse): Pr {
createdAt: pr.created_on,
};
}

export const prFieldsFilter = [
'values.id',
'values.title',
'values.state',
'values.links.commits.href',
'values.summary.raw',
'values.source.branch.name',
'values.destination.branch.name',
'values.reviewers.display_name',
'values.reviewers.uuid',
'values.reviewers.nickname',
'values.reviewers.account_status',
'values.created_on',
].join(',');

0 comments on commit e80b882

Please sign in to comment.