Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/dashboard-reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ The `trending` reporter shows the change in each metric over a period of time, b
- If `[days]` is not provided, it will analyze all reports in your `reports/` directory to show the all-time change.
- If `[days]` is provided, it will show the change over the last `N` days.

**Example Output:**

```
Change Last Value First Value Metrics
------ ---------- ----------- -------
-1 0 1 github open_issues repo.attogram.agents
-15 0 15 github closed_prs repo.attogram.ote
-1 0 1 github open_prs repo.attogram.agents
-13 0 13 github closed_prs repo.attogram.justrefs
+6 10 4 github stars repo.attogram.llm-council
```

### `top-stars`

The `top-stars` reporter finds the most recent report file and lists the top repositories by their star count.
Expand Down
30 changes: 24 additions & 6 deletions modules/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ fi

# --- Data Fetching and Formatting -------------------------------------------

# Helper function to safely get a value from jq
get_json_value() {
local json=$1
local key=$2
local value
value=$(echo "$json" | jq -r "$key")
if [ "$value" == "null" ] || [ -z "$value" ]; then
echo "0"
else
echo "$value"
fi
}

fetch_repo_data() {
local repo_name=$1
local api_url="https://api.github.com/repos/${GITHUB_USER}/${repo_name}"
Expand Down Expand Up @@ -67,15 +80,20 @@ fetch_repo_data() {
local open_prs
local closed_prs

stars=$(echo "$api_response" | jq -r '.stargazers_count')
forks=$(echo "$api_response" | jq -r '.forks_count')
issues=$(echo "$api_response" | jq -r '.open_issues_count')
watchers=$(echo "$api_response" | jq -r '.subscribers_count')
stars=$(get_json_value "$api_response" '.stargazers_count')
forks=$(get_json_value "$api_response" '.forks_count')
issues=$(get_json_value "$api_response" '.open_issues_count')
watchers=$(get_json_value "$api_response" '.subscribers_count')

# Fetch PR counts using the search API to be more efficient
local search_api_url="https://api.github.com/search/issues?q=is:pr+repo:${GITHUB_USER}/${repo_name}"
open_prs=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:open" | jq -r '.total_count')
closed_prs=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:closed" | jq -r '.total_count')
local open_prs_response
local closed_prs_response
open_prs_response=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:open")
closed_prs_response=$(curl -s "${curl_headers[@]}" "${search_api_url}+is:closed")

open_prs=$(get_json_value "$open_prs_response" '.total_count')
closed_prs=$(get_json_value "$closed_prs_response" '.total_count')

local now
now=$(date -u +%Y-%m-%dT%H:%M:%SZ)
Expand Down
16 changes: 13 additions & 3 deletions reporters/trending.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,30 @@ awk '
BEGIN {
FS="\t";
OFS="\t";
print "Metric\tFirst Value\tLast Value\tChange";
print "------\t-----------\t----------\t------";
print "Change\tLast Value\tFirst Value\tMetrics";
print "------\t----------\t-----------\t-------";
}
FNR == 1 { next; } # Skip header row of each file
{
metric = $2 OFS $3 OFS $4; # module, channel, namespace
value = $5;
if (value == "null") {
value = 0;
}
if (!(metric in first_value)) {
first_value[metric] = value;
}
last_value[metric] = value;
}
END {
for (metric in last_value) {
# Safeguard for nulls in old reports
if (first_value[metric] == "null") {
first_value[metric] = 0;
}
if (last_value[metric] == "null") {
last_value[metric] = 0;
}
change = last_value[metric] - first_value[metric];
if (change != 0) {
# Add a plus sign for positive changes
Expand All @@ -91,7 +101,7 @@ END {
} else {
change_str = change;
}
print metric, first_value[metric], last_value[metric], change_str;
print change_str, last_value[metric], first_value[metric], metric;
}
}
}' "${TARGET_FILES[@]}"