From ccf03c1fe8b7308ab1d908c49bd357bc5bf9b6da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Jul 2026 12:51:28 +0000 Subject: [PATCH 1/3] Initial plan From 1527976d3ec4fd2a4bbf043e72ff742a91bb6e9f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Jul 2026 12:53:52 +0000 Subject: [PATCH 2/3] Add weekly email traffic report workflow and documentation --- .github/workflows/email-traffic-report.yml | 78 ++++++++++++++++++++++ README.md | 24 +++++++ 2 files changed, 102 insertions(+) create mode 100644 .github/workflows/email-traffic-report.yml diff --git a/.github/workflows/email-traffic-report.yml b/.github/workflows/email-traffic-report.yml new file mode 100644 index 0000000..a36d394 --- /dev/null +++ b/.github/workflows/email-traffic-report.yml @@ -0,0 +1,78 @@ +name: Email traffic report + +on: + workflow_dispatch: + schedule: + # Every Monday at 08:30 UTC + - cron: "30 8 * * 1" + +jobs: + traffic-report: + runs-on: ubuntu-latest + + steps: + - name: Fetch traffic data and build report + env: + GH_TOKEN: ${{ secrets.TRAFFIC_TOKEN }} + run: | + set -euo pipefail + + OWNER="DHI" + REPO="HydroEO" + + gh api "repos/${OWNER}/${REPO}/traffic/views" > views.json + gh api "repos/${OWNER}/${REPO}/traffic/clones" > clones.json + gh api "repos/${OWNER}/${REPO}/traffic/popular/referrers" > referrers.json + gh api "repos/${OWNER}/${REPO}/traffic/popular/paths" > paths.json + + REPORT_DATE=$(date -u "+%Y-%m-%d %H:%M UTC") + + { + echo "GitHub Traffic Report -- ${OWNER}/${REPO}" + echo "Generated: ${REPORT_DATE}" + echo "Note: Traffic data covers approximately the last 14 days." + echo "========================================================" + echo "" + + echo "=== Views (last 14 days) ===" + TOTAL_VIEWS=$(jq '.count' views.json) + UNIQUE_VIEWS=$(jq '.uniques' views.json) + echo "Total views: ${TOTAL_VIEWS}" + echo "Unique views: ${UNIQUE_VIEWS}" + echo "" + echo "Daily breakdown:" + jq -r '.views[] | " \(.timestamp[0:10]) views: \(.count) uniques: \(.uniques)"' views.json + echo "" + + echo "=== Clones (last 14 days) ===" + TOTAL_CLONES=$(jq '.count' clones.json) + UNIQUE_CLONES=$(jq '.uniques' clones.json) + echo "Total clones: ${TOTAL_CLONES}" + echo "Unique clones: ${UNIQUE_CLONES}" + echo "" + echo "Daily breakdown:" + jq -r '.clones[] | " \(.timestamp[0:10]) clones: \(.count) uniques: \(.uniques)"' clones.json + echo "" + + echo "=== Top Referrers ===" + jq -r '.[] | " \(.referrer) views: \(.count) uniques: \(.uniques)"' referrers.json + echo "" + + echo "=== Top Paths ===" + jq -r '.[] | " \(.path)\n views: \(.count) uniques: \(.uniques)"' paths.json + echo "" + } > report.txt + + cat report.txt + + - name: Send email + uses: dawidd6/action-send-mail@v6 + with: + server_address: ${{ secrets.SMTP_HOST }} + server_port: ${{ secrets.SMTP_PORT }} + username: ${{ secrets.SMTP_USERNAME }} + password: ${{ secrets.SMTP_PASSWORD }} + subject: "GitHub Traffic Report -- DHI/HydroEO" + to: ${{ secrets.TRAFFIC_REPORT_TO }} + from: GitHub Actions <${{ secrets.SMTP_USERNAME }}> + body: file://report.txt diff --git a/README.md b/README.md index e9a7564..4bfa801 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,30 @@ setup_logging(logging.DEBUG) # both console and file setup_logging(logging.INFO, enable_file_logging=False) # console only ``` +## Traffic report (automated email) + +A scheduled GitHub Actions workflow at `.github/workflows/email-traffic-report.yml` sends a weekly traffic summary email every Monday at 08:30 UTC. +It can also be triggered at any time via **Actions → Email traffic report → Run workflow**. + +### Required repository secrets + +| Secret | Description | +| --- | --- | +| `TRAFFIC_TOKEN` | A GitHub personal access token (classic or fine-grained) with **read** access to repository traffic for `DHI/HydroEO`. The token owner must have at least write access to the repository. | +| `SMTP_HOST` | SMTP server hostname (e.g. `smtp.gmail.com`). | +| `SMTP_PORT` | SMTP server port (e.g. `587` for STARTTLS). | +| `SMTP_USERNAME` | SMTP login / sender address. | +| `SMTP_PASSWORD` | SMTP password or app password. | +| `TRAFFIC_REPORT_TO` | Recipient email address(es), comma-separated. | + +Add these secrets under **Settings → Secrets and variables → Actions → New repository secret**. + +### Data retention note + +The GitHub traffic API returns data for approximately the **last 14 days** only. +Running the workflow weekly ensures no data window is missed. +If longer-term history is needed, consider extending the workflow to upload the raw JSON files as build artifacts or commit them to a dedicated branch. + ## Running tests ```sh From ab4abaa3831f11101abe812bacad0ba3190a4cf9 Mon Sep 17 00:00:00 2001 From: numatis Date: Thu, 16 Jul 2026 18:23:12 +0200 Subject: [PATCH 3/3] Keep traffic report changes in workflow only --- .github/workflows/email-traffic-report.yml | 3 +++ README.md | 24 ---------------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/workflows/email-traffic-report.yml b/.github/workflows/email-traffic-report.yml index a36d394..ec49dfb 100644 --- a/.github/workflows/email-traffic-report.yml +++ b/.github/workflows/email-traffic-report.yml @@ -1,3 +1,6 @@ +# Sends a weekly GitHub repository traffic report by email. +# Fetches views, clones, referrers, and popular paths for DHI/HydroEO, then +# formats the latest GitHub traffic data into a plain-text email for maintainers. name: Email traffic report on: diff --git a/README.md b/README.md index 4bfa801..e9a7564 100644 --- a/README.md +++ b/README.md @@ -134,30 +134,6 @@ setup_logging(logging.DEBUG) # both console and file setup_logging(logging.INFO, enable_file_logging=False) # console only ``` -## Traffic report (automated email) - -A scheduled GitHub Actions workflow at `.github/workflows/email-traffic-report.yml` sends a weekly traffic summary email every Monday at 08:30 UTC. -It can also be triggered at any time via **Actions → Email traffic report → Run workflow**. - -### Required repository secrets - -| Secret | Description | -| --- | --- | -| `TRAFFIC_TOKEN` | A GitHub personal access token (classic or fine-grained) with **read** access to repository traffic for `DHI/HydroEO`. The token owner must have at least write access to the repository. | -| `SMTP_HOST` | SMTP server hostname (e.g. `smtp.gmail.com`). | -| `SMTP_PORT` | SMTP server port (e.g. `587` for STARTTLS). | -| `SMTP_USERNAME` | SMTP login / sender address. | -| `SMTP_PASSWORD` | SMTP password or app password. | -| `TRAFFIC_REPORT_TO` | Recipient email address(es), comma-separated. | - -Add these secrets under **Settings → Secrets and variables → Actions → New repository secret**. - -### Data retention note - -The GitHub traffic API returns data for approximately the **last 14 days** only. -Running the workflow weekly ensures no data window is missed. -If longer-term history is needed, consider extending the workflow to upload the raw JSON files as build artifacts or commit them to a dedicated branch. - ## Running tests ```sh