This commit is contained in:
Adam Setch 2025-01-09 12:10:09 +01:00 committed by GitHub
commit d0ead23ab4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 165 additions and 1 deletions

View file

@ -346,6 +346,10 @@ You can also use the special `"$default"` string to denote the repository's defa
Configuring this to `true` means that Renovate will mark all PR Tasks as complete.
## bbMendAppDashboardStatus
Configure this to `true` means that Renovate will create a branch status against the repository's main branch, linking to the [Mend App on Bitbucket Repository Dashboard](./mend-hosted/hosted-apps-config.md).
## bbUseDefaultReviewers
Configuring this to `true` means that Renovate will detect and apply the default reviewers rules to PRs (Bitbucket only).

View file

@ -1951,6 +1951,13 @@ const options: RenovateOptions[] = [
default: false,
supportedPlatforms: ['bitbucket'],
},
{
name: 'bbMendAppDashboardStatus',
description: `Creates a main branch status linked to the repository's Mend App Dashboard.`,
type: 'boolean',
default: false,
supportedPlatforms: ['bitbucket'],
},
{
name: 'bbUseDefaultReviewers',
description: 'Use the default reviewers (Bitbucket only).',

View file

@ -246,6 +246,134 @@ describe('modules/platform/bitbucket/index', () => {
});
});
describe('bbMendAppDashboardStatus', () => {
it('not enabled: should skip setting branch status for main branch', async () => {
httpMock
.scope(baseUrl)
.get('/2.0/repositories/some/repo')
.reply(200, {
mainbranch: { name: 'main' },
uuid: '123',
full_name: 'some/repo',
});
expect(
await bitbucket.initRepo({
repository: 'some/repo',
bbMendAppDashboardStatus: false,
}),
).toMatchObject({
defaultBranch: 'main',
isFork: false,
repoFingerprint: expect.any(String),
});
});
it('enabled: should set main branch status if does not exist', async () => {
httpMock
.scope(baseUrl)
.get('/2.0/repositories/some/repo')
.reply(200, {
mainbranch: { name: 'main' },
uuid: '123',
full_name: 'some/repo',
})
.get('/2.0/repositories/some/repo/refs/branches/main')
.thrice()
.reply(200, {
name: 'main',
target: {
hash: 'main_hash',
},
})
.post('/2.0/repositories/some/repo/commit/main_hash/statuses/build', {
name: 'Mend.io Dashboard',
state: 'SUCCESSFUL',
key: 'Mend.io Dashboard',
description: '',
url: 'https://developer.mend.io/bitbucket/some/repo',
})
.reply(200)
.get(
'/2.0/repositories/some/repo/commit/main_hash/statuses?pagelen=100',
)
.reply(200, {
values: [
{
key: 'Some other status',
state: 'SUCCESSFUL',
},
],
})
.get(
'/2.0/repositories/some/repo/commit/main_hash/statuses?pagelen=100',
)
.reply(200, {
values: [
{
key: 'Some other status',
state: 'SUCCESSFUL',
},
{
key: 'Mend.io Dashboard',
state: 'SUCCESSFUL',
},
],
});
expect(
await bitbucket.initRepo({
repository: 'some/repo',
bbMendAppDashboardStatus: true,
}),
).toMatchObject({
defaultBranch: 'main',
isFork: false,
repoFingerprint: expect.any(String),
});
});
it('enabled: should skip creating main branch status if already exist', async () => {
httpMock
.scope(baseUrl)
.get('/2.0/repositories/some/repo')
.reply(200, {
mainbranch: { name: 'main' },
uuid: '123',
full_name: 'some/repo',
})
.get('/2.0/repositories/some/repo/refs/branches/main')
.reply(200, {
name: 'main',
target: {
hash: 'main_hash',
},
})
.get(
'/2.0/repositories/some/repo/commit/main_hash/statuses?pagelen=100',
)
.reply(200, {
values: [
{
key: 'Mend.io Dashboard',
state: 'SUCCESSFUL',
},
],
});
expect(
await bitbucket.initRepo({
repository: 'some/repo',
bbMendAppDashboardStatus: true,
}),
).toMatchObject({
defaultBranch: 'main',
isFork: false,
repoFingerprint: expect.any(String),
});
});
});
describe('bbUseDevelopmentBranch', () => {
it('not enabled: defaults to using main branch', async () => {
httpMock

View file

@ -187,6 +187,7 @@ export async function initRepo({
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
bbMendAppDashboardStatus,
bbUseDevelopmentBranch,
}: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`);
@ -224,6 +225,27 @@ export async function initRepo({
config.defaultBranch = mainBranch;
if (bbMendAppDashboardStatus) {
const statusName = 'Mend.io Dashboard';
const mendAppDashboardStatus = await getBranchStatusCheck(
config.defaultBranch,
statusName,
);
if (!mendAppDashboardStatus) {
logger.debug(`Creating branch status for ${statusName}`);
await setBranchStatus({
branchName: config.defaultBranch,
context: statusName,
description: '',
state: 'green',
url: `https://developer.mend.io/bitbucket/${repository}`,
});
}
}
config = {
...config,
owner: info.owner,
@ -433,6 +455,7 @@ async function getStatus(
)
).body.values;
}
// Returns the combined status for a branch.
export async function getBranchStatus(
branchName: string,

View file

@ -49,6 +49,7 @@ export interface RepoParams {
cloneSubmodules?: boolean;
cloneSubmodulesFilter?: string[];
ignorePrAuthor?: boolean;
bbMendAppDashboardStatus?: boolean;
bbUseDevelopmentBranch?: boolean;
includeMirrors?: boolean;
}
@ -101,8 +102,9 @@ export type PlatformPrOptions = {
autoApprove?: boolean;
automergeStrategy?: MergeStrategy;
azureWorkItemId?: number;
bbUseDefaultReviewers?: boolean;
bbAutoResolvePrTasks?: boolean;
bbMendAppDashboardStatus?: boolean;
bbUseDefaultReviewers?: boolean;
gitLabIgnoreApprovals?: boolean;
usePlatformAutomerge?: boolean;
forkModeDisallowMaintainerEdits?: boolean;