
GitHub Repository tools - file functions
Source:R/repo.R
, R/repo_add_file.R
, R/repo_delete_file.R
, and 5 more
repo_file.Rd
repo_add_file()
- Add / update files in a GitHub repository. Note that due to delays in caching, files that have been added very recently might not yet be displayed as existing and might accidentally be overwritten.repo_delete_file()
- Delete a file from a GitHub repositoryrepo_modify_file()
- Modify an existing file within a GitHub repository.repo_ls()
- Low level function for listing the files in a GitHub Repositoryrepo_put_file()
- Low level function for adding a file to a GitHub repositoryrepo_get_file()
- Low level function for retrieving the content of a file from a GitHub Repositoryrepo_get_readme()
- Low level function for retrieving the content of theREADME.md
of a GitHub Repository
Usage
repo_add_file(
repo,
file,
message = NULL,
repo_folder = NULL,
branch = NULL,
preserve_path = FALSE,
overwrite = FALSE
)
repo_delete_file(repo, path, message = NULL, branch = NULL)
repo_get_file(repo, path, branch = NULL, quiet = FALSE, include_details = TRUE)
repo_get_readme(repo, branch = NULL, include_details = TRUE)
repo_ls(repo, path = ".", branch = NULL, full_path = FALSE)
repo_modify_file(
repo,
path,
pattern,
content,
method = c("replace", "before", "after"),
all = FALSE,
message = "Modified content",
branch = NULL
)
repo_put_file(
repo,
path,
content,
message = NULL,
branch = NULL,
verbose = TRUE
)
Arguments
- repo
Character. Address of repository in
owner/name
format.- file
Character. Local file path(s) of file or files to be added.
- message
Character. Commit message.
- repo_folder
Character. Name of folder on repository to save the file(s) to. If the folder does not exist on the repository, it will be created.
- branch
Character. Name of branch to use.
- preserve_path
Logical. Should the local relative path be preserved.
- overwrite
Logical. Should existing file or files with same name be overwritten, defaults to FALSE.
- path
Character. File's path within the repository.
- quiet
Logical. Should status messages be printed.
- include_details
Logical. Should file details be attached as attributes.
repo_delete_file()
mrepo_modify_file()
, andrepo_put_file()
all invisibly return a list containing the results of the relevant GitHub API calls.repo_ls()
returns a character vector of repo files in the given path.repo_get_file()
andrepo_get_readme()
return a character vector with API results attached as attributes ifinclude_details = TRUE
- full_path
Logical. Should the function return the full path of the files and directories.
- pattern
Character. Regex pattern.
- content
Character or raw. Content of the file.
- method
Character. Should the content
replace
the matched pattern or be insertedbefore
orafter
the match.- all
Character. Should all instances of the pattern be modified (
TRUE
) or just the first (FALSE
).- verbose
Logical. Should success / failure messages be printed
Examples
# \dontrun{
repo = repo_create("ghclass-test", "repo_file_test", auto_init=TRUE)
#> ✔ Created repo "ghclass-test/repo_file_test".
repo_ls(repo, path = ".")
#> [1] ".gitignore" "README.md"
repo_get_readme(repo, include_details = FALSE)
#> [1] "# repo_file_test"
repo_get_file(repo, ".gitignore", include_details = FALSE)
#> [1] "# History files\n.Rhistory\n.Rapp.history\n\n# Session Data files\n.RData\n\n# User-specific files\n.Ruserdata\n\n# Example code in package build process\n*-Ex.R\n\n# Output files from R CMD build\n/*.tar.gz\n\n# Output files from R CMD check\n/*.Rcheck/\n\n# RStudio files\n.Rproj.user/\n\n# produced vignettes\nvignettes/*.html\nvignettes/*.pdf\n\n# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3\n.httr-oauth\n\n# knitr and R markdown default cache directories\n*_cache/\n/cache/\n\n# Temporary files created by R markdown\n*.utf8.md\n*.knit.md\n\n# R Environment Variables\n.Renviron\n"
repo_modify_file(
repo, path = "README.md", pattern = "repo_file_test",
content = "\n\nHello world!\n", method = "after"
)
#> ✔ Modified file "ghclass-test/repo_file_test/README.md".
repo_get_readme(repo, include_details = FALSE)
#> [1] "# repo_file_test\n\nHello world!\n"
repo_add_file(repo, file = system.file("DESCRIPTION", package="ghclass"))
#> ✔ Added file "DESCRIPTION" to repo "ghclass-test/repo_file_test".
repo_get_file(repo, "DESCRIPTION", include_details = FALSE)
#> [1] "Package: ghclass\nTitle: Tools for Managing Classes on GitHub\nVersion: 0.2.1\nAuthors@R: \n c(person(given = \"Colin\",\n family = \"Rundel\",\n role = c(\"aut\", \"cre\"),\n email = \"rundel@gmail.com\"),\n person(given = \"Mine\",\n family = \"Cetinkaya-Rundel\",\n role = \"aut\",\n email = \"mine@rstudio.com\"),\n person(given = \"Therese\",\n family = \"Anders\",\n role = \"ctb\",\n email = \"tanders@usc.edu\"))\nDescription: Interface for the GitHub API that enables efficient \n management of courses on GitHub. It has a functionality for \n managing organizations, teams, repositories, and users on GitHub \n and helps automate most of the tedious and repetitive tasks \n around creating and distributing assignments.\nLicense: GPL-3\nURL: https://github.com/rundel/ghclass\nBugReports: https://github.com/rundel/ghclass/issues\nDepends: R (>= 3.4.0)\nImports: base64enc, fs, gh, glue, httr, lubridate, purrr, rlang,\n tibble, whisker, withr, dplyr, cli (>= 3.0.0)\nSuggests: here, knitr, rmarkdown, sodium, styler, usethis, gert, readr,\n gitcreds\nEncoding: UTF-8\nLazyData: true\nRoxygen: list(markdown = TRUE)\nRoxygenNote: 7.1.2\nAuthor: Colin Rundel [aut, cre],\n Mine Cetinkaya-Rundel [aut],\n Therese Anders [ctb]\nMaintainer: Colin Rundel <rundel@gmail.com>\nBuilt: R 4.1.2; ; 2022-01-07 03:29:45 UTC; unix\n"
repo_delete_file(repo, "DESCRIPTION")
#> ✔ Deleted file DESCRIPTION from repo "ghclass-test/repo_file_test".
repo_delete(repo, prompt=FALSE)
#> ✔ Deleted repo "ghclass-test/repo_file_test".
# }