Skip to content

Commit

Permalink
Merge pull request #2670 from chaoss/dev
Browse files Browse the repository at this point in the history
Updating materialized view branch with latest dev changes
  • Loading branch information
sgoggins authored Jan 26, 2024
2 parents 0a43a50 + 419f69a commit 5e86c55
Show file tree
Hide file tree
Showing 25 changed files with 812 additions and 120 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "run-linting-checks"
on:
pull_request:
branches: [main, dev]

jobs:
run-pylint:
name: runner / pylint
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dciborow/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
level: warning
glob_pattern: "**/*.py"
filter_mode: "file"

misspell:
name: runner / misspell
runs-on: ubuntu-latest
steps:
- name: Highlight any misspellings in changes.
uses: actions/checkout@v4
- name: misspell
uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
locale: "US"
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#refactoring checker
#enable=R

disable=E0611,E1101,W1203,R0801,W0614,W0611,C0411,C0103,C0301,C0303,C0304,C0305,W0311
disable=E0611,E1101,W1203,R0801,W0614,W0611,C0411,C0103,C0301,C0303,C0304,C0305,W0311,E0401


# Analyse import fallback blocks. This can be used to support both Python 2 and
Expand Down
62 changes: 51 additions & 11 deletions augur/api/routes/util.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#SPDX-License-Identifier: MIT
from augur.api.routes import AUGUR_API_VERSION
from ..server import app, engine
import base64
import sqlalchemy as s
import pandas as pd
import json
from flask import Response
import logging

from augur.application.db.session import DatabaseSession
from augur.application.logs import AugurLogger
from augur.application.config import AugurConfig

logger = AugurLogger("augur").get_logger()

from augur.api.routes import AUGUR_API_VERSION
from ..server import app, engine


@app.route('/{}/repo-groups'.format(AUGUR_API_VERSION))
def get_all_repo_groups(): #TODO: make this name automatic - wrapper?
repoGroupsSQL = s.sql.text("""
Expand Down Expand Up @@ -54,9 +51,9 @@ def get_all_repos():
(select * from api_get_all_repos_issues) b
on
repo.repo_id = b.repo_id
left outer join
(select * from api_get_all_repo_prs) c
on repo.repo_id=c.repo_id
left outer join
(select * from api_get_all_repo_prs) c
on repo.repo_id=c.repo_id
JOIN repo_groups ON repo_groups.repo_group_id = repo.repo_group_id
order by repo_name
""")
Expand Down Expand Up @@ -95,9 +92,9 @@ def get_repos_in_repo_group(repo_group_id):
(select * from api_get_all_repos_issues) b
on
repo.repo_id = b.repo_id
left outer join
(select * from api_get_all_repo_prs) c
on repo.repo_id=c.repo_id
left outer join
(select * from api_get_all_repo_prs) c
on repo.repo_id=c.repo_id
JOIN repo_groups ON repo_groups.repo_group_id = repo.repo_group_id
WHERE
repo_groups.repo_group_id = :repo_group_id
Expand All @@ -111,6 +108,49 @@ def get_repos_in_repo_group(repo_group_id):
status=200,
mimetype="application/json")

@app.route('/{}/repos/<repo_id>'.format(AUGUR_API_VERSION))
def get_repo_by_id(repo_id: int) -> Response:
repo_by_id_SQL = s.sql.text("""
SELECT
repo.repo_id,
repo.repo_name,
repo.description,
repo.repo_git AS url,
a.commits_all_time,
b.issues_all_time,
c.pull_requests_all_time,
rg_name,
repo.repo_group_id
FROM
repo
LEFT OUTER JOIN
(SELECT * FROM api_get_all_repos_commits) a
ON repo.repo_id = a.repo_id
LEFT OUTER JOIN
(SELECT * FROM api_get_all_repos_issues) b
ON repo.repo_id = b.repo_id
LEFT OUTER JOIN
(SELECT * FROM api_get_all_repo_prs) c
ON repo.repo_id = c.repo_id
JOIN repo_groups ON repo_groups.repo_group_id = repo.repo_group_id
WHERE
repo.repo_id = :id
""")

results = pd.read_sql(repo_by_id_SQL, engine, params={"id": repo_id})
results["url"] = results["url"].apply(lambda datum: datum.split("//")[1]) # cut "https://" off the URL
results["base64_url"] = [base64.b64encode(results.at[i, "url"].encode()) for i in results.index]
data = results.to_json(orient="records", date_format="iso", date_unit="ms")

if not data or data == "[]":
return Response(response='{"status": "Repository ' + str(repo_id) + ' does not exist"}',
status=400,
mimetype="application/json")

return Response(response=data[1:-1], # cut off brackets at each end, turns list of length 1 into single value
status=200,
mimetype="application/json")

@app.route('/{}/owner/<owner>/repo/<repo>'.format(AUGUR_API_VERSION))
def get_repo_by_git_name(owner, repo):

Expand Down
8 changes: 6 additions & 2 deletions augur/api/view/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
Defines the api routes for the augur views
"""
import logging
import math
from flask import Flask, render_template, render_template_string, request, abort, jsonify, redirect, url_for, session, flash
from sqlalchemy.orm.exc import NoResultFound
from .utils import *
Expand Down Expand Up @@ -37,9 +41,9 @@ def root(path=""):
def logo(brand=None):
if brand is None:
return redirect(url_for('static', filename='img/augur_logo.png'))
elif "augur" in brand:
if "augur" in brand:
return logo(None)
elif "chaoss" in brand:
if "chaoss" in brand:
return redirect(url_for('static', filename='img/Chaoss_Logo_white.png'))
return ""

Expand Down
4 changes: 4 additions & 0 deletions augur/api/view/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""
Defines utility functions used by the augur api views
"""
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor
from flask import render_template, flash, url_for, Flask
from .init import init_logging
from .init import *
from ..server import app, db_session
from augur.application.config import AugurConfig
Expand Down
Loading

0 comments on commit 5e86c55

Please sign in to comment.