To make GitStats
work
you need to set hosts after creating gitstats_object
.
You can set GitLab host with set_gitlab_host()
and
GitHub host with set_github_host()
or both.
When setting hosts you need to take into account:
Do you wish to connect to private
or
public
hosts?
What scanning scope
do you wish to set? Do you want
to scan specific organizations
or repositories
or maybe whole git platforms?
Do you have tokens
set up and stored in your
environment variables that grant you access to APIs?
If you connect to public hosts you simply call
set_github_host()
or set_gitlab_host()
function without specifying host
parameter.
library(GitStats)
git_stats <- create_gitstats() %>%
set_github_host(
orgs = c("r-world-devs", "openpharma"),
token = Sys.getenv("GITHUB_PAT")
) %>%
set_gitlab_host(
orgs = c("mbtests"),
token = Sys.getenv("GITLAB_PAT_PUBLIC")
)
If you wish to connect to internal GitHub or GitLab, you need to pass
names of the hosts to host
parameter. Remember also to have
tokens set up properly for these hosts (on tokens read below).
git_stats <- create_gitstats() %>%
set_github_host(
host = "github.internal.com",
orgs = c("org_1", "org_2", "org_3"),
token = Sys.getenv("YOUR_GITHUB_PAT")
) %>%
set_gitlab_host(
host = "internal.host.com",
orgs = c("internal_org"),
token = Sys.getenv("YOUR_GITLAB_PAT")
)
GitStats is configured to connect to GitHub API (version 3) and GitLab API (version 4).
When setting hosts you choose what scanning scope of your GitStats will be:
organizations/groups
- in this case you need to pass
character arguments (names of organizations (in case of GitHub) or
groups (in case of GitLab)) to orgs
parameter.git_stats <- create_gitstats() %>%
set_github_host(
orgs = c("r-world-devs", "openpharma"),
token = Sys.getenv("GITHUB_PAT")
) %>%
set_gitlab_host(
orgs = c("mbtests"),
token = Sys.getenv("GITLAB_PAT_PUBLIC")
)
repositories
- in this case you need to pass full names
of repositories ({org_name}/{repo_name}
) to the
repos
parameter.git_stats <- create_gitstats() %>%
set_github_host(
repos = c("r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder", "openpharma/DataFakeR"),
token = Sys.getenv("GITHUB_PAT")
) %>%
set_gitlab_host(
repos = "mbtests/gitstatstesting",
token = Sys.getenv("GITLAB_PAT_PUBLIC")
)
whole hosts
- this is possible for the time being only
in case of private hosts, as public ones are deemed to be too large. To
set whole Git platform to be scanned just set hosts without specifying
orgs
or repos
. On the other hand, remember
that to connect with internal host, you need to pass argument to
host
parameter.