Reads the statistics of the repositories a GitHub user owns and adds them to the history in
dir, one CSV file per table, so that it grows beyond the 14 days of traffic GitHub keeps.
Run it at least once a week, by hand or with the workflow of use_rghcard_action().
Usage
collect_stats(
user = NULL,
dir = "rghcard-data",
token = NULL,
include_private = FALSE,
include_forks = FALSE,
actions_days = 14,
contributions_token = token
)Arguments
- user
GitHub user name. By default the owner of the token or, in a GitHub Actions workflow, the owner of the repository it runs in.
- dir
Folder of the history, created if needed.
NULLkeeps nothing on disk.- token
GitHub token. By default the one that gh finds: the
GITHUB_PATorGITHUB_TOKENenvironment variable, or the git credential store. A token that GitHub refuses, because it expired or was revoked, stopscollect_stats()with a message on how to replace it.- include_private
Include private repositories, and the commits in them?
FALSEby default: the cards and the history are usually public, and would show their names and numbers.- include_forks
Include forks, and the commits in them?
FALSEby default.- actions_days
Read the GitHub Actions runs of the last
actions_daysdays.- contributions_token
GitHub token for the contributions, the commits and their types, by default
token. A token of someone else than the user, such as theGITHUB_TOKENof a GitHub Actions workflow, reads them as the profile shows them to others: the private contributions as bare numbers, when the profile shows them. Private repositories, withinclude_private, need a token of the user that can read them.
Value
The whole history, invisibly: an rghcard_stats object, the same as read_stats()
returns.
Details
Page views and clones (the traffic) are read only with a token of the user, since GitHub
shows the traffic of a repository only to those who can push to it. Without one, or for
another user, collect_stats() collects the public statistics: repositories, stars, forks,
languages, release downloads, GitHub Actions runs and contributions. The contributions come
from GitHub's GraphQL API, which answers any token but none without one, and as the token sees
them: a fine-grained token of the user that reads only the traffic leaves the private
contributions out, which a profile can show as bare numbers. contributions_token reads them
with another token; the rghcard action reads them with the token of its workflow, which sees
the profile as others see it.
The history has these tables:
repos: stars, forks, watchers, open issues, size, main language and last push of each repository, one row per repository on each day it is collected.viewsandclones: page views and clones of each repository per day (UTC days, as GitHub counts them), with the unique visitors and cloners of the day.traffic: the page views and clones of each repository in the 14 days that GitHub keeps, with its unique visitors and cloners in them, on each day it is collected.referrersandpages: the ten top referring sites of each repository and its ten most viewed pages, with their page views and unique visitors, in those 14 days, on each day it is collected.releases: downloads of each file of each release, on each day it is collected.actions: GitHub Actions runs, one row per run, with when it started and finished.languages: the bytes of code of each repository in each language, as GitHub counts them.stars: the time of each star of each repository.profile: the followers of the user, and the users they follow, on each day it is collected.contributions: the contributions of each day since the user joined GitHub, as the contribution graph of their profile counts them, private ones included as bare numbers when the profile shows them.commits: the commits of the user per repository and year, in repositories of anyone.contribution_types: the contributions of each year by type: commits, issues, pull requests, reviews, repositories created, and private ones as bare numbers.
Each collection reads the languages, the stars, the contributions, the commits and the contribution types whole and replaces their tables. The names of those who star, visit or clone are never collected: GitHub does not give them for the traffic, and the history is usually public.
See also
contributions_card(), stats_card(), activity_card(), visitors_card(),
actions_card() and code_card() draw the cards, read_stats() reads the history again.
Examples
if (FALSE) { # \dontrun{
stats <- collect_stats()
contributions_card(stats, "rghcard-contributions.svg")
stats_card(stats, "rghcard-stats.svg")
visitors_card(stats, "rghcard-visitors.svg")
} # }