Learn R Programming

git2r (version 0.21.0)

contributions: Contributions

Description

See contributions to a Git repo

Usage

contributions(repo, breaks = c("month", "year", "quarter", "week", "day"),
  by = c("commits", "author"))

# S4 method for missing contributions(breaks, by)

# S4 method for character contributions(repo, breaks = c("month", "year", "quarter", "week", "day"), by = c("commits", "author"))

# S4 method for git_repository contributions(repo, breaks = c("month", "year", "quarter", "week", "day"), by = c("commits", "author"))

Arguments

repo

The repository object '>git_repository. If the repo argument is missing, the repository is searched for with discover_repository in the current working directory.

breaks

Default is month. Change to year, quarter, week or day as necessary.

by

Contributions by "commits" or "author". Default is "commits".

Value

A data.frame with contributions.

Examples

Run this code
# NOT RUN {
## Create directories and initialize repositories
path_bare <- tempfile(pattern="git2r-")
path_repo_1 <- tempfile(pattern="git2r-")
path_repo_2 <- tempfile(pattern="git2r-")
dir.create(path_bare)
dir.create(path_repo_1)
dir.create(path_repo_2)
repo_bare <- init(path_bare, bare = TRUE)

## Clone to repo 1 and config user
repo_1 <- clone(path_bare, path_repo_1)
config(repo_1, user.name="Alice", user.email="alice@example.org")

## Add changes to repo 1 and push to bare
writeLines("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do",
           con = file.path(path_repo_1, "test.txt"))
add(repo_1, "test.txt")
commit(repo_1, "First commit message")

## Add more changes to repo 1
writeLines(c("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do",
             "eiusmod tempor incididunt ut labore et dolore magna aliqua."),
           con = file.path(path_repo_1, "test.txt"))
add(repo_1, "test.txt")
commit(repo_1, "Second commit message")

## Push to bare
push(repo_1, "origin", "refs/heads/master")

## Clone to repo 2
repo_2 <- clone(path_bare, path_repo_2)
config(repo_2, user.name="Bob", user.email="bob@example.org")

## Add changes to repo 2
writeLines(c("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do",
             "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad",
             "minim veniam, quis nostrud exercitation ullamco laboris nisi ut"),
           con = file.path(path_repo_2, "test.txt"))
add(repo_2, "test.txt")
commit(repo_2, "Third commit message")

## Push to bare
push(repo_2, "origin", "refs/heads/master")

## Pull changes to repo 1
pull(repo_1)

## View contributions by day
contributions(repo_1)

## View contributions by author and day
contributions(repo_1, by = "author")
# }

Run the code above in your browser using DataLab