Skip to content
Merged
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
49 changes: 37 additions & 12 deletions augur/api/view/api.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
from flask import request, jsonify, redirect, url_for, flash, current_app
import logging
import re

from flask import flash, current_app, jsonify, redirect, request, url_for

Check warning on line 4 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused current_app imported from flask (unused-import) Raw Output: augur/api/view/api.py:4:0: W0611: Unused current_app imported from flask (unused-import)
from flask_login import current_user, login_required

from augur.application.db.models import Repo, RepoGroup, UserGroup, UserRepo

Check warning on line 7 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused RepoGroup imported from augur.application.db.models (unused-import) Raw Output: augur/api/view/api.py:7:0: W0611: Unused RepoGroup imported from augur.application.db.models (unused-import)
from augur.tasks.frontend import add_github_orgs_and_repos, parse_org_and_repo_name, parse_org_name, add_gitlab_repos
from .utils import *
from ..server import app
from augur.application.db.session import DatabaseSession

Check warning on line 8 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0611: Unused DatabaseSession imported from augur.application.db.session (unused-import) Raw Output: augur/api/view/api.py:8:0: W0611: Unused DatabaseSession imported from augur.application.db.session (unused-import)
from augur.tasks.frontend import (
add_github_orgs_and_repos,
add_gitlab_repos,
parse_org_and_repo_name,
parse_org_name
)

from ..server import app
from .utils import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it your editor that reformatted a lot of these imports? I dont see anything crazy wrong just wanted to check where this came from

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pylint check was failing coz of the order of imports. So had to make some tweaks


@app.route('/cache/file/')
@app.route('/cache/file/<path:file>')
def cache(file=None):
if file is None:
return redirect(url_for('static', filename="cache"))
return redirect(url_for('static', filename="cache/" + toCacheFilename(file, False)))

Check warning on line 24 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'toCacheFilename' (undefined-variable) Raw Output: augur/api/view/api.py:24:58: E0602: Undefined variable 'toCacheFilename' (undefined-variable)


def add_existing_org_to_group(session, user_id, group_name, rg_id):

logger.info("Adding existing org to group")

Check warning on line 29 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'logger' (undefined-variable) Raw Output: augur/api/view/api.py:29:4: E0602: Undefined variable 'logger' (undefined-variable)

group_id = UserGroup.convert_group_name_to_id(session, user_id, group_name)
if group_id is None:
return False

repos = session.query(Repo).filter(Repo.repo_group_id == rg_id).all()
logger.info("Length of repos in org: " + str(len(repos)))

Check warning on line 36 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'logger' (undefined-variable) Raw Output: augur/api/view/api.py:36:4: E0602: Undefined variable 'logger' (undefined-variable)
for repo in repos:
result = UserRepo.insert(session, repo.repo_id, group_id)
if not result:
logger.info("Failed to add repo to group")

Check warning on line 40 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'logger' (undefined-variable) Raw Output: augur/api/view/api.py:40:12: E0602: Undefined variable 'logger' (undefined-variable)



Expand Down Expand Up @@ -155,21 +164,37 @@
group = request.args.get("group_name")
repo = request.args.get("repo_id")

if not repo:
flash("No repo id provided")
if not group:
flash("No group name provided")

repo = int(repo)

if not repo or not group:
if not repo:
flash("No repo id provided")
if not group:
flash("No group name provided")
# Staying on same page instead of redirecting to settings
return redirect(url_for("user_group_view", group=group))

try:
repo_id = int(repo)
except (TypeError, ValueError) as e:
flash("Invalid repo id provided")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also print a log message here with the actual exception so the admin of augur knows what specifically happened.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated please check


logging.error(f"Invalid repo id provided for repo '{repo}'. Error: {e}")


return redirect(url_for("user_group_view", group=group))

result = current_user.remove_repo(group, repo)[0]
result = current_user.remove_repo(group, repo_id)[0]

if result:
flash(f"Successfully removed repo {repo} from group {group}")
else:
flash("An error occurred removing repo from group")

return redirect(url_for("user_group_view") + f"?group={group}")

return redirect(url_for("user_group_view", group=group))




@app.route('/account/application/deauthorize')
@login_required
Expand Down Expand Up @@ -209,5 +234,5 @@
"""
@app.route('/requests/report/wait/<id>')
def wait_for_report_request(id):
requestReports(id)

Check warning on line 237 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'requestReports' (undefined-variable) Raw Output: augur/api/view/api.py:237:4: E0602: Undefined variable 'requestReports' (undefined-variable)
return jsonify(report_requests[id])

Check warning on line 238 in augur/api/view/api.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'report_requests' (undefined-variable) Raw Output: augur/api/view/api.py:238:19: E0602: Undefined variable 'report_requests' (undefined-variable)
Loading