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

feat(bitbucket): support task autocomplete #30901

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c2358bf
refactor - return Pr at the end of the function
dandandy Aug 19, 2024
f92f192
add new platform pr option bbAutoCompletePrTasks
dandandy Aug 19, 2024
807acde
list PR tasks and update task state to resolved
dandandy Aug 19, 2024
525d0af
clean up logging statements
dandandy Aug 25, 2024
2b350c1
put auto resolve tasks in try catch block
dandandy Aug 25, 2024
92832f3
check pr is not null/undefined
dandandy Aug 25, 2024
722a2b7
don't log repository, it's already in metadata
dandandy Aug 25, 2024
b0b414d
make bbAutoResolvePrTasks optional incase it's not specified. Fixes b…
dandandy Aug 25, 2024
880447f
add tests for resolve bb pr tasks
dandandy Aug 25, 2024
fad7a16
Merge branch 'main' into feat/27485-bitbucket-task-autocomplete
dandandy Aug 25, 2024
83e5702
refactor - move auotResolvePrTask logic to private function, switch p…
dandandy Aug 25, 2024
1b00595
fix eslint error
dandandy Aug 25, 2024
bc882f6
trace instead of debug
dandandy Aug 26, 2024
285be40
just log pr number
dandandy Aug 26, 2024
6903e32
use zod validation
dandandy Aug 26, 2024
2bd439d
remove underscore from variable
dandandy Aug 26, 2024
13c5974
move to schema file
dandandy Aug 26, 2024
bb5ee9e
fix types in test file
dandandy Aug 26, 2024
3ec5fa3
Merge branch 'main' into feat/27485-bitbucket-task-autocomplete
dandandy Aug 26, 2024
1d93199
debug string instead of object
dandandy Aug 27, 2024
be8be4d
add prId to warn log
dandandy Aug 27, 2024
3a15251
use an starting uppercase letter for schemas
dandandy Sep 6, 2024
95d33c2
use an starting uppercase letter for schemas
dandandy Sep 6, 2024
95da535
use an starting uppercase letter for schemas
dandandy Sep 6, 2024
06969d1
use an starting uppercase letter for schemas
dandandy Sep 6, 2024
5b08e03
use an starting uppercase letter for schemas
dandandy Sep 6, 2024
b7c99eb
typescript knows the types
dandandy Sep 6, 2024
890c0e7
schema validation done in http layer
dandandy Sep 6, 2024
9d255c2
fix prettier error
dandandy Sep 6, 2024
9ed86bd
Merge branch 'main' into feat/27485-bitbucket-task-autocomplete
dandandy Sep 6, 2024
85aa188
Merge branch 'main' into feat/27485-bitbucket-task-autocomplete
dandandy Sep 12, 2024
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
4 changes: 4 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ You can also use the special `"$default"` string to denote the repository's defa
Do _not_ use the `baseBranches` config option when you've set a `forkToken`.
You may need a `forkToken` when you're using the Forking Renovate app.

## bbAutoResolvePrTasks

Configuring this to `true` means that Renovate will mark all PR Tasks as complete.

## bbUseDefaultReviewers

Configuring this to `true` means that Renovate will detect and apply the default reviewers rules to PRs (Bitbucket only).
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,14 @@ const options: RenovateOptions[] = [
cli: false,
env: false,
},
{
name: 'bbAutoResolvePrTasks',
description:
'The PR tasks will be automatically completed after the PR is raised.',
type: 'boolean',
default: false,
supportedPlatforms: ['bitbucket'],
},
{
name: 'bbUseDefaultReviewers',
description: 'Use the default reviewers (Bitbucket only).',
Expand Down
59 changes: 55 additions & 4 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
BranchResponse,
Config,
EffectiveReviewer,
ListPrTasksResponse,
PagedResult,
PrResponse,
RepoBranchingModel,
Expand Down Expand Up @@ -909,6 +910,7 @@
reviewers,
};

let pr: Pr;
try {
const prRes = (
await bitbucketHttp.postJson<PrResponse>(
Expand All @@ -918,14 +920,13 @@
},
)
).body;
const pr = utils.prInfo(prRes);
pr = utils.prInfo(prRes);
await BitbucketPrCache.addPr(
bitbucketHttp,
config.repository,
renovateUserUuid,
pr,
);
return pr;
} catch (err) /* istanbul ignore next */ {
// Try sanitizing reviewers
const sanitizedReviewers = await sanitizeReviewers(reviewers, err);
Expand All @@ -945,16 +946,66 @@
},
)
).body;
const pr = utils.prInfo(prRes);
pr = utils.prInfo(prRes);
await BitbucketPrCache.addPr(
bitbucketHttp,
config.repository,
renovateUserUuid,
pr,
);
return pr;
}
}

