Skip to content
Snippets Groups Projects
Commit fe03c79b authored by Ben Gamari's avatar Ben Gamari :turtle:
Browse files

gitlab-utils/spam_util: Update gitlab-python

parent c696e476
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ def cli(): ...@@ -53,7 +53,7 @@ def cli():
@click.option('-o', '--output', type=click.File('w')) @click.option('-o', '--output', type=click.File('w'))
def dump_snippets(output) -> None: def dump_snippets(output) -> None:
gl = gitlab.Gitlab.from_config() gl = gitlab.Gitlab.from_config()
with click.progressbar(gl.snippets.public(as_list=False, all=True, lazy=True), label='Listing spam snippets') as snippets: with click.progressbar(gl.snippets.public(iterator=True, all=True, lazy=True), label='Listing spam snippets') as snippets:
for x in snippets: for x in snippets:
u = gl.users.get(x.author['id']) u = gl.users.get(x.author['id'])
if not good_user(gl, u): if not good_user(gl, u):
...@@ -71,7 +71,7 @@ def parse_user_list(input) -> Iterator[UserName]: ...@@ -71,7 +71,7 @@ def parse_user_list(input) -> Iterator[UserName]:
@click.option('-o', '--output', type=click.File('w')) @click.option('-o', '--output', type=click.File('w'))
def list_bad_users(output) -> None: def list_bad_users(output) -> None:
gl = gitlab.Gitlab.from_config() gl = gitlab.Gitlab.from_config()
with click.progressbar(gl.users.list(as_list=False, all=True, lazy=True), label='Listing users') as users: with click.progressbar(gl.users.list(iterator=True, all=True, lazy=True), label='Listing users') as users:
for user in users: for user in users:
try: try:
if user.username in USER_WHITELIST: if user.username in USER_WHITELIST:
...@@ -89,7 +89,7 @@ def find_bad_projects(output) -> None: ...@@ -89,7 +89,7 @@ def find_bad_projects(output) -> None:
'-phuc-', '-tai-', '-app-', 'thuyet-', '-ly-', 'huong' '-phuc-', '-tai-', '-app-', 'thuyet-', '-ly-', 'huong'
} }
gl = gitlab.Gitlab.from_config() gl = gitlab.Gitlab.from_config()
with click.progressbar(gl.projects.list(as_list=False, all=True, lazy=True), label='Listing projects') as projects: with click.progressbar(gl.projects.list(iterator=True, all=True, lazy=True), label='Listing projects') as projects:
for proj in projects: for proj in projects:
try: try:
if proj.owner['username'] in USER_WHITELIST: if proj.owner['username'] in USER_WHITELIST:
...@@ -129,7 +129,7 @@ def good_user(gl, u) -> bool: ...@@ -129,7 +129,7 @@ def good_user(gl, u) -> bool:
@click.option('--dryrun', is_flag=True) @click.option('--dryrun', is_flag=True)
def reject_pending_requests(dryrun: bool): def reject_pending_requests(dryrun: bool):
gl = gitlab.Gitlab.from_config() gl = gitlab.Gitlab.from_config()
with click.progressbar(gl.users.list(as_list=False, all=True, lazy=True, without_projects=True), label='Listing users') as users: with click.progressbar(gl.users.list(iterator=True, all=True, lazy=True, without_projects=True), label='Listing users') as users:
for u in users: for u in users:
if u.state == 'blocked_pending_approval': if u.state == 'blocked_pending_approval':
logging.info(f'Rejecting approval request for {u.username}') logging.info(f'Rejecting approval request for {u.username}')
...@@ -190,7 +190,7 @@ def inactive_user(gl, u, thresh: timedelta = timedelta(days=180)) -> bool: ...@@ -190,7 +190,7 @@ def inactive_user(gl, u, thresh: timedelta = timedelta(days=180)) -> bool:
@click.option('-o', '--output', type=click.File('w')) @click.option('-o', '--output', type=click.File('w'))
def list_inactive_users(output) -> None: def list_inactive_users(output) -> None:
gl = gitlab.Gitlab.from_config() gl = gitlab.Gitlab.from_config()
with click.progressbar(gl.users.list(as_list=False, all=True, lazy=True), label='Listing inactive users') as users: with click.progressbar(gl.users.list(iterator=True, all=True, lazy=True), label='Listing inactive users') as users:
for u in users: for u in users:
if inactive_user(gl, u) and not good_user(gl, u): if inactive_user(gl, u) and not good_user(gl, u):
output.write('%-20s # %s\n' % (u.username, u.last_sign_in_at)) output.write('%-20s # %s\n' % (u.username, u.last_sign_in_at))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment