Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Install Chmod Issue as Well as SQL Syntax #2737

Merged
merged 3 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions augur/api/metrics/repo_meta.py
Expand Up @@ -258,14 +258,22 @@ def nadia_project_labeling_badge(repo_group_id, repo_id=None):
SELECT repo_id, COUNT(*) AS repo_contributor_count FROM
(
SELECT cntrb_id, repo_id, COUNT(*) FROM explorer_contributor_actions GROUP BY cntrb_id, repo_id
) a GROUP BY repo_id
WHERE repo_id = :repo_id_param
ORDER BY repo_id;
) a
WHERE repo_id= :repo_id_param
GROUP BY repo_id
ORDER BY repo_id;
""").bindparams(repo_id_param=repo_id)

with current_app.engine.connect() as conn:
raw_df = pd.read_sql(get_unique_contributor_ids_sql, conn)
unique_contribs = int(raw_df.at[0,1])
#print(raw_df)
try:
unique_contribs = int(raw_df.at[0,'repo_contributor_count'])
except KeyError:
result = {
"nadia_badge_level": "unknown"
}
return pd.DataFrame(result, index=[0])

stars_count_SQL = s.sql.text("""
SELECT repo_name, stars_count AS stars
Expand Down
4 changes: 3 additions & 1 deletion augur/application/cli/db.py
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: MIT

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
C0114: Missing module docstring (missing-module-docstring)

import os
from os import environ, chmod, path, getenv, stat
import logging
from sys import exit

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0622: Redefining built-in 'exit' (redefined-builtin)

Expand All @@ -11,6 +12,7 @@
import pandas as pd
import json
import re
import stat
IsaacMilarky marked this conversation as resolved.
Show resolved Hide resolved

from augur.application.cli import test_connection, test_db_connection, with_database, DatabaseContext

Expand Down Expand Up @@ -41,14 +43,14 @@
NOTE: The Group ID must already exist in the REPO_Groups Table.

If you want to add an entire GitHub organization, refer to the command: augur db add-github-org"""
from augur.tasks.github.util.github_task_session import GithubTaskSession

Check warning on line 46 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0415: Import outside toplevel (augur.tasks.github.util.github_task_session.GithubTaskSession) (import-outside-toplevel) Raw Output: augur/application/cli/db.py:46:4: C0415: Import outside toplevel (augur.tasks.github.util.github_task_session.GithubTaskSession) (import-outside-toplevel)
from augur.util.repo_load_controller import RepoLoadController

Check warning on line 47 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0415: Import outside toplevel (augur.util.repo_load_controller.RepoLoadController) (import-outside-toplevel) Raw Output: augur/application/cli/db.py:47:4: C0415: Import outside toplevel (augur.util.repo_load_controller.RepoLoadController) (import-outside-toplevel)

with GithubTaskSession(logger, engine=ctx.obj.engine) as session:

controller = RepoLoadController(session)

with open(filename) as upload_repos_file:

Check warning on line 53 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W1514: Using open without explicitly specifying an encoding (unspecified-encoding) Raw Output: augur/application/cli/db.py:53:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
data = csv.reader(upload_repos_file, delimiter=",")
for row in data:

Expand Down Expand Up @@ -112,7 +114,7 @@
"""
)

with open(filename) as create_repo_groups_file:

Check warning on line 117 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W1514: Using open without explicitly specifying an encoding (unspecified-encoding) Raw Output: augur/application/cli/db.py:117:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
data = csv.reader(create_repo_groups_file, delimiter=",")
for row in data:

Expand Down Expand Up @@ -145,8 +147,8 @@
"""
Create new repo groups in Augur's database
"""
from augur.tasks.github.util.github_task_session import GithubTaskSession

Check warning on line 150 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0415: Import outside toplevel (augur.tasks.github.util.github_task_session.GithubTaskSession) (import-outside-toplevel) Raw Output: augur/application/cli/db.py:150:4: C0415: Import outside toplevel (augur.tasks.github.util.github_task_session.GithubTaskSession) (import-outside-toplevel)
from augur.util.repo_load_controller import RepoLoadController

Check warning on line 151 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0415: Import outside toplevel (augur.util.repo_load_controller.RepoLoadController) (import-outside-toplevel) Raw Output: augur/application/cli/db.py:151:4: C0415: Import outside toplevel (augur.util.repo_load_controller.RepoLoadController) (import-outside-toplevel)

with GithubTaskSession(logger, engine=ctx.obj.engine) as session:

Expand Down Expand Up @@ -303,7 +305,7 @@


else:
with open("db.config.json", "r") as f:

Check warning on line 308 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W1514: Using open without explicitly specifying an encoding (unspecified-encoding) Raw Output: augur/application/cli/db.py:308:14: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
config = json.load(f)
print(f"Config: {config}")
check_pgpass_credentials(config)
Expand Down Expand Up @@ -343,7 +345,7 @@
}
}
check_pgpass_credentials(config)
run_db_creation_psql_command(

Check warning on line 348 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0602: Undefined variable 'run_db_creation_psql_command' (undefined-variable) Raw Output: augur/application/cli/db.py:348:4: E0602: Undefined variable 'run_db_creation_psql_command' (undefined-variable)
host, port, default_user, default_db_name, f"CREATE DATABASE {target_db_name};"
)
run_db_creation_psql_command(
Expand Down Expand Up @@ -391,7 +393,7 @@
print("Successful db connection")


# TODO: Fix this function

Check warning on line 396 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0511: TODO: Fix this function (fixme) Raw Output: augur/application/cli/db.py:396:1: W0511: TODO: Fix this function (fixme)
def run_psql_command_in_database(target_type, target):
if target_type not in ["-f", "-c"]:
logger.error("Invalid target type. Exiting...")
Expand All @@ -404,7 +406,7 @@

if augur_db_environment_var:
pass
#TODO: Add functionality for environment variable

Check warning on line 409 in augur/application/cli/db.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 W0511: TODO: Add functionality for environment variable (fixme) Raw Output: augur/application/cli/db.py:409:9: W0511: TODO: Add functionality for environment variable (fixme)
else:
with open("db.config.json", 'r') as f:
db_config = json.load(f)
Expand Down Expand Up @@ -443,7 +445,7 @@
open(pgpass_file_path, "w+")
IsaacMilarky marked this conversation as resolved.
Show resolved Hide resolved
IsaacMilarky marked this conversation as resolved.
Show resolved Hide resolved
chmod(pgpass_file_path, stat.S_IWRITE | stat.S_IREAD)

pgpass_file_mask = oct(stat(pgpass_file_path).st_mode & 0o777)
pgpass_file_mask = oct(os.stat(pgpass_file_path).st_mode & 0o777)

if pgpass_file_mask != "0o600":
print("Updating ~/.pgpass file permissions.")
Expand Down