forked from workflowr/workflowr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contribute.R
83 lines (65 loc) · 2.63 KB
/
contribute.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env Rscript
# Please run this script before you submit your Pull Request on GitHub.
#
# Usage:
# In the R console: source("contribute.R")
# In the terminal: Rscript contribute.R
# In RStudio: Click on Source (Ctrl/Cmd-Shift-s)
#
# Thanks for contributing to workflowr!
# Print warnings as they occur
options(warn = 1)
# Check required packages ------------------------------------------------------
message("* Checking that required dependencies are installed")
pkgs <- c("devtools", "fs", "git2r", "roxygen2", "spelling", "stringr",
"testthat", "withr")
installed <- rownames(installed.packages())
for (p in pkgs) {
if (!p %in% installed) {
msg <- sprintf("%s is required. Install with install.packages(\"%s\")", p, p)
stop(msg, call. = FALSE)
}
}
# Check setup ------------------------------------------------------------------
message("* Checking setup")
if (!file.exists("workflowr.Rproj")) {
stop("Please run this script from the root directory.",
"\nUse setwd() or in RStudio Click Session -> Set Working Directory -> To Project Directory",
call. = FALSE)
}
if (!git2r::in_repository()) {
stop("Something went wrong with the Git repository", call. = FALSE)
}
r <- git2r::repository()
# b <- git2r::repository_head(r)$name
remote_avail <- git2r::remotes(r)
if (!"origin" %in% remote_avail) {
warning("There is no remote named origin", call. = FALSE)
} else {
origin <- git2r::remote_url(r, "origin")
if (stringr::str_detect(origin, "jdblischak/workflowr.git$")) {
warning("The remote origin is set to the main workflowr repository.",
"\nDid you fork the repository on GitHub and then clone your fork?",
call. = FALSE)
}
}
# Update documentation ---------------------------------------------------------
message("* Updating documentation")
o <- utils::capture.output(suppressMessages(
devtools::document(roclets = c('rd', 'collate', 'namespace'))
))
# Notify to commit any changes to documentation files
status <- git2r::status(r)
changed <- c(unlist(status$unstaged), unlist(status$staged))
docs <- c("DESCRIPTION", fs::dir_ls("man/"), "NAMESPACE")
for (f in docs) {
if (f %in% changed) {
cat("To do: Please commit changes to", f, "\n")
}
}
# Check package ----------------------------------------------------------------
message("* Checking package (this might take a few minutes)")
devtools::check(document = FALSE, args = "--no-tests", quiet = TRUE,
error_on = "error")
# Finish -----------------------------------------------------------------------
message("* Congrats! Please commit your changes, push them to GitHub, and open a Pull Request")