official

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package official reads what GitHub itself shows on a profile: earned badges, their tiers, unlock dates and milestone history, and the profile highlights.

None of this is in GitHub's API. It comes from the public profile page and from the /users/<user>/achievements/<slug>/detail fragment GitHub loads into the badge dialog. Both are HTML, so every parser here is covered by fixtures saved from real profiles and by a weekly canary against live pages.

Index

Constants

This section is empty.

Variables

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound means GitHub has no such user.

Functions

func HasHighlight

func HasHighlight(highlights []string, name string) bool

HasHighlight matches a highlight by its whole label, ignoring a leading count and a plural. A substring match would let "Pro" match "Developer Program Member".

func IsLogin

func IsLogin(s string) bool

IsLogin reports whether s can be a GitHub username. Every entry point checks it before a username reaches a URL or a search query.

func ParseEarned

func ParseEarned(page string) []string

ParseEarned reads native achievement badge images and deduplicates their slugs.

func ParseHighlights

func ParseHighlights(page string) []string

ParseHighlights returns the labels in the profile's Highlights list.

func Text

func Text(fragment string) string

Text strips tags and collapses whitespace.

Types

type Client

type Client struct {
	HTTP *http.Client
	Base string // https://github.com
}

Client fetches official pages from github.com.

func NewClient

func NewClient() *Client

NewClient returns a client for github.com.

func (*Client) Detail

func (c *Client) Detail(user, slug string) (*Detail, error)

Detail reads GitHub's record of one earned badge. It returns nil when the badge is not earned, since GitHub serves the fragment only for earned badges.

func (*Client) Profile

func (c *Client) Profile(user string) (Profile, error)

Profile reads the achievements tab. The tab answers 404 both for a missing user and for one who hides achievements, so the profile page tells the two apart.

type Detail

type Detail struct {
	Slug       string      `json:"slug"`
	Name       string      `json:"name"`
	Tier       int         `json:"tier"`
	Unlocked   string      `json:"unlocked,omitempty"` // first unlock date, YYYY-MM-DD
	Milestones []Milestone `json:"milestones,omitempty"`
}

Detail is GitHub's own record of one earned badge.

func ParseDetail

func ParseDetail(slug, fragment string) Detail

ParseDetail reads one badge's detail fragment.

type Milestone

type Milestone struct {
	N     int    `json:"n,omitempty"`    // the ordinal GitHub counted to (2nd → 2), 0 if none
	PR    string `json:"pr,omitempty"`   // "owner/repo#123", empty when private ("inaccessible")
	Repo  string `json:"repo,omitempty"` // "owner/repo" for repository milestones (Starstruck)
	Label string `json:"label"`
}

Milestone is one row of a badge's history, e.g. "2nd pull request merged".

type Profile

type Profile struct {
	// Hidden is true when the user turned off "Show Achievements on my profile".
	Hidden     bool
	Earned     []string // badge slugs, in profile order
	Highlights []string
}

Profile is what the profile page shows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL