Conversation
- Introduced a new workflow to collect and append weekly repo traffic data (views and unique visitors) to CSV files. - The workflow fetches data from the GitHub Traffic API and handles date management to ensure accurate data recording. - Includes steps for determining the last recorded date, fetching new traffic data, appending to CSV files, and creating a pull request with a summary of the collected data.
There was a problem hiding this comment.
Pull request overview
Adds an agentic workflow that periodically collects GitHub repo traffic (views + uniques) and proposes CSV updates via an automated PR.
Changes:
- Added a new agentic workflow prompt (
traffic-updater.md) describing how to fetch and append traffic data. - Added the compiled workflow lock file (
traffic-updater.lock.yml) to run on a weekly schedule. - Seeded initial traffic datasets in
.github/views.csvand.github/uvs.csv.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/workflows/traffic-updater.md | Defines the agent instructions for fetching/appending traffic data and opening a PR. |
| .github/workflows/traffic-updater.lock.yml | Compiled GitHub Actions workflow that executes the agentic workflow on a schedule / dispatch. |
| .github/views.csv | Adds initial daily total views data. |
| .github/uvs.csv | Adds initial daily unique visitors data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mkdir -p /tmp/gh-aw/safeoutputs | ||
| mkdir -p /tmp/gh-aw/mcp-logs/safeoutputs | ||
| cat > ${RUNNER_TEMP}/gh-aw/safeoutputs/config.json << 'GH_AW_SAFE_OUTPUTS_CONFIG_f14d4f09daa40f9e_EOF' | ||
| {"create_pull_request":{"base_branch":"main","labels":["automated-update","traffic-data"],"max":1,"max_patch_size":1024,"protected_files":["package.json","bun.lockb","bunfig.toml","deno.json","deno.jsonc","deno.lock","global.json","NuGet.Config","Directory.Packages.props","mix.exs","mix.lock","go.mod","go.sum","stack.yaml","stack.yaml.lock","pom.xml","build.gradle","build.gradle.kts","settings.gradle","settings.gradle.kts","gradle.properties","package-lock.json","yarn.lock","pnpm-lock.yaml","npm-shrinkwrap.json","requirements.txt","Pipfile","Pipfile.lock","pyproject.toml","setup.py","setup.cfg","Gemfile","Gemfile.lock","uv.lock","CODEOWNERS"],"protected_path_prefixes":[".github/",".agents/"],"title_prefix":"[bot] "},"missing_data":{},"missing_tool":{},"noop":{"max":1,"report-as-issue":"true"}} |
There was a problem hiding this comment.
The Safe Outputs create_pull_request config blocks changes under the .github/ prefix (protected_path_prefixes includes .github/), but this workflow’s purpose is to update .github/uvs.csv and .github/views.csv. As-is, PR creation for the traffic CSV updates is likely to be rejected by the Safe Outputs handler. Consider moving these CSVs out of .github/ (e.g., data/traffic/*.csv), or adjust the Safe Outputs config (if supported) to allow just these two paths while still protecting workflows.
| {"create_pull_request":{"base_branch":"main","labels":["automated-update","traffic-data"],"max":1,"max_patch_size":1024,"protected_files":["package.json","bun.lockb","bunfig.toml","deno.json","deno.jsonc","deno.lock","global.json","NuGet.Config","Directory.Packages.props","mix.exs","mix.lock","go.mod","go.sum","stack.yaml","stack.yaml.lock","pom.xml","build.gradle","build.gradle.kts","settings.gradle","settings.gradle.kts","gradle.properties","package-lock.json","yarn.lock","pnpm-lock.yaml","npm-shrinkwrap.json","requirements.txt","Pipfile","Pipfile.lock","pyproject.toml","setup.py","setup.cfg","Gemfile","Gemfile.lock","uv.lock","CODEOWNERS"],"protected_path_prefixes":[".github/",".agents/"],"title_prefix":"[bot] "},"missing_data":{},"missing_tool":{},"noop":{"max":1,"report-as-issue":"true"}} | |
| {"create_pull_request":{"base_branch":"main","labels":["automated-update","traffic-data"],"max":1,"max_patch_size":1024,"protected_files":["package.json","bun.lockb","bunfig.toml","deno.json","deno.jsonc","deno.lock","global.json","NuGet.Config","Directory.Packages.props","mix.exs","mix.lock","go.mod","go.sum","stack.yaml","stack.yaml.lock","pom.xml","build.gradle","build.gradle.kts","settings.gradle","settings.gradle.kts","gradle.properties","package-lock.json","yarn.lock","pnpm-lock.yaml","npm-shrinkwrap.json","requirements.txt","Pipfile","Pipfile.lock","pyproject.toml","setup.py","setup.cfg","Gemfile","Gemfile.lock","uv.lock","CODEOWNERS"],"protected_path_prefixes":[".github/workflows/",".agents/"],"title_prefix":"[bot] "},"missing_data":{},"missing_tool":{},"noop":{"max":1,"report-as-issue":"true"}} |
| Read the last line of `.github/uvs.csv` (or `.github/views.csv` — they should be in sync). Parse the `"MM/DD"` date to determine the last day already recorded. Assume the current year for the date. | ||
|
|
||
| If both files are empty, treat the start date as 14 days ago (the maximum the GitHub API provides). | ||
|
|
There was a problem hiding this comment.
Step 1 assumes the CSV date (MM/DD) is in the current year. Around the New Year this can interpret the last recorded date as being in the future (e.g., last row 12/30 run on 01/02), which would cause the workflow to append nothing. Consider deriving the year by comparing to “today” (if parsed MM/DD is after today, treat it as previous year), and also validating both CSVs are in sync (or using the max of the two last dates) instead of assuming they match.
| Read the last line of `.github/uvs.csv` (or `.github/views.csv` — they should be in sync). Parse the `"MM/DD"` date to determine the last day already recorded. Assume the current year for the date. | |
| If both files are empty, treat the start date as 14 days ago (the maximum the GitHub API provides). | |
| Read the last line of **both** `.github/uvs.csv` and `.github/views.csv` (if they exist). Each line has the format `"MM/DD",count`. | |
| - If **both files are empty**, treat the start date as **14 days ago from today** (date-only; ignore the time of day), which is the maximum range the GitHub API provides. | |
| - If **only one file has data**, use that file’s last `"MM/DD"` as the last recorded date. | |
| - If **both files have data**, parse the `"MM/DD"` from each last line, infer the full date for each (see below), and then use the **later** of the two dates as the last recorded date. This keeps the files in sync even if they briefly diverge. | |
| To infer the **year** for a `"MM/DD"` value: | |
| 1. Start by constructing a date using the **current year** and the parsed month/day. | |
| 2. Compare that constructed date to **today’s date** (also with the current year). | |
| 3. If the constructed date is **after today** (i.e., in the future), treat it as belonging to the **previous year** instead. | |
| The result of this step is a concrete “last recorded date” (with year), which will be used to decide which API results are new. |
| Use the `gh` CLI to call the GitHub Traffic API for this repository: | ||
|
|
||
| ```bash | ||
| gh api repos/{owner}/{repo}/traffic/views |
There was a problem hiding this comment.
The command example uses gh api repos/{owner}/{repo}/traffic/views, but {owner}/{repo} aren’t defined anywhere in the prompt. To avoid the agent running this literally, consider specifying an explicit substitution (e.g., derive owner/repo from GITHUB_REPOSITORY / repo context) and using that in the command.
| gh api repos/{owner}/{repo}/traffic/views | |
| gh api repos/"${GITHUB_REPOSITORY}"/traffic/views |
| "03/04",440 | ||
| "03/05",882 | ||
| "03/06",901 |
There was a problem hiding this comment.
This file starts at 03/04, but .github/uvs.csv includes 03/03, so the two datasets are not aligned even though the workflow prompt states they should be in sync. Either add the missing 03/03 views row (if available) or remove the extra 03/03 uniques row so both CSVs cover the same date range.
See below for a potential fix:
@ -1,3 +1,4 @@
"03/03",0
Adds a new agentic workflow (
traffic-updater.md) that collects weekly repo traffic data (views and unique visitors) from the GitHub API and appends it to.github/uvs.csvand.github/views.csv.How it works:
gh api repos/{owner}/{repo}/traffic/viewsSchedule: Runs weekly on Monday (also supports manual trigger via
workflow_dispatch)