Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Multiple reporting workflows independently implement similar metrics calculations (issues, PRs, code, workflows), leading to inconsistent naming, duplicated code (~500-750 lines), and difficult cross-report comparisons.

Changes

Created .github/workflows/shared/metrics-patterns.md (538 lines)

Provides 6 standardized calculation patterns:

  1. Issue Metrics (Python) - Volume, time-based, quality metrics with pandas
  2. Pull Request Metrics (bash/jq) - Counts, merge rates, time windows
  3. Code Metrics (bash/cloc) - LOC, test coverage, ratios
  4. Workflow Performance (Python) - Success rates, durations
  5. Trend Calculation (Python) - Directional indicators (⬆️/➡️/⬇️) with % change
  6. Cross-Platform Dates (bash) - GNU/BSD compatible utilities

Each pattern includes:

  • Explicit scope documentation (e.g., # Scope: Issues created in last 7 days)
  • 15 references to specs/metrics-glossary.md for naming standardization
  • Edge case handling (empty datasets, null values, division by zero)
  • Usage examples

Usage

# In workflow frontmatter
imports:
  - shared/metrics-patterns.md
# Copy-paste pattern from shared component
# All metric names follow specs/metrics-glossary.md standards
total_issues = len(df)  # Scope: All issues in repository, no filters
open_issues = len(df[df['state'] == 'OPEN'])  # Scope: State = OPEN
issues_opened_7d = len(df[df['createdAt'] > now - timedelta(days=7)])

Impact

  • 10-15 workflows can migrate to these patterns
  • Single source for metrics calculations - fix bugs once
  • Consistent naming enables accurate cross-report comparisons
  • Clear documentation with scope and references

Updated .gitignore to exclude test validation workflow.

Original prompt

This section details on the original issue you should resolve

<issue_title>[refactoring] Create shared metrics calculation patterns skill</issue_title>
<issue_description>## Skill Overview

Create a shared component that provides standardized metrics calculation patterns and code snippets for common repository metrics. This will ensure consistency across all reporting workflows and reduce duplication of metrics calculation logic.

Current Usage

This skill pattern appears in the following workflows with repeated metrics calculation code:

  • daily-issues-report.md (lines 83-191) - Issue metrics with clustering
  • daily-code-metrics.md (lines 48-95) - Code quality metrics
  • metrics-collector.md (lines 44-127) - Workflow performance metrics
  • weekly-issue-summary.md - Issue summary metrics
  • daily-team-evolution-insights.md - Team activity metrics
  • daily-regulatory.md - Compliance metrics
  • copilot-session-insights.md - Session analysis metrics
  • daily-performance-summary.md - Performance metrics
  • daily-observability-report.md - Observability metrics
  • agent-performance-analyzer.md - Agent quality metrics

Estimated: 10-15 workflows currently calculating similar metrics independently

Proposed Shared Component

File: .github/workflows/shared/metrics-patterns.md

Configuration:

---
# Metrics Calculation Patterns
# Provides standardized Python and bash patterns for common metrics
---

# Metrics Calculation Patterns

This shared component provides standardized code patterns for calculating common repository metrics, ensuring consistency across all reporting workflows.

## Available Patterns

### 1. Issue Metrics (Python)

Use these patterns for analyzing GitHub issues data. All metric names follow `specs/metrics-glossary.md` standards.

``````python
import pandas as pd
from datetime import datetime, timedelta

# Load issues data
with open('/tmp/gh-aw/issues-data/issues.json', 'r') as f:
    issues = json.load(f)
df = pd.DataFrame(issues)

# Convert timestamps
df['createdAt'] = pd.to_datetime(df['createdAt'])
df['updatedAt'] = pd.to_datetime(df['updatedAt'])
df['closedAt'] = pd.to_datetime(df['closedAt'])

# Standardized metric calculations (see specs/metrics-glossary.md)
now = datetime.now(df['createdAt'].iloc[0].tzinfo if len(df) > 0 else None)

# Volume metrics
total_issues = len(df)  # Scope: All issues
open_issues = len(df[df['state'] == 'OPEN'])  # Scope: State = OPEN
closed_issues = len(df[df['state'] == 'CLOSED'])  # Scope: State = CLOSED

# Time-based metrics
issues_opened_7d = len(df[df['createdAt'] > now - timedelta(days=7)])
issues_opened_30d = len(df[df['createdAt'] > now - timedelta(days=30)])

# Quality metrics
issues_without_labels = len(df[df['labels'].map(len) == 0])
issues_without_assignees = len(df[df['assignees'].map(len) == 0])
stale_issues = len(df[df['updatedAt'] < now - timedelta(days=30)])

2. Pull Request Metrics (jq + bash)

# Calculate PR metrics using jq
# Input: /tmp/gh-aw/pr-data/prs.json

# Volume metrics
total_prs=$(jq 'length' /tmp/gh-aw/pr-data/prs.json)
merged_prs=$(jq '[.[] | select(.mergedAt != null)] | length' /tmp/gh-aw/pr-data/prs.json)
open_prs=$(jq '[.[] | select(.state == "OPEN")] | length' /tmp/gh-aw/pr-data/prs.json)

# Time-based metrics (last 7 days)
DATE_7D=$(date -d '7 days ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date -v-7d '+%Y-%m-%dT%H:%M:%SZ')
prs_opened_7d=$(jq --arg date "$DATE_7D" '[.[] | select(.createdAt >= $date)] | length' /tmp/gh-aw/pr-data/prs.json)

# Calculate merge rate
merge_rate=$(echo "scale=3; $merged_prs / $total_prs" | bc)

3. Code Metrics (bash + cloc)

# Lines of code metrics
# Uses cloc for accurate language detection

# Total LOC by language
cloc . --json --quiet > /tmp/gh-aw/data/cloc_output.json
lines_of_code_total=$(jq '.SUM.code' /tmp/gh-aw/data/cloc_output.json)

# Test LOC (find test files and measure)
find . -name "*_test.go" -o -name "*.test.js" | xargs cloc --json --quiet > /tmp/gh-aw/data/test_cloc.json
test_lines_of_code=$(jq '.SUM.code' /tmp/gh-aw/data/test_cloc.json)

# Calculate test-to-source ratio
test_to_source_ratio=$(echo "scale=3; $test_lines_of_code / $lines_of_code_total" | bc)

4. Workflow Performance Metrics (Python)

# Calculate workflow performance metrics from logs data
# Input: workflow_runs list from agentic-workflows tool

workflow_metrics = {}
for workflow_name, runs in workflow_runs.items():
    total = len(runs)
    successful = len([r for r in runs if r['conclusion'] == 'success'])
    failed = total - successful
    
    workflow_metrics[workflow_name] = {
        'total_runs': total,
        'successful_runs': successful,
        'failed_runs': failed,
        'success_rate': round(successful / total, 3) if total > 0 else 0,
        'avg_duration_seconds': sum(r['duration'] for r in runs) / total if total > 0 else 0
    }

##...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Create shared metrics calculation patterns skill Add shared metrics calculation patterns skill Jan 20, 2026
@pelikhan pelikhan marked this pull request as ready for review January 20, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactoring] Create shared metrics calculation patterns skill

3 participants