Skip to content

Commit

Permalink
feat(manager/composer): Use bitbucket-tags for vcs repos if it has bi…
Browse files Browse the repository at this point in the history
…tbucket.org URL (#24096)

Co-authored-by: Rhys Arkins <[email protected]>
  • Loading branch information
BernhardK91 and rarkins authored Sep 6, 2023
1 parent a966aea commit 2e57646
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/modules/manager/composer/__fixtures__/composer6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "acme/git-sources",
"description": "Fetch Packages via bitbucket-tags",
"repositories": [
{
"name": "awesome/bitbucket-repo1",
"type": "vcs",
"url": "https://bitbucket.org/awesome/bitbucket-repo1.git"
},
{
"name": "awesome/bitbucket-repo2",
"type": "vcs",
"url": "[email protected]/awesome/bitbucket-repo2.git"
},
{
"name": "awesome/bitbucket-repo3",
"type": "vcs",
"url": "[email protected]/awesome/bitbucket-repo3"
}
],
"require": {
"awesome/bitbucket-repo1": "dev-trunk",
"awesome/bitbucket-repo2": "dev-trunk",
"awesome/bitbucket-repo3": "dev-trunk"
},
"autoload": {
"psr-0": {
"Acme": "src/"
}
}
}
30 changes: 30 additions & 0 deletions lib/modules/manager/composer/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const requirements2 = Fixtures.get('composer2.json');
const requirements3 = Fixtures.get('composer3.json');
const requirements4 = Fixtures.get('composer4.json');
const requirements5 = Fixtures.get('composer5.json');
const requirements6 = Fixtures.get('composer6.json');
const requirements5Lock = Fixtures.get('composer5.lock');

describe('modules/manager/composer/extract', () => {
Expand Down Expand Up @@ -215,6 +216,35 @@ describe('modules/manager/composer/extract', () => {
});
});

it('extracts bitbucket repositories and registryUrls', async () => {
const res = await extractPackageFile(requirements6, packageFile);
expect(res).toEqual({
deps: [
{
currentValue: 'dev-trunk',
datasource: 'bitbucket-tags',
depName: 'awesome/bitbucket-repo1',
depType: 'require',
packageName: 'awesome/bitbucket-repo1',
},
{
currentValue: 'dev-trunk',
datasource: 'bitbucket-tags',
depName: 'awesome/bitbucket-repo2',
depType: 'require',
packageName: 'awesome/bitbucket-repo2',
},
{
currentValue: 'dev-trunk',
datasource: 'bitbucket-tags',
depName: 'awesome/bitbucket-repo3',
depType: 'require',
packageName: 'awesome/bitbucket-repo3',
},
],
});
});

it('extracts object repositories and registryUrls with lock file', async () => {
fs.readLocalFile.mockResolvedValue(requirements5Lock);
const res = await extractPackageFile(requirements5, packageFile);
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/composer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Category } from '../../../constants';
import { BitbucketTagsDatasource } from '../../datasource/bitbucket-tags';
import { GitTagsDatasource } from '../../datasource/git-tags';
import { PackagistDatasource } from '../../datasource/packagist';
import { updateArtifacts } from './artifacts';
Expand All @@ -24,6 +25,7 @@ export const defaultConfig = {
export const categories: Category[] = ['php'];

export const supportedDatasources = [
BitbucketTagsDatasource.id,
GitTagsDatasource.id,
PackagistDatasource.id,
];
16 changes: 16 additions & 0 deletions lib/modules/manager/composer/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '../../../logger';
import { readLocalFile } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import { Json, LooseArray, LooseRecord } from '../../../util/schema-utils';
import { BitbucketTagsDatasource } from '../../datasource/bitbucket-tags';
import { GitTagsDatasource } from '../../datasource/git-tags';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { PackagistDatasource } from '../../datasource/packagist';
Expand Down Expand Up @@ -60,6 +61,10 @@ export type NamedRepo = z.infer<typeof NamedRepo>;
const DisablePackagist = z.object({ type: z.literal('disable-packagist') });
export type DisablePackagist = z.infer<typeof DisablePackagist>;

const bitbucketUrlRegex = regEx(
/^(?:https:\/\/|git@)bitbucket\.org[/:](?<packageName>[^/]+\/[^/]+?)(?:\.git)?$/
);

export const ReposRecord = LooseRecord(z.union([Repo, z.literal(false)]), {
onError: ({ error: err }) => {
logger.debug({ err }, 'Composer: error parsing repositories object');
Expand Down Expand Up @@ -304,6 +309,17 @@ export const ComposerExtract = z

const gitRepo = gitRepos[depName];
if (gitRepo) {
const bitbucketMatchGroups = bitbucketUrlRegex.exec(
gitRepo.url
)?.groups;

if (bitbucketMatchGroups) {
dep.datasource = BitbucketTagsDatasource.id;
dep.packageName = bitbucketMatchGroups.packageName;
deps.push(dep);
continue;
}

dep.datasource = GitTagsDatasource.id;
dep.packageName = gitRepo.url;
deps.push(dep);
Expand Down

0 comments on commit 2e57646

Please sign in to comment.