Skip to content

Commit b37691b

Browse files
committed
fix:format length
1 parent 400d8e2 commit b37691b

File tree

5 files changed

+87
-101
lines changed

5 files changed

+87
-101
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v1.1.1
2+
3+
### 🚀 Features
4+
5+
- Format output string to be more readable.
6+
- Scan and analyze GitHub organizations and repositories.
7+
18
## v1.1.0
29

310
### 🚀 Features

gha_cli/cli.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
from typing import Optional, List, Set, Dict, Union, Any
66

77
import click
8+
import coloredlogs
89
import yaml
910
from github import Github, Workflow
11+
from github.Organization import Organization
12+
from github.PaginatedList import PaginatedList
1013

11-
logging.basicConfig(level=logging.WARNING)
12-
logging.getLogger('github.Requester').setLevel(logging.WARNING)
14+
from gha_cli.scanner import Org, print_orgs_as_csvs
15+
16+
coloredlogs.install(level='INFO')
1317
logger = logging.getLogger()
1418

1519
ActionVersion = namedtuple('ActionVersion', ['name', 'current', 'latest'])
@@ -186,6 +190,8 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio
186190

187191

188192
@click.group(invoke_without_command=True)
193+
@click.option('-v', '--verbose', count=True,
194+
help="Increase verbosity, can be used multiple times to increase verbosity")
189195
@click.option(
190196
'--repo', default='.', show_default=True, type=str,
191197
help='Repository to analyze, can be a local directory or a {OWNER}/{REPO} format', )
@@ -196,7 +202,11 @@ def _get_workflow_file_content(self, repo_name: str, workflow_path: str) -> Unio
196202
'--compare-exact-versions', is_flag=True, default=False,
197203
help="Compare versions using all semantic and not only major versions, e.g., v1 will be upgraded to v1.2.3", )
198204
@click.pass_context
199-
def cli(ctx, repo: str, github_token: Optional[str], compare_exact_versions: bool):
205+
def cli(ctx, verbose: int, repo: str, github_token: Optional[str], compare_exact_versions: bool):
206+
if verbose == 1:
207+
coloredlogs.install(level='INFO')
208+
if verbose > 1:
209+
coloredlogs.install(level='DEBUG')
200210
ctx.ensure_object(dict)
201211
global FLAG_COMPARE_EXACT_VERSION
202212
FLAG_COMPARE_EXACT_VERSION = compare_exact_versions
@@ -259,5 +269,24 @@ def list_workflows(ctx):
259269
click.echo(f'{path} - {name}')
260270

261271

272+
@cli.command(help='Analyze organizations')
273+
@click.option('-x', '--exclude', multiple=True, default=[], help='Exclude orgs')
274+
@click.pass_context
275+
def analyze_orgs(ctx, exclude: Set[str] = None):
276+
gh_client: Github = ctx.obj['gh'].client
277+
exclude = exclude or {}
278+
exclude = set(exclude)
279+
current_user = gh_client.get_user()
280+
gh_orgs: PaginatedList[Organization] = current_user.get_orgs()
281+
logging.info(f'Analyzing {gh_orgs.totalCount} organizations')
282+
orgs: List[Org] = []
283+
for gh_org in gh_orgs:
284+
if gh_org.login in exclude:
285+
continue
286+
org = Org.from_github_org(gh_org)
287+
orgs.append(org)
288+
print_orgs_as_csvs(orgs)
289+
290+
262291
if __name__ == '__main__':
263292
cli(obj={})

gha_cli/scanner.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import logging
2-
import os
32
from dataclasses import dataclass, fields
43
from datetime import datetime, timedelta
5-
from typing import List, Optional, Set
4+
from typing import List
65

76
import click
8-
import coloredlogs
9-
from github import Github
107
from github.Organization import Organization
118
from github.PaginatedList import PaginatedList
129
from github.Repository import Repository
1310

14-
logging.basicConfig(level=logging.INFO)
15-
THIS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)))
16-
17-
coloredlogs.install(level='DEBUG')
11+
logger = logging.getLogger()
1812

1913

2014
@dataclass
@@ -93,28 +87,7 @@ def from_github_org(cls, org: Organization):
9387
)
9488

9589

96-
GITHUB_ACTION_NOT_PROVIDED_MSG = """GitHub connection token not provided.
97-
You might not be able to make the changes to remote repositories.
98-
You can provide it using GITHUB_TOKEN environment variable or --github-token option.
99-
"""
100-
101-
102-
@click.group(invoke_without_command=True)
103-
@click.option(
104-
'--github-token', default=os.getenv('GITHUB_TOKEN'), type=str, show_default=False,
105-
help='GitHub token to use, by default will use GITHUB_TOKEN environment variable')
106-
@click.pass_context
107-
def cli(ctx, github_token: Optional[str]):
108-
ctx.ensure_object(dict)
109-
if not github_token:
110-
click.secho(GITHUB_ACTION_NOT_PROVIDED_MSG, fg='yellow', err=True)
111-
exit(1)
112-
ctx.obj['gh'] = Github(github_token)
113-
if not ctx.invoked_subcommand:
114-
ctx.invoke(analyze_orgs)
115-
116-
117-
def _print_data(orgs: List[Org]):
90+
def print_orgs_as_csvs(orgs: List[Org]):
11891
if len(orgs) == 0:
11992
return
12093

@@ -123,33 +96,9 @@ def _print_data(orgs: List[Org]):
12396
click.echo(org.csv_str())
12497

12598
for org in orgs:
126-
logging.info(f'Analyzing repos for {org.name}')
99+
logger.info(f'Analyzing repos for {org.name}')
127100
if len(org.repositories) == 0:
128101
continue
129102
click.echo(org.repositories[0].csv_header())
130103
for repo in org.repositories:
131104
click.echo(repo.csv_str())
132-
133-
134-
@cli.command(help='Analyze organizations')
135-
@click.option('-x', '--exclude', multiple=True, default=[], help='Exclude orgs')
136-
@click.pass_context
137-
def analyze_orgs(ctx, exclude: Set[str] = None):
138-
gh_client: Github = ctx.obj['gh']
139-
exclude = exclude or {}
140-
exclude = set(exclude)
141-
current_user = gh_client.get_user()
142-
gh_orgs: PaginatedList[Organization] = current_user.get_orgs()
143-
logging.info(f'Analyzing {gh_orgs.totalCount} organizations')
144-
orgs: List[Org] = []
145-
for gh_org in gh_orgs:
146-
if gh_org.login in exclude:
147-
continue
148-
org = Org.from_github_org(gh_org)
149-
orgs.append(org)
150-
_print_data(orgs)
151-
152-
153-
if __name__ == '__main__':
154-
# print(Org(name='test', repositories=[], members_count=1, teams_count=1).csv_header())
155-
cli(obj={})

poetry.lock

Lines changed: 43 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ github-actions-cli = "gha_cli.cli:cli"
88

99
[tool.poetry]
1010
name = "github-actions-cli"
11-
version = "1.1.0"
11+
version = "1.1.1"
1212
description = "GitHub Actions CLI - allows updating workflows, etc."
1313
readme = "README.md"
1414
keywords = ["GitHub Actions", "CLI"]

0 commit comments

Comments
 (0)