logger.debug(
{
repository: config.repository,
title,
base,
bbAutoResolvePrTasks: platformPrOptions?.bbAutoResolvePrTasks,
},
'Auto resolve PR tasks',
);
dandandy marked this conversation as resolved.
Show resolved Hide resolved
if (platformPrOptions?.bbAutoResolvePrTasks) {
dandandy marked this conversation as resolved.
Show resolved Hide resolved
const listTaskRes = (

Check warning on line 969 in lib/modules/platform/bitbucket/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/index.ts#L969

Added line #L969 was not covered by tests
dandandy marked this conversation as resolved.
Show resolved Hide resolved
await bitbucketHttp.getJson<ListPrTasksResponse>(
`/2.0/repositories/${config.repository}/pullrequests/${pr.number}/tasks`,
{ paginate: true, pagelen: 100 },
)
).body.values;

logger.debug(

Check warning on line 976 in lib/modules/platform/bitbucket/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/index.ts#L976

Added line #L976 was not covered by tests
dandandy marked this conversation as resolved.
Show resolved Hide resolved
{
repository: config.repository,
title,
base,
dandandy marked this conversation as resolved.
Show resolved Hide resolved
bbAutoCompleteTasks: platformPrOptions.bbAutoResolvePrTasks,
listTaskRes,
},
'List PR tasks',
);

const unResolvedTasks = utils.filterUnresolvedTasksIds(listTaskRes);

Check warning on line 987 in lib/modules/platform/bitbucket/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/index.ts#L987

Added line #L987 was not covered by tests

for (const task of unResolvedTasks) {
const res = await bitbucketHttp.putJson<unknown>(

Check warning on line 990 in lib/modules/platform/bitbucket/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/index.ts#L989-L990

Added lines #L989 - L990 were not covered by tests
`/2.0/repositories/${config.repository}/pullrequests/${pr.number}/tasks/${task.id}`,
{
body: {
state: 'RESOLVED',
content: {
raw: task.content.raw,
},
dandandy marked this conversation as resolved.
Show resolved Hide resolved
},
},
);
logger.debug(

Check warning on line 1001 in lib/modules/platform/bitbucket/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/index.ts#L1001

Added line #L1001 was not covered by tests
dandandy marked this conversation as resolved.
Show resolved Hide resolved
{ repository: config.repository, title, base, updateTaskResponse: res },
'Put PR tasks - mark resolved',
);
}
}

return pr;
}

export async function updatePr({
Expand Down
14 changes: 14 additions & 0 deletions lib/modules/platform/bitbucket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ export interface BitbucketPrCacheData {
updated_on: string | null;
author: string | null;
}

export interface ListPrTasksResponse {
values: PrTask[];
}

export interface PrTask {
id: number;
state: TaskState;
content: {
raw: string;
};
}

export type TaskState = 'RESOLVED' | 'UNRESOLVED';
dandandy marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions lib/modules/platform/bitbucket/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
BitbucketMergeStrategy,
MergeRequestBody,
PrResponse,
PrTask,
} from './types';

const bitbucketMergeStrategies: Map<MergeStrategy, BitbucketMergeStrategy> =
Expand Down Expand Up @@ -74,3 +75,7 @@
'values.created_on',
'values.updated_on',
].join(',');

export function filterUnresolvedTasksIds(tasks: PrTask[]): PrTask[] {
return tasks.filter((task) => task.state === 'UNRESOLVED');

Check warning on line 80 in lib/modules/platform/bitbucket/utils.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/platform/bitbucket/utils.ts#L80

Added line #L80 was not covered by tests
}
1 change: 1 addition & 0 deletions lib/modules/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type PlatformPrOptions = {
automergeStrategy?: MergeStrategy;
azureWorkItemId?: number;
bbUseDefaultReviewers?: boolean;
bbAutoResolvePrTasks: boolean;
gitLabIgnoreApprovals?: boolean;
usePlatformAutomerge?: boolean;
forkModeDisallowMaintainerEdits?: boolean;
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/update/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function getPlatformPrOptions(
autoApprove: !!config.autoApprove,
automergeStrategy: config.automergeStrategy,
azureWorkItemId: config.azureWorkItemId ?? 0,
bbAutoResolvePrTasks: !!config.bbAutoResolvePrTasks,
bbUseDefaultReviewers: !!config.bbUseDefaultReviewers,
gitLabIgnoreApprovals: !!config.gitLabIgnoreApprovals,
forkModeDisallowMaintainerEdits: !!config.forkModeDisallowMaintainerEdits,
Expand Down
Loading