Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 54 additions & 1 deletion plugins/renovate-backend/src/wrapper/platforms/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { getPlatformEnvs } from './index';
import { mockDeep } from 'jest-mock-extended';
import { DefaultGithubCredentialsProvider } from '@backstage/integration';
import { DefaultGithubCredentialsProvider, DefaultAzureDevOpsCredentialsProvider } from '@backstage/integration';
import { mockServices } from '@backstage/backend-test-utils';

const githubCredentialProvider = mockDeep<DefaultGithubCredentialsProvider>();
DefaultGithubCredentialsProvider.fromIntegrations = jest
.fn()
.mockReturnValue(githubCredentialProvider);

const azureCredentialProvider = mockDeep<DefaultAzureDevOpsCredentialsProvider>();
DefaultAzureDevOpsCredentialsProvider.fromIntegrations = jest
.fn()
.mockReturnValue(azureCredentialProvider);

describe('wrapper/platforms', () => {
beforeEach(() => {
githubCredentialProvider.getCredentials.mockReset();
azureCredentialProvider.getCredentials.mockReset();
});

it('throw if platform could not be identified', async () => {
Expand Down Expand Up @@ -153,4 +159,51 @@ describe('wrapper/platforms', () => {
RENOVATE_TOKEN: 'bbbbbbbbbb',
});
});

it('return env for azure devops with token', async () => {
const rootConfig = mockServices.rootConfig({
data: {
integrations: {
github: [
{
host: 'github.com',
token: 'aaaaaa',
},
],
azure: [
{
host: 'dev.azure.com',
token: 'cccccccc',
},
],
},
},
});
githubCredentialProvider.getCredentials.mockResolvedValue({
token: 'aaaaaa',
type: 'token',
});
azureCredentialProvider.getCredentials.mockResolvedValue({
token: 'cccccccc',
type: 'token',
});
await expect(
getPlatformEnvs(
{
host: 'dev.azure.com',
repository: 'myOrg/myRepo',
},
{
rootConfig,
logger: mockServices.logger.mock(),
},
),
).resolves.toEqual({
RENOVATE_ENDPOINT: 'https://dev.azure.com',
GITHUB_COM_TOKEN: 'aaaaaa',
RENOVATE_PLATFORM: 'azure',
RENOVATE_REPOSITORIES: 'myOrg/myRepo',
RENOVATE_TOKEN: 'cccccccc',
});
});
});
20 changes: 20 additions & 0 deletions plugins/renovate-backend/src/wrapper/platforms/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DefaultGitlabCredentialsProvider,
ScmIntegrations,
DefaultAzureDevOpsCredentialsProvider,
} from '@backstage/integration';
import is from '@sindresorhus/is';
import { PlatformEnvsOptions } from './types';
Expand Down Expand Up @@ -52,6 +53,25 @@ export async function getPlatformEnvs(
env.RENOVATE_REPOSITORIES = target.repository;
}
break;
case 'azure':
case 'azure-devops':
case 'azuredevops':
Comment on lines +57 to +58
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case 'azure-devops':
case 'azuredevops':

I think this would be only azure https://github.com/backstage/backstage/blob/315ab530cc8f5a88e58de245998ae10bbea9b3b8/packages/integration/src/azure/AzureIntegration.ts#L42

{
const cred = await DefaultAzureDevOpsCredentialsProvider.fromIntegrations(
integrations,
).getCredentials({ url });
const azureIntegrationConfig = requireConfigVariable(
integrations.azure.byHost(target.host)?.config,
errMsg,
);
env.RENOVATE_PLATFORM = 'azure';
// Use configured apiBaseUrl if present, otherwise fall back to host
env.RENOVATE_ENDPOINT =
azureIntegrationConfig.apiBaseUrl ?? `https://${target.host}`;
Comment on lines +68 to +70
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Use configured apiBaseUrl if present, otherwise fall back to host
env.RENOVATE_ENDPOINT =
azureIntegrationConfig.apiBaseUrl ?? `https://${target.host}`;
env.RENOVATE_ENDPOINT = `https://${target.host}`;

There is no apiBaseUrl in azureIntegrationConfig

env.RENOVATE_TOKEN = requireConfigVariable(cred.token, errMsg);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
env.RENOVATE_TOKEN = requireConfigVariable(cred.token, errMsg);
env.RENOVATE_TOKEN = requireConfigVariable(cred?.token, errMsg);

cred can be undefined

env.RENOVATE_REPOSITORIES = target.repository;
}
break;
default:
throw new Error(`Unsupported platform type ${integration.type}`);
}
Expand Down