diff --git a/docs/dashboard-reporters.md b/docs/dashboard-reporters.md index 7bd06f2..eb3a089 100644 --- a/docs/dashboard-reporters.md +++ b/docs/dashboard-reporters.md @@ -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. diff --git a/modules/github.sh b/modules/github.sh index 0dbd0d7..97ec8b1 100755 --- a/modules/github.sh +++ b/modules/github.sh @@ -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}" @@ -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) diff --git a/reporters/trending.sh b/reporters/trending.sh index d58dd7c..91936af 100755 --- a/reporters/trending.sh +++ b/reporters/trending.sh @@ -69,13 +69,16 @@ 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; } @@ -83,6 +86,13 @@ FNR == 1 { next; } # Skip header row of each file } 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 @@ -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[@]}"