From 3ad7e345d1df7890ecf5f93d3216cd4a5f7d72d1 Mon Sep 17 00:00:00 2001 From: davidabram Date: Wed, 2 Jul 2025 00:14:12 +0200 Subject: [PATCH] feat/DXTA-315 --- cmd/oss-api/main.go | 1 + go.mod | 1 + internal/docs/code_change/markdown_handler.md | 11 ++++++ internal/docs/commits/markdown_handler.md | 3 ++ internal/docs/deploy_freq/markdown_handler.md | 3 ++ internal/docs/embed.go | 10 +++++ internal/docs/merge_freq/markdown_handler.md | 3 ++ internal/docs/mr_opened/markdown_handler.md | 3 ++ internal/oss-api/handler/code_chage.go | 28 ++++++++----- internal/util/markdown_file.go | 39 +++++++++++++++++++ 10 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 internal/docs/code_change/markdown_handler.md create mode 100644 internal/docs/commits/markdown_handler.md create mode 100644 internal/docs/deploy_freq/markdown_handler.md create mode 100644 internal/docs/embed.go create mode 100644 internal/docs/merge_freq/markdown_handler.md create mode 100644 internal/docs/mr_opened/markdown_handler.md create mode 100644 internal/util/markdown_file.go diff --git a/cmd/oss-api/main.go b/cmd/oss-api/main.go index ecd2b926..2366b96c 100644 --- a/cmd/oss-api/main.go +++ b/cmd/oss-api/main.go @@ -48,6 +48,7 @@ func initTracer(ctx context.Context, res *sdkresource.Resource) (*sdktrace.Trace return tp, nil } + func main() { isEndpointProvided := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" || os.Getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") != "" diff --git a/go.mod b/go.mod index c7ddf584..51f2efe7 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( go.temporal.io/api v1.50.0 go.temporal.io/sdk v1.34.0 google.golang.org/protobuf v1.36.6 + gopkg.in/yaml.v2 v2.4.0 ) require ( diff --git a/internal/docs/code_change/markdown_handler.md b/internal/docs/code_change/markdown_handler.md new file mode 100644 index 00000000..dc3b60d7 --- /dev/null +++ b/internal/docs/code_change/markdown_handler.md @@ -0,0 +1,11 @@ +--- +title: "Code Change Metrics" +--- +The Code Change engineering metric quantifies the team’s weekly development activity by measuring the total number of lines of code added, modified, or deleted across our repositories. + +* **Source**: Computed from commit diffs in our Git version-control system, excluding merge commits and auto-generated files. +* **Aggregation**: Grouped by ISO week (Monday–Sunday). +* **Purpose**: + * Tracks engineering velocity and throughput over time. + * Highlights spikes (e.g., major feature work or refactors) and troughs (e.g., stabilization periods, planning, or holidays). + * Helps correlate process changes (code freezes, new tooling) with fluctuations in developer output. diff --git a/internal/docs/commits/markdown_handler.md b/internal/docs/commits/markdown_handler.md new file mode 100644 index 00000000..2ada54ab --- /dev/null +++ b/internal/docs/commits/markdown_handler.md @@ -0,0 +1,3 @@ +--- +title: "Commits Metrics" +--- diff --git a/internal/docs/deploy_freq/markdown_handler.md b/internal/docs/deploy_freq/markdown_handler.md new file mode 100644 index 00000000..b8981247 --- /dev/null +++ b/internal/docs/deploy_freq/markdown_handler.md @@ -0,0 +1,3 @@ +--- +title: "Deploy Frequency Metrics" +--- diff --git a/internal/docs/embed.go b/internal/docs/embed.go new file mode 100644 index 00000000..f964fd7f --- /dev/null +++ b/internal/docs/embed.go @@ -0,0 +1,10 @@ +package docs + +import "embed" + +//go:embed */*.md +var DocsFS embed.FS + +type MarkdownHandlerFrontmatter struct { + Title string `yaml:"title"` +} diff --git a/internal/docs/merge_freq/markdown_handler.md b/internal/docs/merge_freq/markdown_handler.md new file mode 100644 index 00000000..e00ea798 --- /dev/null +++ b/internal/docs/merge_freq/markdown_handler.md @@ -0,0 +1,3 @@ +--- +title: "Merge Frequency Metrics" +--- diff --git a/internal/docs/mr_opened/markdown_handler.md b/internal/docs/mr_opened/markdown_handler.md new file mode 100644 index 00000000..e00ea798 --- /dev/null +++ b/internal/docs/mr_opened/markdown_handler.md @@ -0,0 +1,3 @@ +--- +title: "Merge Frequency Metrics" +--- diff --git a/internal/oss-api/handler/code_chage.go b/internal/oss-api/handler/code_chage.go index 225db376..d1939da2 100644 --- a/internal/oss-api/handler/code_chage.go +++ b/internal/oss-api/handler/code_chage.go @@ -6,6 +6,7 @@ import ( api "github.com/dxta-dev/app/internal/oss-api" "github.com/dxta-dev/app/internal/data" + "github.com/dxta-dev/app/internal/docs" "github.com/dxta-dev/app/internal/markdown" "github.com/dxta-dev/app/internal/util" ) @@ -39,17 +40,19 @@ func CodeChangeMarkdownHandler(w http.ResponseWriter, r *http.Request) { return } + meta, body, err := util.ReadMarkdownFromFS[docs.MarkdownHandlerFrontmatter]( + docs.DocsFS, + "code_change/markdown_handler.md", + ) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + m, err := markdown.GetAggregatedValuesMarkdown( ctx, - "Code Change Metrics", - `The Code Change engineering metric quantifies the team’s weekly development activity by measuring the total number of lines of code added, modified, or deleted across our repositories. - -* **Source**: Computed from commit diffs in our Git version-control system, excluding merge commits and auto-generated files. -* **Aggregation**: Grouped by ISO week (Monday–Sunday). -* **Purpose**: - * Tracks engineering velocity and throughput over time. - * Highlights spikes (e.g., major feature work or refactors) and troughs (e.g., stabilization periods, planning, or holidays). - * Helps correlate process changes (code freezes, new tooling) with fluctuations in developer output.`, + meta.Title, + body, result, ) if err != nil { @@ -65,6 +68,13 @@ func CodeChangeMarkdownHandler(w http.ResponseWriter, r *http.Request) { } } +type OSSMetricQueryBuilder[ func(weeks []string, team *int64) data.AggregatedValuesQuery + + +func OSSMetricHandler[T any]() { +} + + func CodeChangeHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/internal/util/markdown_file.go b/internal/util/markdown_file.go new file mode 100644 index 00000000..b138ebe2 --- /dev/null +++ b/internal/util/markdown_file.go @@ -0,0 +1,39 @@ +package util + +import ( + "fmt" + "io/fs" + "strings" + + "gopkg.in/yaml.v2" +) + +func ReadMarkdownFromFS[T any](fsys fs.FS, path string) (meta T, body string, err error) { + data, err := fs.ReadFile(fsys, path) + if err != nil { + return meta, "", fmt.Errorf("failed to read %q: %w", path, err) + } + fm, b, err := splitFrontMatter(data) + if err != nil { + return meta, "", err + } + if err := yaml.Unmarshal(fm, &meta); err != nil { + return meta, "", fmt.Errorf("parsing frontmatter into %T: %w", meta, err) + } + return meta, string(b), nil +} + +func splitFrontMatter(data []byte) (fm []byte, body []byte, err error) { + const delim = "---\n" + text := string(data) + if !strings.HasPrefix(text, delim) { + return nil, data, nil + } + parts := strings.SplitN(text, "\n---\n", 2) + if len(parts) != 2 { + return nil, nil, fmt.Errorf("invalid frontmatter format") + } + fm = []byte(strings.TrimPrefix(parts[0], delim)) + body = []byte(parts[1]) + return fm, body, nil +}