Documentation
¶
Overview ¶
Package traffic owns the M4 "traffic" plugin. It aggregates per- repository view counts from REST /repos/{owner}/{repo}/traffic/views for every repository in base.Computed.RepositoryList. The endpoint requires the `repo` OAuth scope; without it the plugin returns Skipped=true. Repositories that fail are dropped and aggregation continues; up to three aggregated AppendErrors are recorded (one per non-zero bucket: rate limited / forbidden / failed) so the degradation is observable via Result.Errors / JSON output.
Index ¶
Constants ¶
const Name = "traffic"
Name is the canonical plugin slug.
Variables ¶
var Plugin plugins.Plugin = &trafficPlugin{}
Plugin is the singleton registered with the global plugin registry.
Functions ¶
func Partial ¶
Partial renders the classic SVG fragment for the traffic plugin. Upstream classic does not ship a standalone traffic.ejs (the data is merged into base.repositories); we emit a self-contained section with header + aggregate counts + per-repo breakdown so downstream consumers can see the data the plugin actually collects.
Output structure:
<section data-section="traffic">
<h2 class="field"><svg/>Traffic</h2>
<div class="row"><section>
<div class="field"><span class="label">N views (M unique)</span></div>
[for each repo with views]:
<div class="field"><span class="repo">${name}</span>: ${views} views (${uniques} unique)</div>
</section></div>
</section>
When `plugin_traffic_hide_empty` is true (default), repositories with Count == 0 are filtered before sorting/rendering so the per-repo breakdown only shows repos that actually received traffic.
Types ¶
type Result ¶
type Result struct {
Skipped bool `json:"skipped,omitempty"`
SkippedReason string `json:"-"`
Views map[string]TrafficView `json:"views"`
Total TrafficView `json:"total"`
// HideEmpty controls whether per-repo entries with Count==0 are
// filtered out at render time. It mirrors the
// `plugin_traffic_hide_empty` input (default true).
HideEmpty bool `json:"hide_empty"`
}
Result is the JSON payload published under data.Plugins["traffic"].
func (*Result) TotalViews ¶ added in v1.2.0
TotalViews exposes the aggregate view count without forcing base partials to import this package and create an init-time cycle.
type TrafficView ¶
TrafficView mirrors the upstream {count, uniques} pair.