Skip to content

Commit

Permalink
feat(manager/azure-pipelines): Add Azure DevOps project support (#27277)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjackstewart committed Mar 10, 2024
1 parent 17c69a8 commit 3313b72
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 62 deletions.
192 changes: 141 additions & 51 deletions lib/modules/manager/azure-pipelines/extract.spec.ts
Expand Up @@ -35,11 +35,14 @@ describe('modules/manager/azure-pipelines/extract', () => {
describe('extractRepository()', () => {
it('should extract repository information', () => {
expect(
extractRepository({
type: 'github',
name: 'user/repo',
ref: 'refs/tags/v1.0.0',
}),
extractRepository(
{
type: 'github',
name: 'user/repo',
ref: 'refs/tags/v1.0.0',
},
'user',
),
).toMatchObject({
depName: 'user/repo',
packageName: 'https://github.com/user/repo.git',
Expand All @@ -48,30 +51,39 @@ describe('modules/manager/azure-pipelines/extract', () => {

it('should return null when repository type is not github', () => {
expect(
extractRepository({
type: 'bitbucket',
name: 'user/repo',
ref: 'refs/tags/v1.0.0',
}),
extractRepository(
{
type: 'bitbucket',
name: 'user/repo',
ref: 'refs/tags/v1.0.0',
},
'user/repo',
),
).toBeNull();
});

it('should return null when reference is not defined specified', () => {
expect(
extractRepository({
type: 'github',
name: 'user/repo',
}),
extractRepository(
{
type: 'github',
name: 'user/repo',
},
'user/repo',
),
).toBeNull();
});

it('should return null when reference is invalid tag format', () => {
expect(
extractRepository({
type: 'github',
name: 'user/repo',
ref: 'refs/head/master',
}),
extractRepository(
{
type: 'github',
name: 'user/repo',
ref: 'refs/head/master',
},
'user/repo',
),
).toBeNull();
});

Expand All @@ -82,43 +94,91 @@ describe('modules/manager/azure-pipelines/extract', () => {
});

expect(
extractRepository({
type: 'git',
name: 'project/repo',
ref: 'refs/tags/v1.0.0',
}),
extractRepository(
{
type: 'git',
name: 'project/repo',
ref: 'refs/tags/v1.0.0',
},
'otherProject/otherRepo',
),
).toMatchObject({
depName: 'project/repo',
packageName: 'https://dev.azure.com/renovate-org/project/_git/repo',
});
});

it('should return null if repository type is git and project not in name', () => {
it('should extract Azure repository information if project is not in name but is in the config repository', () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://dev.azure.com/renovate-org',
});

expect(
extractRepository({
type: 'git',
name: 'repo',
ref: 'refs/tags/v1.0.0',
}),
extractRepository(
{
type: 'git',
name: 'repo',
ref: 'refs/tags/v1.0.0',
},
'project/otherrepo',
),
).toMatchObject({
depName: 'project/repo',
packageName: 'https://dev.azure.com/renovate-org/project/_git/repo',
});
});

it('should return null if repository type is git and project not in name nor in config repository name', () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://dev.azure.com/renovate-org',
});

expect(
extractRepository(
{
type: 'git',
name: 'repo',
ref: 'refs/tags/v1.0.0',
},
'',
),
).toBeNull();
});

it('should return null if repository type is git and currentRepository is undefined', () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://dev.azure.com/renovate-org',
});

expect(
extractRepository(
{
type: 'git',
name: 'repo',
ref: 'refs/tags/v1.0.0',
},
undefined,
),
).toBeNull();
});

it('should extract return null for git repo type if platform not Azure', () => {
it('should return null for git repo type if platform not Azure', () => {
GlobalConfig.set({
platform: 'github',
});

expect(
extractRepository({
type: 'git',
name: 'project/repo',
ref: 'refs/tags/v1.0.0',
}),
extractRepository(
{
type: 'git',
name: 'project/repo',
ref: 'refs/tags/v1.0.0',
},
'',
),
).toBeNull();
});
});
Expand Down Expand Up @@ -153,11 +213,15 @@ describe('modules/manager/azure-pipelines/extract', () => {

describe('extractPackageFile()', () => {
it('returns null for invalid azure pipelines files', () => {
expect(extractPackageFile('}', azurePipelinesFilename)).toBeNull();
expect(
extractPackageFile('}', azurePipelinesFilename, { repository: 'repo' }),
).toBeNull();
});

it('extracts dependencies', () => {
const res = extractPackageFile(azurePipelines, azurePipelinesFilename);
const res = extractPackageFile(azurePipelines, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toMatchObject([
{
depName: 'user/repo',
Expand All @@ -180,7 +244,9 @@ describe('modules/manager/azure-pipelines/extract', () => {

it('should return null when there is no dependency found', () => {
expect(
extractPackageFile(azurePipelinesNoDependency, azurePipelinesFilename),
extractPackageFile(azurePipelinesNoDependency, azurePipelinesFilename, {
repository: 'repo',
}),
).toBeNull();
});

Expand All @@ -196,7 +262,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -219,7 +287,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -242,7 +312,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -264,7 +336,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -286,7 +360,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -308,7 +384,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -330,7 +408,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -352,7 +432,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -373,7 +455,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -392,7 +476,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -409,7 +495,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
inputs:
script: 'echo Hello World'
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res?.deps).toEqual([
{
depName: 'Bash',
Expand All @@ -424,7 +512,9 @@ describe('modules/manager/azure-pipelines/extract', () => {
steps:
- bash: 'echo Hello World';
`;
const res = extractPackageFile(packageFile, azurePipelinesFilename);
const res = extractPackageFile(packageFile, azurePipelinesFilename, {
repository: 'repo',
});
expect(res).toBeNull();
});
});
Expand Down

0 comments on commit 3313b72

Please sign in to comment.