Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/another-guy/solo
Browse files Browse the repository at this point in the history
  • Loading branch information
another-guy committed Jan 7, 2025
2 parents e3472e5 + c40c624 commit 37c5cc1
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 144 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ npm install -g .
* NPM
*`npm-audit`
* ADO
* 🔨 `ado-list-remote-repos-hierarchy`
*`ado-list-remote-repos`
* 🧠 `ado-list-deploys`
* SCV
Expand Down
25 changes: 12 additions & 13 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "https://github.com/another-guy/solo"
},
"dependencies": {
"axios": "^1.7.7",
"axios": "^1.7.9",
"chalk": "^4.1.2",
"cli-table3": "^0.6.5",
"commander": "^12.1.0",
Expand All @@ -28,7 +28,7 @@
"typescript": "^5.7.2"
},
"devDependencies": {
"@types/node": "^22.9.3",
"@types/node": "^22.10.2",
"@types/semver": "^7.5.8"
}
}
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

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

97 changes: 0 additions & 97 deletions src/commands/command-ado-list-remote-repos-hierarchy.ts

This file was deleted.

74 changes: 62 additions & 12 deletions src/commands/command-ado-list-remote-repos.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,92 @@
import axios, { AxiosResponse } from 'axios';
import { createExecutionContext, parseCommonOptions } from '../cli';
import { renderTable } from '../cli/render-table';
import { AdoListRepositoriesResponse, AdoRepository } from '../types';
import { AdoListProjectsResponse, AdoListRepositoriesResponse, AdoRepository } from '../types';
import { commonAdoOptions } from './ado-options';
import { CliCommandMetadata } from './cli-option';
import { CliCommandMetadata, CliOption } from './cli-option';

const commandName = `ado-list-remote-repos`;

const sortOption: CliOption = {
short: 's',
long: `sort`,
codeName: `sort`,
description: `Column to sort by.`,
exampleValue: `project or repo`,
defaultValue: `project`,
};

const { project, ...otherCommonOptions } = commonAdoOptions;
const listRemoteReposCommandOptions = {
...commonAdoOptions,
...otherCommonOptions,
sortOption,
};

async function adoListRemoteReposAsyncCommand(this: any, str: any, options: any) {
const executionContext = createExecutionContext(parseCommonOptions(options));
const { organization, project, login, token } = str;
const { organization, project, login, token, sort } = str;
const { logger } = executionContext;

const org = organization || listRemoteReposCommandOptions.organization.defaultValue;
const proj = project || listRemoteReposCommandOptions.project.defaultValue;
const listRepositoriesResponse = await axios.get<{}, AxiosResponse<AdoListRepositoriesResponse>>(`https://dev.azure.com/${org}/${proj}/_apis/git/repositories`, {
const listProjectsResponse = await axios.get<{}, AxiosResponse<AdoListProjectsResponse>>(`https://dev.azure.com/${org}/_apis/projects`, {
headers: {
Authorization: `Basic ${Buffer.from(`${login}:${token}`).toString('base64')}`,
},
});

if (listRepositoriesResponse.status < 200 && listRepositoriesResponse.status >= 300)
// TODO: refactor into axios wrapper?
throw new Error(`Failed to list repositories. Status: ${listRepositoriesResponse.status}.`);
const xPromises = listProjectsResponse
.data
.value
.filter((adoProject) => !project ? true : adoProject.name === project)
.map(async (adoProject) => {
try {
const listRepositoriesResponse = await axios.get<{}, AxiosResponse<AdoListRepositoriesResponse>>(`https://dev.azure.com/${org}/${adoProject.id}/_apis/git/repositories`, {
headers: {
Authorization: `Basic ${Buffer.from(`${login}:${token}`).toString('base64')}`,
},
});

if (listRepositoriesResponse.status < 200 && listRepositoriesResponse.status >= 300)
// TODO: refactor into axios wrapper?
throw new Error(`Failed to list repositories. Status: ${listRepositoriesResponse.status}.`);

return { adoProject, adoRepos: listRepositoriesResponse.data.value };
} catch (e) {
return { adoProject, error: e };
}
});
const promiseResults = await Promise.allSettled(xPromises);

const columnDefs = [
{ title: 'repo id', width: 38, selector: (repo: AdoRepository) => repo.id },
{ title: 'project', width: 40, selector: (repo: AdoRepository) => repo.project.name },
// { title: 'repo id', width: 38, selector: (repo: AdoRepository) => repo.id },
{ title: 'repo name', width: 40, selector: (repo: AdoRepository) => repo.name },
{ title: 'remoteUrl', width: 160, selector: (repo: AdoRepository) => repo.remoteUrl },
];
const rows =
promiseResults.reduce(
(result, promiseResult) => {
if (promiseResult.status !== 'rejected') {
(promiseResult.value.adoRepos || []).forEach((repo) => {
result.push(repo);
});
}
return result;
},
[] as AdoRepository[],
)
.sort((repo1, repo2) => {
const select = (repo: AdoRepository) =>
sort === 'repo' ? repo.name :
sort === 'project' ? repo.project.name :
repo.name;
return select(repo1).localeCompare(select(repo2));
});

console.log(renderTable(
columnDefs,
listRepositoriesResponse.data.value,
));
rows,
))
};

export const command: CliCommandMetadata = {
Expand Down
Loading

0 comments on commit 37c5cc1

Please sign in to comment.