Workflows CLI: add list command (#38816)
* hello world * better description * cli-table types * row types * just strings * lockfile
This commit is contained in:
parent
cd69c99ef6
commit
72a6f2b503
|
@ -3419,12 +3419,18 @@ importers:
|
|||
'@octokit/types':
|
||||
specifier: ^9.2.0
|
||||
version: 9.2.0
|
||||
'@types/cli-table':
|
||||
specifier: ^0.3.1
|
||||
version: 0.3.1
|
||||
'@types/uuid':
|
||||
specifier: ^9.0.1
|
||||
version: 9.0.1
|
||||
chalk:
|
||||
specifier: ^4.1.2
|
||||
version: 4.1.2
|
||||
cli-table:
|
||||
specifier: ^0.3.11
|
||||
version: 0.3.11
|
||||
commander:
|
||||
specifier: ^10.0.1
|
||||
version: 10.0.1
|
||||
|
@ -4997,7 +5003,7 @@ packages:
|
|||
'@babel/core': ^7.13.0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-skip-transparent-expression-wrappers': 7.18.9
|
||||
'@babel/plugin-proposal-optional-chaining': 7.18.9(@babel/core@7.17.8)
|
||||
dev: true
|
||||
|
@ -5009,7 +5015,7 @@ packages:
|
|||
'@babel/core': ^7.13.0
|
||||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-skip-transparent-expression-wrappers': 7.18.9
|
||||
'@babel/plugin-proposal-optional-chaining': 7.18.9(@babel/core@7.21.3)
|
||||
|
||||
|
@ -7059,8 +7065,8 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-module-imports': 7.18.6
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-module-imports': 7.21.4
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-remap-async-to-generator': 7.18.9(@babel/core@7.17.8)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
@ -7073,8 +7079,8 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-module-imports': 7.18.6
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-module-imports': 7.21.4
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-remap-async-to-generator': 7.18.9(@babel/core@7.21.3)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
@ -7682,7 +7688,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-builder-binary-assignment-operator-visitor': 7.18.9
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-transform-exponentiation-operator@7.18.6(@babel/core@7.21.3):
|
||||
|
@ -7693,7 +7699,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-builder-binary-assignment-operator-visitor': 7.18.9
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
|
||||
/@babel/plugin-transform-flow-strip-types@7.16.7(@babel/core@7.12.9):
|
||||
resolution: {integrity: sha512-mzmCq3cNsDpZZu9FADYYyfZJIOrSONmHcop2XEKPdBNMa4PDC4eEvcOvzZaCNcjKu72v0XQlA5y1g58aLRXdYg==}
|
||||
|
@ -7858,7 +7864,7 @@ packages:
|
|||
'@babel/core': 7.17.8
|
||||
'@babel/helper-compilation-targets': 7.20.7(@babel/core@7.17.8)
|
||||
'@babel/helper-function-name': 7.21.0
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-transform-function-name@7.18.9(@babel/core@7.21.3):
|
||||
|
@ -7870,7 +7876,7 @@ packages:
|
|||
'@babel/core': 7.21.3
|
||||
'@babel/helper-compilation-targets': 7.20.7(@babel/core@7.21.3)
|
||||
'@babel/helper-function-name': 7.21.0
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
|
||||
/@babel/plugin-transform-literals@7.16.0(@babel/core@7.12.9):
|
||||
resolution: {integrity: sha512-gQDlsSF1iv9RU04clgXqRjrPyyoJMTclFt3K1cjLmTKikc0s/6vE3hlDeEVC71wLTRu72Fq7650kABrdTc2wMQ==}
|
||||
|
@ -8027,7 +8033,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.12.9
|
||||
'@babel/helper-module-transforms': 7.21.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
babel-plugin-dynamic-import-node: 2.3.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
@ -8041,7 +8047,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-module-transforms': 7.21.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
babel-plugin-dynamic-import-node: 2.3.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
@ -8082,7 +8088,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-module-transforms': 7.21.2
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
@ -8095,7 +8101,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-module-transforms': 7.21.2
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
|
@ -8450,7 +8456,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-create-regexp-features-plugin': 7.19.0(@babel/core@7.17.8)
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-transform-named-capturing-groups-regex@7.19.1(@babel/core@7.21.3):
|
||||
|
@ -8461,7 +8467,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-create-regexp-features-plugin': 7.19.0(@babel/core@7.21.3)
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
|
||||
/@babel/plugin-transform-new-target@7.16.0(@babel/core@7.12.9):
|
||||
resolution: {integrity: sha512-fhjrDEYv2DBsGN/P6rlqakwRwIp7rBGLPbrKxwh7oVt5NNkIhZVOY2GRV+ULLsQri1bDqwDWnU3vhlmx5B2aCw==}
|
||||
|
@ -9734,7 +9740,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.17.8
|
||||
'@babel/helper-create-regexp-features-plugin': 7.19.0(@babel/core@7.17.8)
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
dev: true
|
||||
|
||||
/@babel/plugin-transform-unicode-regex@7.18.6(@babel/core@7.21.3):
|
||||
|
@ -9745,7 +9751,7 @@ packages:
|
|||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-create-regexp-features-plugin': 7.19.0(@babel/core@7.21.3)
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
|
||||
/@babel/polyfill@7.12.1:
|
||||
resolution: {integrity: sha512-X0pi0V6gxLi6lFZpGmeNa4zxtwEmCs42isWLNjZZDE0Y8yVfgu0T2OAHlzBbdYlqbW/YXVvoBHpATEM+goCj8g==}
|
||||
|
@ -10424,8 +10430,8 @@ packages:
|
|||
'@babel/core': ^7.0.0-0
|
||||
dependencies:
|
||||
'@babel/core': 7.21.3
|
||||
'@babel/helper-plugin-utils': 7.20.2
|
||||
'@babel/helper-validator-option': 7.18.6
|
||||
'@babel/helper-plugin-utils': 7.21.5
|
||||
'@babel/helper-validator-option': 7.21.0
|
||||
'@babel/plugin-transform-react-display-name': 7.16.7(@babel/core@7.21.3)
|
||||
'@babel/plugin-transform-react-jsx': 7.19.0(@babel/core@7.21.3)
|
||||
'@babel/plugin-transform-react-jsx-development': 7.16.7(@babel/core@7.21.3)
|
||||
|
@ -16124,6 +16130,10 @@ packages:
|
|||
'@types/node': 16.18.21
|
||||
dev: false
|
||||
|
||||
/@types/cli-table@0.3.1:
|
||||
resolution: {integrity: sha512-m3+6WWfSSl6zqoXy8uQQifbgqV7Gt6fsyWnHLgUWVtJQk75+OfUB+edSZ52YDj7leSiZtX7w1/E4w2x/Hb0orA==}
|
||||
dev: false
|
||||
|
||||
/@types/color-convert@2.0.0:
|
||||
resolution: {integrity: sha512-m7GG7IKKGuJUXvkZ1qqG3ChccdIM/qBBo913z+Xft0nKCX4hAU/IxKwZBU4cpRZ7GS5kV4vOblUkILtSShCPXQ==}
|
||||
dependencies:
|
||||
|
@ -23849,7 +23859,6 @@ packages:
|
|||
engines: {node: '>= 0.2.0'}
|
||||
dependencies:
|
||||
colors: 1.0.3
|
||||
dev: true
|
||||
|
||||
/cli-truncate@2.1.0:
|
||||
resolution: {integrity: sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==}
|
||||
|
@ -24074,7 +24083,6 @@ packages:
|
|||
/colors@1.0.3:
|
||||
resolution: {integrity: sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==}
|
||||
engines: {node: '>=0.1.90'}
|
||||
dev: true
|
||||
|
||||
/colors@1.1.2:
|
||||
resolution: {integrity: sha512-ENwblkFQpqqia6b++zLD/KUWafYlVY/UNnAp7oz7LY7E924wmpye416wBOmvv/HMWzl8gL1kJlfvId/1Dg176w==}
|
||||
|
@ -38861,7 +38869,7 @@ packages:
|
|||
is-touch-device: 1.0.1
|
||||
lodash: 4.17.21
|
||||
moment: 2.29.4
|
||||
object.assign: 4.1.4
|
||||
object.assign: 4.1.2
|
||||
object.values: 1.1.5
|
||||
prop-types: 15.8.1
|
||||
raf: 3.4.1
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
"@octokit/graphql": "4.8.0",
|
||||
"@octokit/graphql-schema": "^14.1.0",
|
||||
"@octokit/types": "^9.2.0",
|
||||
"@types/cli-table": "^0.3.1",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"chalk": "^4.1.2",
|
||||
"cli-table": "^0.3.11",
|
||||
"commander": "^10.0.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"figlet": "^1.6.0",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
import ora, { Ora } from 'ora';
|
||||
import chalk from 'chalk';
|
||||
import Table from 'cli-table';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -63,6 +64,13 @@ export class Logger {
|
|||
}
|
||||
}
|
||||
|
||||
static table( head: Array< string >, rows: Array< string[] > ) {
|
||||
if ( Logger.loggingLevel > LOGGING_LEVELS.silent ) {
|
||||
const table = new Table( { head, rows } );
|
||||
log( table.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
static endTask() {
|
||||
if (
|
||||
Logger.loggingLevel > LOGGING_LEVELS.silent &&
|
||||
|
|
|
@ -11,6 +11,7 @@ import chalk from 'chalk';
|
|||
import CodeFreeze from './code-freeze/commands';
|
||||
import Slack from './slack/commands/slack';
|
||||
import Changefile from './changefile';
|
||||
import WorkflowProfiler from './workflow-profiler/commands';
|
||||
import { Logger } from './core/logger';
|
||||
import { isGithubCI } from './core/environment';
|
||||
|
||||
|
@ -27,7 +28,8 @@ const program = new Command()
|
|||
.description( 'Monorepo utilities' )
|
||||
.addCommand( CodeFreeze )
|
||||
.addCommand( Slack )
|
||||
.addCommand( Changefile );
|
||||
.addCommand( Changefile )
|
||||
.addCommand( WorkflowProfiler );
|
||||
|
||||
program.exitOverride();
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { Command } from '@commander-js/extra-typings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import List from './list';
|
||||
|
||||
const program = new Command( 'workflows' )
|
||||
.description( 'Profile Github workflows' )
|
||||
.addCommand( List );
|
||||
|
||||
export default program;
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { Command } from '@commander-js/extra-typings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { getAllWorkflows } from '../../lib';
|
||||
import { Logger } from '../../../core/logger';
|
||||
|
||||
const program = new Command( 'list' )
|
||||
.description( 'List all Github workflows in a repository' )
|
||||
.option(
|
||||
'-o --owner <owner>',
|
||||
'Repository owner. Default: woocommerce',
|
||||
'woocommerce'
|
||||
)
|
||||
.option(
|
||||
'-n --name <name>',
|
||||
'Repository name. Default: woocommerce',
|
||||
'woocommerce'
|
||||
)
|
||||
.action( async ( { owner, name } ) => {
|
||||
Logger.startTask( 'Listing all workflows' );
|
||||
const allWorkflows = await getAllWorkflows( owner, name );
|
||||
Logger.notice(
|
||||
`There are ${ allWorkflows.length } workflows in the repository.`
|
||||
);
|
||||
Logger.table(
|
||||
[ 'Workflow Name', 'Id' ],
|
||||
allWorkflows.map( ( workflow ) => [ workflow.name, workflow.id ] )
|
||||
);
|
||||
Logger.endTask();
|
||||
} );
|
||||
|
||||
export default program;
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { octokitWithAuth } from '../../core/github/api';
|
||||
import { Logger } from '../../core/logger';
|
||||
|
||||
/**
|
||||
* Get all workflows from the WooCommerce repository.
|
||||
*
|
||||
* @param {string} owner - The owner of the repository.
|
||||
* @param {string} name - The name of the repository.
|
||||
* @return Workflows and total count
|
||||
*/
|
||||
export const getAllWorkflows = async ( owner: string, name: string ) => {
|
||||
let totalWorkflows = [];
|
||||
const request = async ( page = 1, per_page = 100 ) => {
|
||||
try {
|
||||
const result = await octokitWithAuth().request(
|
||||
'GET /repos/{owner}/{repo}/actions/workflows',
|
||||
{
|
||||
owner,
|
||||
repo: name,
|
||||
page,
|
||||
per_page,
|
||||
}
|
||||
);
|
||||
|
||||
const { data } = result;
|
||||
const { total_count, workflows } = data;
|
||||
totalWorkflows = totalWorkflows.concat( workflows );
|
||||
|
||||
if ( total_count > totalWorkflows.length ) {
|
||||
await request( page + 1 );
|
||||
}
|
||||
} catch ( e ) {
|
||||
Logger.error( e );
|
||||
}
|
||||
};
|
||||
|
||||
await request();
|
||||
return totalWorkflows;
|
||||
};
|
Loading…
Reference in New Issue