Skip to content

Commit

Permalink
Merge pull request #2731 from chaoss/add-complexity-endpoint-features
Browse files Browse the repository at this point in the history
Add Repository ID Parameters to Line Complexity Endpoints
  • Loading branch information
sgoggins authored Mar 13, 2024
2 parents 48e93be + 7410274 commit 3b7f2ef
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 45 deletions.
76 changes: 43 additions & 33 deletions augur/api/routes/complexity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#SPDX-License-Identifier: MIT
from flask import Response, current_app
import sqlalchemy as s
from flask import Response, current_app, request
import pandas as pd
import sqlalchemy as s
from augur.api.util import metric_metadata
import os
import requests
Expand All @@ -12,6 +12,8 @@

@app.route('/{}/complexity/project_languages'.format(AUGUR_API_VERSION), methods=["GET"])
def get_project_languages():

repo_id = request.args.get('repo_id')
project_languages_sql = s.sql.text("""
SELECT
e.repo_id,
Expand Down Expand Up @@ -96,8 +98,10 @@ def get_project_files():

@app.route('/{}/complexity/project_lines'.format(AUGUR_API_VERSION), methods=["GET"])
def get_project_lines():

repo_id = request.args.get('repo_id')
project_lines_sql = s.sql.text("""
SELECT
SELECT
e.repo_id,
augur_data.repo.repo_git,
augur_data.repo.repo_name,
Expand Down Expand Up @@ -125,9 +129,9 @@ def get_project_lines():
augur_data.repo_labor.repo_id = recent.repo_id
AND augur_data.repo_labor.data_collection_date > recent.last_collected - (5 * interval '1 minute')) d
GROUP BY d.repo_id) e
WHERE augur_data.repo.repo_id = e.repo_id
WHERE augur_data.repo.repo_id = e.repo_id and augur_data.repo.repo_id = :repo_id_param
ORDER BY e.repo_id
""")
""").bindparams(repo_id_param=repo_id)

with current_app.engine.connect() as conn:
results = pd.read_sql(project_lines_sql, conn)
Expand All @@ -138,6 +142,8 @@ def get_project_lines():

@app.route('/{}/complexity/project_comment_lines'.format(AUGUR_API_VERSION), methods=["GET"])
def get_project_comment_lines():

repo_id = request.args.get('repo_id')
comment_lines_sql = s.sql.text("""
SELECT
e.repo_id,
Expand Down Expand Up @@ -167,9 +173,10 @@ def get_project_comment_lines():
augur_data.repo_labor.repo_id = recent.repo_id
AND augur_data.repo_labor.data_collection_date > recent.last_collected - (5 * interval '1 minute')) d
GROUP BY d.repo_id) e
WHERE augur_data.repo.repo_id = e.repo_id
WHERE augur_data.repo.repo_id = e.repo_id
AND e.repo_id = :repo_id_param
ORDER BY e.repo_id
""")
""").bindparams(repo_id_param=repo_id)

with current_app.engine.connect() as conn:
results = pd.read_sql(comment_lines_sql, conn)
Expand All @@ -180,38 +187,41 @@ def get_project_comment_lines():

@app.route('/{}/complexity/project_blank_lines'.format(AUGUR_API_VERSION), methods=["GET"])
def get_project_blank_lines():

repo_id = request.args.get('repo_id')
blank_lines_sql = s.sql.text("""
SELECT
SELECT
e.repo_id,
augur_data.repo.repo_git,
augur_data.repo.repo_name,
e.blank_lines,
e.avg_blank_lines
FROM
augur_data.repo,
(SELECT
d.repo_id,
SUM(d.blank_lines) AS blank_lines,
AVG(d.blank_lines)::int AS avg_blank_lines
FROM
(SELECT
augur_data.repo_labor.repo_id,
augur_data.repo_labor.blank_lines
FROM
augur_data.repo_labor,
( SELECT
augur_data.repo_labor.repo_id,
MAX ( data_collection_date ) AS last_collected
FROM
augur_data.repo_labor
GROUP BY augur_data.repo_labor.repo_id) recent
WHERE
augur_data.repo_labor.repo_id = recent.repo_id
AND augur_data.repo_labor.data_collection_date > recent.last_collected - (5 * interval '1 minute')) d
GROUP BY d.repo_id) e
WHERE augur_data.repo.repo_id = e.repo_id
ORDER BY e.repo_id
""")
FROM
augur_data.repo,
(SELECT
d.repo_id,
SUM(d.blank_lines) AS blank_lines,
AVG(d.blank_lines)::int AS avg_blank_lines
FROM
(SELECT
augur_data.repo_labor.repo_id,
augur_data.repo_labor.blank_lines
FROM
augur_data.repo_labor,
( SELECT
augur_data.repo_labor.repo_id,
MAX ( data_collection_date ) AS last_collected
FROM
augur_data.repo_labor
GROUP BY augur_data.repo_labor.repo_id) recent
WHERE
augur_data.repo_labor.repo_id = recent.repo_id
AND augur_data.repo_labor.data_collection_date > recent.last_collected - (5 * interval '1 minute')) d
GROUP BY d.repo_id) e
WHERE augur_data.repo.repo_id = e.repo_id
AND e.repo_id = :repo_id_param
ORDER BY e.repo_id
""").bindparams(repo_id_param=repo_id)

with current_app.engine.connect() as conn:
results = pd.read_sql(blank_lines_sql, conn)
Expand Down
48 changes: 36 additions & 12 deletions docs/source/rest-api/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4711,7 +4711,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -4772,7 +4772,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -4833,7 +4833,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -4887,7 +4887,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -4948,7 +4948,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -4988,7 +4988,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5028,7 +5028,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5068,7 +5068,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5108,7 +5108,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5148,7 +5148,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5195,7 +5195,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5235,7 +5235,7 @@ paths:
schema:
type: integer
type: integer
description: Reposity Id
description: Repository Id
- in: query
name: start_date
required: false
Expand Down Expand Up @@ -5275,6 +5275,14 @@ paths:
get:
description: 'Returns project line data for all repositories in an Augur instance, using information from a git platform (GitHub, GitLab, etc.). Each record includes the total and average number of lines in the project repository.'
operationId: Total Lines (repo)
parameters:
- in: query
name: repo_id
required: true
schema:
type: integer
type: integer
description: Repository Id
responses:
'200':
description: OK
Expand Down Expand Up @@ -5331,6 +5339,14 @@ paths:
get:
description: 'Returns project blank line data for all repositories in an Augur instance, using information from a git platform (GitHub, GitLab, etc.). Each record includes the total and average number of blank lines in the project repository.'
operationId: Total Blank Lines (repo)
parameters:
- in: query
name: repo_id
required: true
schema:
type: integer
type: integer
description: Repository Id
responses:
'200':
description: OK
Expand Down Expand Up @@ -5359,6 +5375,14 @@ paths:
get:
description: 'Returns project comment line data for all repositories in an Augur instance, using information from a git platform (GitHub, GitLab, etc.). Each record includes the total and average number of comment lines in the project repository.'
operationId: Total Comment Lines (repo)
parameters:
- in: query
name: repo_id
required: true
schema:
type: integer
type: integer
description: Repository Id
responses:
'200':
description: OK
Expand Down

0 comments on commit 3b7f2ef

Please sign in to comment.