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

Add custom url option for Azure DevOps #88

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
28 changes: 15 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ora": "^5.4.1",
"prettier": "^2.6.2",
"snyk-api-ts-client": "^1.11.2",
"snyk-request-manager": "^1.8.2",
"snyk-request-manager": "^1.8.4",
"yargs": "^17.5.1"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions src/cmds/azure-devops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const builder = {
default: undefined,
desc: 'Your Org name in Azure Devops e.g. https://dev.azure.com/{OrgName}',
},
url: {
required: false,
default: 'https://dev.azure.com/',
desc: '[Optional] Your Azure DevOps host URL e.g. https://your.company.azure.com/\n',
},
projectKeys: {
required: false,
default: undefined,
Expand Down Expand Up @@ -107,6 +112,7 @@ export async function handler(argv: {
skipSnykMonitoredRepos: boolean;
importConfDir: string;
importFileRepoType: string;
url: string;
}): Promise<void> {
if (process.env.DEBUG) {
debug('DEBUG MODE ENABLED \n');
Expand Down Expand Up @@ -144,6 +150,7 @@ export async function handler(argv: {
OrgName: argv.org,
projectKeys: argv.projectKeys?.toString().split(','),
repo: argv.repo,
url: argv.url
};

const azureDevopsTask = new AzureDevops(scmTarget);
Expand Down
12 changes: 7 additions & 5 deletions src/lib/azure-devops/azure-devops-contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const fetchAzureDevopsContributors = async (
azureInfo.projectKeys = [];
projectList = projectList.concat(
await fetchAzureProjects(
azureDefaultUrl,
azureInfo.url ? azureInfo.url : azureDefaultUrl,
azureInfo.OrgName,
azureInfo.token,
),
Expand Down Expand Up @@ -127,8 +127,9 @@ export const fetchAzureContributorsForRepo = async (
debug(
`Fetching single repo contributor from Azure Devops. Project ${repo.project.key} - Repo ${repo.name}\n`,
);
const azureUrl = AzureInfo.url ? AzureInfo.url : azureDefaultUrl;
const response = await getRepoCommits(
azureDefaultUrl + AzureInfo.OrgName,
azureUrl + AzureInfo.OrgName,
repo.project.key,
repo.name,
AzureInfo.token,
Expand Down Expand Up @@ -217,8 +218,9 @@ export const fetchAzureReposForProjects = async (
if (AzureInfo.projectKeys) {
try {
for (let i = 0; i < AzureInfo.projectKeys.length; i++) {
const azureUrl = AzureInfo.url ? AzureInfo.url : azureDefaultUrl
const repos = await getReposPerProjects(
azureDefaultUrl + AzureInfo.OrgName,
azureUrl + AzureInfo.OrgName,
AzureInfo.projectKeys[i],
AzureInfo.token,
);
Expand Down Expand Up @@ -256,13 +258,13 @@ export const fetchAzureReposForProjects = async (
};

export const fetchAzureProjects = async (
azureDefaultUrl: string,
azureUrl: string,
OrgName: string,
token: string,
): Promise<Project[]> => {
const projectList: Project[] = [];
try {
const projects = await getProjects(azureDefaultUrl, OrgName, token);
const projects = await getProjects(azureUrl, OrgName, token);
const result = await projects.text();
const parsedResponse = JSON.parse(result).value;
parsedResponse.map((project: { name: string; id: string }) => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface AzureDevopsTarget {
OrgName: string;
projectKeys?: string[];
repo?: string;
url?: string;
}

export interface BitbucketCloudTarget {
Expand Down