Skip to content

Commit

Permalink
add repo id parameter to certain complexity endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Milarsky <[email protected]>
  • Loading branch information
IsaacMilarky committed Mar 11, 2024
1 parent 5972723 commit 56e91a2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 31 deletions.
70 changes: 39 additions & 31 deletions augur/api/routes/complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,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 @@ -127,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 @@ -140,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 @@ -169,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 @@ -182,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
24 changes: 24 additions & 0 deletions docs/source/rest-api/spec.yml
Original file line number Diff line number Diff line change
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: Reposity Id

Check failure on line 5285 in docs/source/rest-api/spec.yml

View workflow job for this annotation

GitHub Actions / misspell

[misspell] docs/source/rest-api/spec.yml#L5285

"Reposity" is a misspelling of "Repository"
Raw output
./docs/source/rest-api/spec.yml:5285:23: "Reposity" is a misspelling of "Repository"
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: Reposity Id

Check failure on line 5349 in docs/source/rest-api/spec.yml

View workflow job for this annotation

GitHub Actions / misspell

[misspell] docs/source/rest-api/spec.yml#L5349

"Reposity" is a misspelling of "Repository"
Raw output
./docs/source/rest-api/spec.yml:5349:23: "Reposity" is a misspelling of "Repository"
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: Reposity Id

Check failure on line 5385 in docs/source/rest-api/spec.yml

View workflow job for this annotation

GitHub Actions / misspell

[misspell] docs/source/rest-api/spec.yml#L5385

"Reposity" is a misspelling of "Repository"
Raw output
./docs/source/rest-api/spec.yml:5385:23: "Reposity" is a misspelling of "Repository"
responses:
'200':
description: OK
Expand Down

0 comments on commit 56e91a2

Please sign in to comment.