Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Add make sprint-data-import and issue-data-import to import github sprint and issue data to database #84

Merged
merged 14 commits into from
Jun 26, 2024
Merged
9 changes: 5 additions & 4 deletions .github/workflows/ci-analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ jobs:
- name: Run tests
run: make test-audit

- name: Export GitHub data
run: make gh-data-export
# Both of these tasks are looking for github and slack auth
# - name: Export GitHub data
# run: make gh-data-export

- name: Run reports
run: make sprint-reports
# - name: Run reports
# run: make sprint-reports

vulnerability-scans:
name: Run Analytics Vulnerability Scans
Expand Down
8 changes: 4 additions & 4 deletions .grype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ ignore:
- fix-state: not-fixed
- fix-state: wont-fix
- fix-state: unknown
# Golang vulnerability inside of a python docker image. It's basically impossible to find
# out where the impacted golang vulnerability is coming from. The python image in question
# does not even have golang installed, yet somehow still there's a golang vulnerability.
# We are ignoring the finding because it would take undue effort to track down the source.
# Golang vulnerabilities inside of a python docker image. Both originate from lower level packages within the GitHub CLI:
# https://github.com/cli/cli/blob/trunk/go.mod#L101
# https://github.com/cli/cli/blob/trunk/go.mod#L161
- vulnerability: GHSA-4v7x-pqxf-cx7m
- vulnerability: GHSA-v6v8-xj6m-xwqh
# https://github.com/anchore/grype/issues/1172
- vulnerability: GHSA-xqr8-7jwr-rhp7
- vulnerability: GHSA-7fh5-64p2-3v2j
Expand Down
7 changes: 7 additions & 0 deletions analytics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ sprint-data-export:
--project $(SPRINT_PROJECT) \
--output-file $(SPRINT_FILE)

gh-db-data-import:
@echo "=> Importing sprint data to the database"
@echo "====================================================="
$(POETRY) analytics import db_import \
--sprint-file $(SPRINT_FILE) \
--issue-file $(ISSUE_FILE)

roadmap-data-export:
@echo "=> Exporting project data from the product roadmap"
@echo "====================================================="
Expand Down
285 changes: 159 additions & 126 deletions analytics/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions analytics/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ python = "^3.11"
slack-sdk = "^3.23.0"
typer = { extras = ["all"], version = "^0.9.0" }
sqlalchemy = "^2.0.30"
psycopg = ">=3.0.7"

[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
Expand Down
2 changes: 1 addition & 1 deletion analytics/settings.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POSTGRES_NAME = "app"
POSTGRES_HOST = "0.0.0.0"
POSTGRES_HOST = "grants-analytics-db"
POSTGRES_USER = "app"
POSTGRES_PORT = 5432
Copy link
Member

Choose a reason for hiding this comment

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

I believe you would need a password here as well, can you confirm?

Copy link
Author

Choose a reason for hiding this comment

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

Theres a secrets.toml that's in the gitignore that has the password

38 changes: 37 additions & 1 deletion analytics/src/analytics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
# instantiate sub-commands for exporting data and calculating metrics
export_app = typer.Typer()
metrics_app = typer.Typer()
import_app = typer.Typer()
# add sub-commands to main entrypoint
app.add_typer(export_app, name="export", help="Export data needed to calculate metrics")
app.add_typer(metrics_app, name="calculate", help="Calculate key project metrics")
app.add_typer(import_app, name="import", help="Import data into the database")


@app.callback()
Expand Down Expand Up @@ -126,7 +128,7 @@ def calculate_sprint_burnup(
)


@export_app.command(name="test_connection")
@import_app.command(name="test_connection")
def test_connection() -> None:
"""Test function that ensures the DB connection works."""
engine = db.get_db()
Expand All @@ -149,6 +151,40 @@ def test_connection() -> None:
result.close()


@import_app.command(name="db_import")
def export_json_to_database(
sprint_file: Annotated[str, SPRINT_FILE_ARG],
issue_file: Annotated[str, ISSUE_FILE_ARG],
) -> None:
"""Import JSON data to the database."""
# Get the database engine and establish a connection
engine = db.get_db()

# get data and load from JSON
deliverable_data = DeliverableTasks.load_from_json_files(
sprint_file=sprint_file,
issue_file=issue_file,
)

# Load data from the sprint board
sprint_data = SprintBoard.load_from_json_files(
sprint_file=sprint_file,
issue_file=issue_file,
)

deliverable_data.to_sql(
output_table="github_project_data",
engine=engine,
replace_table=True,
) # replace_table=True is the default

sprint_data.to_sql(
output_table="github_project_data",
engine=engine,
replace_table=True,
)


@metrics_app.command(name="deliverable_percent_complete")
def calculate_deliverable_percent_complete(
sprint_file: Annotated[str, SPRINT_FILE_ARG],
Expand Down
2 changes: 2 additions & 0 deletions analytics/tests/integrations/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def mock_slackbot() -> SlackBot:
return SlackBot(client=client)


@pytest.mark.skip(reason="requires Slack token")
def test_fetch_slack_channels(slackbot: SlackBot):
"""The fetch_slack_channels() function should execute correctly."""
result = slackbot.fetch_slack_channel_info(channel_id=settings.reporting_channel_id)
assert result["ok"] is True
assert result["channel"]["name"] == "z_bot-analytics-ci-test"


@pytest.mark.skip(reason="requires Slack token")
def test_upload_files_to_slack_channel(slackbot: SlackBot):
"""The upload_files_to_slack_channel() function should execute correctly."""
# setup - create test files to upload
Expand Down
Loading