Skip to content

Commit 3faeea8

Browse files
committed
Improve documentation
1 parent 0cd2e07 commit 3faeea8

26 files changed

+412
-200
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Description: Read all commit messages of your local git repository and
2222
organisms required to testify for every changes in their source code,
2323
in relation to features requests.
2424
License: MIT + file LICENSE
25-
URL: https://github.com/Thinkr-open/gitdown
25+
URL: https://thinkr-open.github.io/gitdown,
26+
https://github.com/Thinkr-open/gitdown
2627
BugReports: https://github.com/Thinkr-open/gitdown/issues
2728
Depends:
2829
R (>= 3.4)
@@ -45,4 +46,5 @@ Suggests:
4546
VignetteBuilder:
4647
knitr
4748
Encoding: UTF-8
49+
Roxygen: list(markdown = TRUE)
4850
RoxygenNote: 7.1.1

R/fake_repo.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#' @importFrom git2r init config add commit tag
1010
#' @export
1111
#'
12-
#' @return A few files and an initiated git repository in 'path'.
13-
#' Returns the path of the fake repository.
12+
#' @return Character. Path of a fake repository used for reproducible examples.
13+
#' Fake repository contains a few files with an initiated git repository.
1414
#' @examples
1515
#' # Fake repository with git
1616
#' fake_repo()

R/get_commits.R

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
#' @inheritParams git2r::commits
44
#' @param silent Logical. Whether to hide messages.
55
#'
6-
#' @return A tibble with commits content, information and associated tags
6+
#' @return A tibble with one line for each commit and the following columns:
7+
#'
8+
#' - sha: sha of the commit
9+
#' - summary: First line of the commit message
10+
#' - message: Full content of the commit message
11+
#' - author: author of the commit
12+
#' - email: email of the author
13+
#' - when: commit time
14+
#' - order: order of commit messages. 1 is the oldest.
15+
#' - tag.name: name of tag associated with all commits since the last tag
16+
#' - tag.message: message of the tagged commit
717
#'
818
#' @importFrom git2r commits tags
919
#' @importFrom purrr map_dfr flatten
@@ -61,13 +71,26 @@ get_commits_tags <- function(repo = ".", ref = "master",
6171

6272
#' Get commits associated with a text pattern
6373
#'
64-
#' @param pattern Named vector with regex pattern to expose commits, like c("Issues" = "#[[:digit:]]") for issues
65-
#' @param pattern.table data.frame with two columns: pattern and description.
74+
#' @param pattern Named vector with regex pattern to expose commits, like `c("Issues" = "#\[\[:digit:\]\]")` for issues
75+
#' @param pattern.table data.frame with two columns: pattern and description of the pattern.
6676
#' This is used as correspondence table to add some names to existing patterns.
6777
#' @inheritParams git2r::commits
6878
#' @inheritParams get_commits_tags
6979
#'
70-
#' @return A tibble with commits content, information, associated tags and associated patterns found.
80+
#' @return A tibble with one line for each commit, duplicated if
81+
#' associated with multiple patterns and the following columns:
82+
#'
83+
#' - sha: sha of the commit
84+
#' - summary: First line of the commit message
85+
#' - message: Full content of the commit message
86+
#' - author: author of the commit
87+
#' - email: email of the author
88+
#' - when: commit time
89+
#' - order: order of commit messages. 1 is the oldest.
90+
#' - tag.name: name of tag associated with all commits since the last tag
91+
#' - tag.message: message of the tagged commit
92+
#' - pattern.type: name of the pattern found in the commit message
93+
#' - pattern.content: pattern found in the commit message
7194
#'
7295
#' @importFrom dplyr mutate distinct rowwise tibble left_join mutate
7396
#' @importFrom dplyr if_else mutate_all filter select

R/get_info_files.R

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' @param object hunks list
44
#'
55
#' @return time
6+
#' @noRd
67
get_time <- function(object) {
78
pluck(object, "final_signature", "when", "time")
89
}
@@ -12,7 +13,16 @@ get_time <- function(object) {
1213
#' @param path path to the file
1314
#' @param repo repo of the git project
1415
#'
15-
#' @return A list with information on first and last modification time of the selected file.
16+
#' @return A list with information of the selected file:
17+
#'
18+
#' - file: file name
19+
#' - in_repository: Logical. Whether the file has already been commit once in the
20+
#' git repository
21+
#' - first_modif: time of first modification. Commit time if in the git repository,
22+
#' system date of creation otherwise.
23+
#' - last_modif: time of last modification. Commit time if in the git repository,
24+
#' system date of last modification otherwise.
25+
#'
1626
#' @export
1727
#'
1828
#' @importFrom git2r blame
@@ -61,14 +71,23 @@ get_info <- function(path, repo = ".") {
6171
)
6272
}
6373

64-
#' Get the first and last modification time of files of a repository
74+
#' Get the first and last modification time of files of a directory
6575
#'
6676
#' @param repo git repository
67-
#' @param path Default to R folder. Use "" for the complete repository.
77+
#' @param path Default to R folder. Use "" for the complete directory
6878
#' @param recursive Logical. Should the listing recurse into directories?
6979
#' @param untracked Logical. Should the not tracked files be included?
7080
#'
71-
#' @return A list of files with information on first and last modification time.
81+
#' @return A list of files with information of each file:
82+
#'
83+
#' - file: file name
84+
#' - in_repository: Logical. Whether the file has already been commit once in the
85+
#' git repository
86+
#' - first_modif: time of first modification. Commit time if in the git repository,
87+
#' system date of creation otherwise.
88+
#' - last_modif: time of last modification. Commit time if in the git repository,
89+
#' system date of last modification otherwise.
90+
#'
7291
#' @export
7392
#'
7493
#' @importFrom purrr map
@@ -147,7 +166,8 @@ present_files <- function(repo = ".", path = "R",
147166

148167
#' Creates and updates a vignette in the 'vignette/' directory of a package with last modification time of tracked files
149168
#'
150-
#' @return Creates and updates the content of the "modification_files.Rmd" vignette
169+
#' @return No return value, called for side effect.
170+
#' Creates and updates the content of the "modification_files.Rmd" vignette
151171
#' @export
152172
#'
153173
#' @rdname create_vignette_last_modif

R/git_down.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Turns the history of git into a bookdown.
1+
#' Turns the active branch history of git into a bookdown.
22
#'
33
#' Read all commit messages of your local git repository and
44
#' sort them according to tags or specific text pattern into chapters of
@@ -10,12 +10,12 @@
1010
#' @param open Should the bookdown be opened once compiled? Default is TRUE.
1111
#' @param author Author of the bookdown
1212
#' @param ref the name of the branch, by default master
13-
#' @param ... Other parameters to pass to \code{\link[rmarkdown]{render}}
13+
#' @param ... Other parameters to pass to [rmarkdown::render()]
1414
#'
1515
#' @inheritParams get_commits_pattern
1616
#' @export
1717
#'
18-
#' @return A directory with content of a HTML gitbook
18+
#' @return Path of the HTML gitbook saved in the repo/book_path directory.
1919
#'
2020
#' @importFrom attempt if_not
2121
#' @importFrom rmarkdown render

R/gitdown-package.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#' @description Read all commit messages of your local git repository
2+
#' and sort them according to tags or specific text pattern into chapters
3+
#' of a HTML book using 'bookdown'.
4+
#' The git history book presentation helps organisms required to testify
5+
#' for every changes in their source code, in relation to features requests.
6+
#'
7+
#' The main functions to be used in this package are [git_down()] and [create_vignette_last_modif()]
8+
#' @keywords internal
9+
"_PACKAGE"
10+
11+
# The following block is used by usethis to automatically manage
12+
# roxygen namespace tags. Modify with care!
13+
## usethis namespace: start
14+
## usethis namespace: end
15+
NULL

R/utils-pipe.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Pipe operator
22
#'
3-
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
3+
#' See `magrittr::[\%>\%][magrittr::pipe]` for details.
44
#'
55
#' @name %>%
66
#' @rdname pipe

R/utils.R

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,32 @@ to_singular <- function(x) {
104104
#' @importFrom stringi stri_extract_all
105105
#' @importFrom tidyr nest
106106
#'
107-
#' @return A tibble with a row for each different pattern found and
107+
#' @return A tibble with a row for each different pattern found in commit messages
108+
#' and following columns:
109+
#'
110+
#' - pattern.type: name of the pattern found in the commit message
111+
#' - pattern.content: pattern found in the commit message
112+
#' - pattern.title: pattern.content or title used in the pattern.table
108113
#' a nested 'data' column with all related commits
114+
#' - pattern_numeric: extraction of numeric value in pattern.content
115+
#' - link_pattern: internal url of the pattern in the future HTML gitbook
116+
#' - data: a nested list of tibbles with commits content as issued from [get_commits_pattern()]
109117
#'
110118
#' @export
111119
#' @examples
112120
#' repo <- fake_repo()
113121
#' nest_commits_by_pattern(repo)
122+
#'
123+
#' # With table of correspondence
124+
#' pattern.table <- data.frame(
125+
#' number = c("#2", "#1", "#1000"),
126+
#' title = c("#2 A second issue to illustrate a blog post",
127+
#' "#1 An example of issue",
128+
#' "#1000 issue with no commit"))
129+
#' nest_commits_by_pattern(
130+
#' repo,
131+
#' pattern.table = pattern.table,
132+
#' pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"))
114133

115134
nest_commits_by_pattern <- function(repo,
116135
pattern = c("Issues" = "#[[:digit:]]+"),
@@ -175,7 +194,18 @@ nest_commits_by_pattern <- function(repo,
175194
#' @importFrom purrr map_chr pmap
176195
#' @export
177196
#' @return A tibble with a row for each different pattern found and
178-
#' a 'text' column to be included in a markdown file.
197+
#' a 'text' column to be included in a markdown file:
198+
#'
199+
#' - pattern.content: pattern found in the commit message
200+
#' - link_pattern: internal url of the pattern in the future HTML gitbook
201+
#' - text: list of vectors of markdown text to present commits of each pattern
202+
#' in the HTML gitbook output
203+
#' - pattern.type: name of the pattern found in the commit message
204+
#' - pattern.title: pattern.content or title used in the pattern.table
205+
#' a nested 'data' column with all related commits
206+
#' - pattern_numeric: extraction of numeric value in pattern.content
207+
#' - data: a nested list of tibbles with commits content as issued from [get_commits_pattern()]
208+
#'
179209
#' @examples
180210
#' repo <- fake_repo()
181211
#' res_commits <- nest_commits_by_pattern(

README.Rmd

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ You can install the last version of {gitdown} from Github:
4040
remotes::install_github("ThinkR-open/gitdown")
4141
```
4242

43-
## Example
43+
## Create a reproducible example of a versioned directory
44+
45+
Create a versioned directory with some commits and a NEWS.md in a temporary directory
46+
47+
- Some commits mention an issue with `#`
48+
- Some commits mention a ticket with `ticket`
49+
- A commit is associated with a tag
4450

4551
```{r example, message=FALSE}
4652
library(dplyr)
@@ -49,26 +55,11 @@ library(gitdown)
4955
repo <- fake_repo()
5056
```
5157

52-
Get commits with issues mentioned. The searched pattern is a `#` followed by at least one number: `"#[[:digit:]]+"`. Variable `pattern.content` lists patterns found in the commit messages.
53-
54-
```{r}
55-
get_commits_pattern(repo, pattern = "#[[:digit:]]+", ref = "master") %>%
56-
select(pattern.content, everything())
57-
```
58-
59-
Get commits with issues and specific home-made pattern. Use a named vector to properly separate types of patterns.
60-
61-
```{r}
62-
get_commits_pattern(
63-
repo,
64-
pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"),
65-
ref = "master"
66-
) %>%
67-
select(pattern.type, pattern.content, everything())
68-
```
69-
7058
## Create a gitbook of commits sorted by a pattern
7159

60+
The main function of {gitdown} is to build this gitbook with all commit messages ordered according to a pattern. Each commit message associated with an issue will be recorded in the section of this issue. A commit message can thus appears multiple times if it is associated with multiple issues.
61+
If you have your own referencing system for tickets in an external software, you can also create the gitbook associated like using `ticket` as in the example below.
62+
7263
```{r, eval=FALSE}
7364
git_down(repo, pattern = c("Tickets" = "ticket[[:digit:]]+",
7465
"Issues" = "#[[:digit:]]+"))
@@ -79,7 +70,8 @@ knitr::include_graphics("reference/figures/gitdown_links.png")
7970
```
8071

8172
If you add a table of correspondence, you can change titles of the patterns.
82-
_Note that you can use [{gitlabr}](https://statnmap.github.io/gitlabr/) or [{gh}](https://gh.r-lib.org) to retrieve list of issues from Gitlab or Github respectively._
73+
_Note that you can use [{gitlabr}](https://statnmap.github.io/gitlabr/) or [{gh}](https://gh.r-lib.org) to retrieve list of issues from Gitlab or Github respectively, as presented in ["Download Gitlab or Github issues and make a summary report of your commits"](https://rtask.thinkr.fr/download-gitlab-or-github-issues-and-make-a-summary-report-of-your-commits/)._
74+
8375
```{r, eval=FALSE}
8476
# With table of correspondence
8577
pattern.table <- data.frame(
@@ -99,6 +91,29 @@ _Note that characters like `[`, `]`, `_` or `*` will be replaced by `-` in the t
9991
knitr::include_graphics("reference/figures/issues-with-title.png")
10092
```
10193

94+
## Read list of commits and extract information
95+
96+
As a side effect of {gitdown}, you can get some intermediate information used to build the book with some exported functions.
97+
98+
Get commits with issues mentioned. The searched pattern is a `#` followed by at least one number: `"#[[:digit:]]+"`. Variable `pattern.content` lists patterns found in the commit messages.
99+
100+
```{r}
101+
get_commits_pattern(repo, pattern = "#[[:digit:]]+", ref = "master") %>%
102+
select(pattern.content, everything())
103+
```
104+
105+
Get commits with issues and specific home-made pattern. Use a named vector to properly separate types of patterns.
106+
107+
```{r}
108+
get_commits_pattern(
109+
repo,
110+
pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"),
111+
ref = "master"
112+
) %>%
113+
select(pattern.type, pattern.content, everything())
114+
```
115+
116+
102117
## Create a vignette that lists all files with date of modification
103118

104119
```{r, eval=FALSE}

0 commit comments

Comments
 (0)