├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── R ├── commands.R └── utilities.R ├── README.Rmd ├── README.md ├── appveyor.yml ├── knowledgerepo.Rproj ├── man-roxygen └── extra-args.R └── man ├── after_submit.Rd ├── get_remote_link.Rd ├── kr_add.Rd ├── kr_command.Rd ├── kr_create.Rd ├── kr_deploy.Rd ├── kr_init.Rd ├── kr_preview.Rd ├── kr_runserver.Rd ├── kr_status.Rd └── kr_submit.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^CODE_OF_CONDUCT\.md$ 5 | ^README\.Rmd$ 6 | ^\.travis\.yml$ 7 | man-roxygen 8 | ^appveyor\.yml$ 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: 6 | - packages 7 | - pip 8 | python: 9 | - "2.7" 10 | before_install: 11 | - sudo pip install knowledge-repo 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http://contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: knowledgerepo 2 | Type: Package 3 | Title: R Interface to Knowledge Repository 4 | Version: 0.1.0 5 | Author: David Robinson 6 | Maintainer: David Robinson 7 | Description: R package that wraps the command line interface 8 | to AirBnB's Knowledge Repository project. 9 | License: Apache License (>= 2.0) 10 | Encoding: UTF-8 11 | LazyData: true 12 | Imports: 13 | purrr, 14 | stringr, 15 | git2r, 16 | rmarkdown 17 | RoxygenNote: 6.0.1 18 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | ============== 3 | 4 | _Version 2.0, January 2004_ 5 | _<>_ 6 | 7 | ### Terms and Conditions for use, reproduction, and distribution 8 | 9 | #### 1. Definitions 10 | 11 | “License” shall mean the terms and conditions for use, reproduction, and 12 | distribution as defined by Sections 1 through 9 of this document. 13 | 14 | “Licensor” shall mean the copyright owner or entity authorized by the copyright 15 | owner that is granting the License. 16 | 17 | “Legal Entity” shall mean the union of the acting entity and all other entities 18 | that control, are controlled by, or are under common control with that entity. 19 | For the purposes of this definition, “control” means **(i)** the power, direct or 20 | indirect, to cause the direction or management of such entity, whether by 21 | contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the 22 | outstanding shares, or **(iii)** beneficial ownership of such entity. 23 | 24 | “You” (or “Your”) shall mean an individual or Legal Entity exercising 25 | permissions granted by this License. 26 | 27 | “Source” form shall mean the preferred form for making modifications, including 28 | but not limited to software source code, documentation source, and configuration 29 | files. 30 | 31 | “Object” form shall mean any form resulting from mechanical transformation or 32 | translation of a Source form, including but not limited to compiled object code, 33 | generated documentation, and conversions to other media types. 34 | 35 | “Work” shall mean the work of authorship, whether in Source or Object form, made 36 | available under the License, as indicated by a copyright notice that is included 37 | in or attached to the work (an example is provided in the Appendix below). 38 | 39 | “Derivative Works” shall mean any work, whether in Source or Object form, that 40 | is based on (or derived from) the Work and for which the editorial revisions, 41 | annotations, elaborations, or other modifications represent, as a whole, an 42 | original work of authorship. For the purposes of this License, Derivative Works 43 | shall not include works that remain separable from, or merely link (or bind by 44 | name) to the interfaces of, the Work and Derivative Works thereof. 45 | 46 | “Contribution” shall mean any work of authorship, including the original version 47 | of the Work and any modifications or additions to that Work or Derivative Works 48 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 49 | by the copyright owner or by an individual or Legal Entity authorized to submit 50 | on behalf of the copyright owner. For the purposes of this definition, 51 | “submitted” means any form of electronic, verbal, or written communication sent 52 | to the Licensor or its representatives, including but not limited to 53 | communication on electronic mailing lists, source code control systems, and 54 | issue tracking systems that are managed by, or on behalf of, the Licensor for 55 | the purpose of discussing and improving the Work, but excluding communication 56 | that is conspicuously marked or otherwise designated in writing by the copyright 57 | owner as “Not a Contribution.” 58 | 59 | “Contributor” shall mean Licensor and any individual or Legal Entity on behalf 60 | of whom a Contribution has been received by Licensor and subsequently 61 | incorporated within the Work. 62 | 63 | #### 2. Grant of Copyright License 64 | 65 | Subject to the terms and conditions of this License, each Contributor hereby 66 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 67 | irrevocable copyright license to reproduce, prepare Derivative Works of, 68 | publicly display, publicly perform, sublicense, and distribute the Work and such 69 | Derivative Works in Source or Object form. 70 | 71 | #### 3. Grant of Patent License 72 | 73 | Subject to the terms and conditions of this License, each Contributor hereby 74 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 75 | irrevocable (except as stated in this section) patent license to make, have 76 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 77 | such license applies only to those patent claims licensable by such Contributor 78 | that are necessarily infringed by their Contribution(s) alone or by combination 79 | of their Contribution(s) with the Work to which such Contribution(s) was 80 | submitted. If You institute patent litigation against any entity (including a 81 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 82 | Contribution incorporated within the Work constitutes direct or contributory 83 | patent infringement, then any patent licenses granted to You under this License 84 | for that Work shall terminate as of the date such litigation is filed. 85 | 86 | #### 4. Redistribution 87 | 88 | You may reproduce and distribute copies of the Work or Derivative Works thereof 89 | in any medium, with or without modifications, and in Source or Object form, 90 | provided that You meet the following conditions: 91 | 92 | * **(a)** You must give any other recipients of the Work or Derivative Works a copy of 93 | this License; and 94 | * **(b)** You must cause any modified files to carry prominent notices stating that You 95 | changed the files; and 96 | * **(c)** You must retain, in the Source form of any Derivative Works that You distribute, 97 | all copyright, patent, trademark, and attribution notices from the Source form 98 | of the Work, excluding those notices that do not pertain to any part of the 99 | Derivative Works; and 100 | * **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any 101 | Derivative Works that You distribute must include a readable copy of the 102 | attribution notices contained within such NOTICE file, excluding those notices 103 | that do not pertain to any part of the Derivative Works, in at least one of the 104 | following places: within a NOTICE text file distributed as part of the 105 | Derivative Works; within the Source form or documentation, if provided along 106 | with the Derivative Works; or, within a display generated by the Derivative 107 | Works, if and wherever such third-party notices normally appear. The contents of 108 | the NOTICE file are for informational purposes only and do not modify the 109 | License. You may add Your own attribution notices within Derivative Works that 110 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 111 | provided that such additional attribution notices cannot be construed as 112 | modifying the License. 113 | 114 | You may add Your own copyright statement to Your modifications and may provide 115 | additional or different license terms and conditions for use, reproduction, or 116 | distribution of Your modifications, or for any such Derivative Works as a whole, 117 | provided Your use, reproduction, and distribution of the Work otherwise complies 118 | with the conditions stated in this License. 119 | 120 | #### 5. Submission of Contributions 121 | 122 | Unless You explicitly state otherwise, any Contribution intentionally submitted 123 | for inclusion in the Work by You to the Licensor shall be under the terms and 124 | conditions of this License, without any additional terms or conditions. 125 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 126 | any separate license agreement you may have executed with Licensor regarding 127 | such Contributions. 128 | 129 | #### 6. Trademarks 130 | 131 | This License does not grant permission to use the trade names, trademarks, 132 | service marks, or product names of the Licensor, except as required for 133 | reasonable and customary use in describing the origin of the Work and 134 | reproducing the content of the NOTICE file. 135 | 136 | #### 7. Disclaimer of Warranty 137 | 138 | Unless required by applicable law or agreed to in writing, Licensor provides the 139 | Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, 140 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 141 | including, without limitation, any warranties or conditions of TITLE, 142 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 143 | solely responsible for determining the appropriateness of using or 144 | redistributing the Work and assume any risks associated with Your exercise of 145 | permissions under this License. 146 | 147 | #### 8. Limitation of Liability 148 | 149 | In no event and under no legal theory, whether in tort (including negligence), 150 | contract, or otherwise, unless required by applicable law (such as deliberate 151 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 152 | liable to You for damages, including any direct, indirect, special, incidental, 153 | or consequential damages of any character arising as a result of this License or 154 | out of the use or inability to use the Work (including but not limited to 155 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 156 | any and all other commercial damages or losses), even if such Contributor has 157 | been advised of the possibility of such damages. 158 | 159 | #### 9. Accepting Warranty or Additional Liability 160 | 161 | While redistributing the Work or Derivative Works thereof, You may choose to 162 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 163 | other liability obligations and/or rights consistent with this License. However, 164 | in accepting such obligations, You may act only on Your own behalf and on Your 165 | sole responsibility, not on behalf of any other Contributor, and only if You 166 | agree to indemnify, defend, and hold each Contributor harmless for any liability 167 | incurred by, or claims asserted against, such Contributor by reason of your 168 | accepting any such warranty or additional liability. 169 | 170 | _END OF TERMS AND CONDITIONS_ 171 | 172 | ### APPENDIX: How to apply the Apache License to your work 173 | 174 | To apply the Apache License to your work, attach the following boilerplate 175 | notice, with the fields enclosed by brackets `[]` replaced with your own 176 | identifying information. (Don't include the brackets!) The text should be 177 | enclosed in the appropriate comment syntax for the file format. We also 178 | recommend that a file or class name and description of purpose be included on 179 | the same “printed page” as the copyright notice for easier identification within 180 | third-party archives. 181 | 182 | Copyright 2018 David Robinson 183 | 184 | Licensed under the Apache License, Version 2.0 (the "License"); 185 | you may not use this file except in compliance with the License. 186 | You may obtain a copy of the License at 187 | 188 | http://www.apache.org/licenses/LICENSE-2.0 189 | 190 | Unless required by applicable law or agreed to in writing, software 191 | distributed under the License is distributed on an "AS IS" BASIS, 192 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 193 | See the License for the specific language governing permissions and 194 | limitations under the License. 195 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(kr_add) 4 | export(kr_command) 5 | export(kr_create) 6 | export(kr_deploy) 7 | export(kr_init) 8 | export(kr_preview) 9 | export(kr_runserver) 10 | export(kr_status) 11 | export(kr_submit) 12 | -------------------------------------------------------------------------------- /R/commands.R: -------------------------------------------------------------------------------- 1 | # This file wraps commands from the Knowledge Repo CLI 2 | 3 | #' Create a new post from a default template 4 | #' 5 | #' Creates a new post from the built in template, using either 6 | #' Rmd (default), IPython notebook, or Markdown 7 | #' 8 | #' @param filename Where this file should be created. 9 | #' @param format The format of the knowledge post to be created: 10 | #' either Rmd, ipynb, or md. By default, retrieved from the extension 11 | #' of the filename. 12 | #' @param template Optionally, a template to create the knowledge post from. 13 | #' 14 | #' @template extra-args 15 | #' 16 | #' @examples 17 | #' 18 | #' # set up a repository and post 19 | #' repo <- tempfile() 20 | #' kr_init(repo) 21 | #' kr_create("test.Rmd", repo = repo) 22 | #' 23 | #' @export 24 | kr_create <- function(filename, format = NULL, template = NULL, ...) { 25 | if (is.null(format)) { 26 | format <- tools::file_ext(filename) 27 | # to be case insensitive 28 | format <- switch(tolower(format), 29 | rmd = "Rmd", 30 | ipynb = "ipynb", 31 | md = "md", 32 | stop("Extension '", format, "' not recognized")) 33 | } 34 | 35 | kr_command(..., 36 | "create", 37 | template = template, 38 | format, 39 | filename) 40 | } 41 | 42 | 43 | #' Add a post to a knowledge repository 44 | #' 45 | #' Add a local file to a knowledge repository. Unless submit = TRUE, this doesn't 46 | #' (yet) submit the post. 47 | #' 48 | #' @param filename Filename to add 49 | #' @param path The path of the destination post to be added in the 50 | #' knowledge repo. Required if the knowledge post does 51 | #' not specify "path" in its headers. 52 | #' @param update Whether this should update an existing post of the 53 | #' same name. 54 | #' @param branch The branch to use for this addition, if not the 55 | #' default (which is the path of the knowledge post). 56 | #' @param squash Automatically suppress all previous commits, and 57 | #' replace it with this version. 58 | #' @param submit Submit newly added post. 59 | #' @param message Commit message. By default, will use 'Adding post: [title]' 60 | #' @param src Specify additional source files to add to 61 | #' \code{/orig_src.} 62 | #' @param browse_pr If \code{submit}, whether to browse to a GitHub pull request for 63 | #' submitting this post. 64 | #' @param repo Repository of the knowledge post to add 65 | #' 66 | #' @template extra-args 67 | #' 68 | #' @examples 69 | #' 70 | #' # set up a repository and post 71 | #' repo <- tempfile() 72 | #' kr_init(repo) 73 | #' kr_create("test.Rmd", repo = repo) 74 | #' 75 | #' # add to knowledge repo 76 | #' kr_add("test.Rmd", repo = repo, path = "tests/test") 77 | #' 78 | #' # custom commit message 79 | #' kr_add("test.Rmd", repo = repo, path = "tests/test2", message = "Committing a new post") 80 | #' 81 | #' @export 82 | kr_add <- function(filename, 83 | path = NULL, 84 | update = FALSE, 85 | branch = NULL, 86 | squash = FALSE, 87 | submit = FALSE, 88 | message = NULL, 89 | src = NULL, 90 | browse_pr = FALSE, 91 | ..., 92 | repo = Sys.getenv("KNOWLEDGE_REPO")) { 93 | if (is.null(message)) { 94 | title <- rmarkdown::yaml_front_matter(filename)$title 95 | if (is.null(title)) { 96 | warning("Can't find title in YAML header of ", title) 97 | } 98 | message <- paste0("Adding post: ", title) 99 | } 100 | 101 | if (repo == "") { 102 | stop("No repository specified and no KNOWLEDGE_REPO environment variable") 103 | } 104 | 105 | kr_command(repo = repo, 106 | ..., 107 | "add", 108 | path = path, 109 | update = update, 110 | branch = branch, 111 | squash = squash, 112 | submit = submit, 113 | message = message, 114 | src = src, 115 | filename) 116 | 117 | # may need to add reminder 118 | if (submit) { 119 | if (is.null(path)) { 120 | path <- rmarkdown::yaml_front_matter(filename)$path 121 | } 122 | 123 | after_submit(repo, path, browse_pr = browse_pr) 124 | } 125 | } 126 | 127 | 128 | #' Initialize a new knowledge repository 129 | #' 130 | #' @param repo Folder of the repository to create 131 | #' @param tooling_embed Embed a reference version knowledge_repo tooling in 132 | #' the repository. 133 | #' @param tooling_repo The repository to use (if not the default). 134 | #' @param tooling_branch The branch to use when embedding the tools as a 135 | #' submodule (default is "master"). 136 | #' @template extra-args 137 | #' 138 | #' @examples 139 | #' 140 | #' repo <- tempfile() 141 | #' kr_init(repo) 142 | #' 143 | #' @export 144 | kr_init <- function(repo, 145 | tooling_embed = FALSE, 146 | tooling_repo = NULL, 147 | tooling_branch = NULL, 148 | ...) { 149 | kr_command(repo = repo, 150 | ..., 151 | "init", 152 | tooling_embed = tooling_embed, 153 | tooling_repo = tooling_repo, 154 | tooling_branch = tooling_branch) 155 | } 156 | 157 | 158 | #' Submit a post to the knowledge base for review 159 | #' 160 | #' Submit a post to the knowledge base for review. This would be done 161 | #' after adding it with \code{\link{kr_add}} 162 | #' (assuming submit was FALSE in that command). 163 | #' 164 | #' @param path The path of the knowledge post to submit for review. 165 | #' @param repo Repository of the knowledge post to add 166 | #' @param browse_pr Whether to browse to a GitHub pull request for 167 | #' submitting this post 168 | #' @param master Whether to submit it on master rather than on a 169 | #' separate branch (allowing for review). If TRUE, rather than using 170 | #' the knowlege_base CLI it locally merges to master than pushes. 171 | #' Works only if you have commit access to master. 172 | #' 173 | #' @details The "direct" option is not supported by the \code{knowledge_repo} 174 | #' command line interface, and is a shortcut provided by this package. 175 | #' 176 | #' @template extra-args 177 | #' 178 | #' @examples 179 | #' 180 | #' # set up a repository and post 181 | #' repo <- tempfile() 182 | #' kr_init(repo) 183 | #' kr_create("test.Rmd", repo = repo) 184 | #' 185 | #' # add to knowledge repo 186 | #' kr_add("test.Rmd", repo = repo, path = "tests/test") 187 | #' 188 | #' \dontrun{ 189 | #' # submit to remote repository 190 | #' kr_submit("tests/test") 191 | #' } 192 | #' 193 | #' @export 194 | kr_submit <- function(path, 195 | repo = Sys.getenv("KNOWLEDGE_REPO"), 196 | browse_pr = FALSE, 197 | master = FALSE, 198 | ...) { 199 | if (repo == "") { 200 | stop("No repository specified and no KNOWLEDGE_REPO environment variable") 201 | } 202 | 203 | if (master) { 204 | # Push directly to master branch rather than a PR 205 | # Note that this isn't generally supported by knowledge_repo: 206 | # we'll have to see how it works in practice 207 | message("Merging ", path, " to master and pushing") 208 | r <- git2r::init(repo) 209 | git2r::checkout(r, "master") 210 | git2r::merge(r, paste0(path, ".kp")) 211 | git2r::push(r) 212 | return() 213 | } 214 | 215 | kr_command(..., repo = repo, "submit", path) 216 | 217 | after_submit(repo, path, browse_pr = browse_pr) 218 | } 219 | 220 | 221 | #' Show status of knowledge repo 222 | #' 223 | #' @param ... Global arguments to \code{knowledge_repo} commands, such as 224 | #' \code{repo} or \code{noupdate} 225 | #' 226 | #' @export 227 | kr_status <- function(...) { 228 | kr_command(..., "status") 229 | } 230 | 231 | 232 | #' Show status of knowledge repo 233 | #' 234 | #' @template extra-args 235 | #' 236 | #' @export 237 | kr_runserver <- function(...) { 238 | kr_command(..., "status") 239 | } 240 | 241 | 242 | #' Preview a post locally 243 | #' 244 | #' @param path The path of the knowledge post to preview. 245 | #' @param port Specify the port on which to run the web server. 246 | #' @param dburi The SQLAlchemy database uri. 247 | #' @param config Configuration file 248 | #' 249 | #' @template extra-args 250 | #' 251 | #' @export 252 | kr_preview <- function(path, port = NULL, dburi = NULL, config = NULL, ...) { 253 | kr_command(..., 254 | "preview", 255 | path, 256 | port = port, 257 | dburi = dburi, 258 | config = config) 259 | } 260 | 261 | 262 | #' Deploy a local server 263 | #' 264 | #' @param port Specify the port on which to run the web server. 265 | #' @param dburi The SQLAlchemy database uri. 266 | #' @param workers Number of gunicorn worker threads to spin up. 267 | #' @param timeout Specify the timeout (seconds) for the gunicorn web 268 | #' server. 269 | #' @param config The config file from which to read server configuration. 270 | #' @param engine Which server engine to use when deploying; choose 271 | #' from: "flask", "gunicorn" (default) or "uwsgi". 272 | #' 273 | #' @template extra-args 274 | #' 275 | #' @export 276 | kr_deploy <- function(port = NULL, 277 | dburi = NULL, 278 | workers = NULL, 279 | timeout = NULL, 280 | config = NULL, 281 | engine = NULL, 282 | ...) { 283 | kr_command(..., 284 | "deploy", 285 | port = port, 286 | dburi = dburi, 287 | workers = workers, 288 | timeout = timeout, 289 | config = config, 290 | engine = engine) 291 | } 292 | 293 | 294 | #' Run a keybase command on the command line 295 | #' 296 | #' Run a keybase command with the given arguments. Positional 297 | #' arguments are provided in order, while named arguments are prefixed 298 | #' with \code{--name}. Arguments passed as TRUE are empty (e.g. 299 | #' \code{help = TRUE} becomes \code{--help}), while FALSE and NULL are 300 | #' dropped. 301 | #' 302 | #' @param ... Arguments to construct a command, either unnamed (positional) 303 | #' or named 304 | #' @param .verbose Whether to display the output as a message 305 | #' 306 | #' @examples 307 | #' 308 | #' kr_command("create", "Rmd", "test.Rmd") 309 | #' 310 | #' @export 311 | kr_command <- function(..., .verbose = TRUE) { 312 | # remove NULLs and FALSEs, turn TRUE to "" 313 | args <- list(...) 314 | args <- purrr::keep(purrr::compact(args), ~ !identical(., FALSE)) 315 | args <- purrr::modify_if(args, ~ identical(., TRUE), ~ "") 316 | args <- purrr::modify_if(args, ~ . != "", shQuote) 317 | 318 | n <- names(args) 319 | n <- gsub("_", "-", n) 320 | n[n != ""] <- paste0("--", n, " ")[n != ""] 321 | 322 | with_names <- as.list(c("knowledge_repo", paste0(n, unlist(args)))) 323 | 324 | cmd <- do.call(paste, with_names) 325 | 326 | if (.verbose) { 327 | message("Running '", cmd, "'") 328 | } 329 | system(cmd) 330 | } 331 | -------------------------------------------------------------------------------- /R/utilities.R: -------------------------------------------------------------------------------- 1 | #' Retrieve the remote link of a GitHub repository 2 | #' 3 | #' This is useful for linking to a remote pull request 4 | #' 5 | #' @param path Path to a local git repository 6 | get_remote_link <- function(path) { 7 | if (!requireNamespace("git2r")) { 8 | stop("Working with remote GitHub repos requires the git2r package") 9 | } 10 | 11 | remote_link <- git2r::remote_url(git2r::init(path))[1] 12 | 13 | if (length(remote_link) == 0) { 14 | return(NULL) 15 | } 16 | 17 | if (!stringr::str_detect(remote_link, "github.com.*git")) { 18 | stop("Does not appear to be a github remote: ", remote_link) 19 | } 20 | 21 | repo_name <- stringr::str_match(remote_link, ":(.*).git")[2] 22 | paste0("https://github.com/", repo_name) 23 | } 24 | 25 | 26 | #' Provide a message with context about a path variable, after submitting 27 | #' 28 | #' @param repo Local path to repo 29 | #' @param path Path of knowledge post 30 | #' @param browse_pr Whether to browse to a pull request 31 | after_submit <- function(repo, path, browse_pr = FALSE) { 32 | remote_link <- get_remote_link(repo) 33 | 34 | if (is.null(remote_link)) { 35 | stop("Appears to have no remote repository; cannot submit") 36 | } 37 | 38 | pr_url <- paste0(remote_link, "/compare/", path, ".kp?expand=1") 39 | 40 | message("You've pushed the post to the ", path, " branch, ", 41 | "you can now submit a PR for review at ", 42 | pr_url) 43 | 44 | if (browse_pr) { 45 | utils::browseURL(pr_url) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | ```{r setup, include = FALSE} 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>", 5 | fig.path = "man/figures/README-", 6 | out.width = "100%" 7 | ) 8 | ``` 9 | 10 | [![Travis build status](https://travis-ci.org/dgrtwo/knowledgerepo.svg?branch=master)](https://travis-ci.org/dgrtwo/knowledgerepo) 11 | [![AppVeyor Build Status](https://ci.appveyor.com/dgrtwo/knowledgerepo)](https://ci.appveyor.com/api/projects/status/github//dgrtwo/knowledgerepo/?branch=master&svg=true) 12 | 13 | # knowledgerepo 14 | 15 | The knowledgerepo package is a wrapper around [AirBnB's Knowledge Repository project](https://github.com/airbnb/knowledge-repo), particularly the command line tools included within the project. Its goal is to make it easy to create and submit knowledge posts from within an R session. 16 | 17 | ## Installation 18 | 19 | Use the [remotes](https://cran.r-project.org/web/packages/remotes/index.html) package to install the development version from GitHub: 20 | 21 | ```{r, eval = FALSE} 22 | remotes::install_github("dgrtwo/knowledgerepo") 23 | ``` 24 | 25 | You'll also need to install the [knowledge_repo](https://github.com/airbnb/knowledge-repo) Python package from your terminal. 26 | 27 | ``` 28 | [sudo] pip install --upgrade knowledge-repo 29 | ``` 30 | 31 | ## Usage 32 | 33 | The package offers functions, each prefixed with `kr_`, that wrap the `knowledge_base` command line interface. For example, `knowledge_repo init` is replaced with `kr_init`, and `knowledge_repo add` replaced with `kr_add`. 34 | 35 | ```{r eval = FALSE} 36 | library(knowledgerepo) 37 | 38 | # Initialize a repository 39 | repo_dir <- tempfile() 40 | kr_init(repo_dir) 41 | 42 | # Create a test post 43 | test_file <- tempfile(fileext = ".Rmd") 44 | kr_create(test_file) 45 | 46 | # Create a test post 47 | kr_add(test_file, path = "examples/test_post", repo = repo_dir) 48 | ``` 49 | 50 | Once you've added a remote GitHub repository, you can also submit the post for review. 51 | 52 | ```{r eval = FALSE} 53 | # Submit it for review 54 | kr_submit("examples/test_post", repo = repo) 55 | ``` 56 | 57 | ## Code of Conduct 58 | 59 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). 60 | By participating in this project you agree to abide by its terms. 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [![Travis build status](https://travis-ci.org/dgrtwo/knowledgerepo.svg?branch=master)](https://travis-ci.org/dgrtwo/knowledgerepo) 4 | [![AppVeyor Build Status](https://ci.appveyor.com/dgrtwo/knowledgerepo)](https://ci.appveyor.com/api/projects/status/github//dgrtwo/knowledgerepo/?branch=master&svg=true) 5 | 6 | # knowledgerepo 7 | 8 | The knowledgerepo package is a wrapper around [AirBnB's Knowledge Repository project](https://github.com/airbnb/knowledge-repo), particularly the command line tools included within the project. Its goal is to make it easy to create and submit knowledge posts from within an R session. 9 | 10 | ## Installation 11 | 12 | Use the [remotes](https://cran.r-project.org/web/packages/remotes/index.html) package to install the development version from GitHub: 13 | 14 | 15 | ```r 16 | remotes::install_github("dgrtwo/knowledgerepo") 17 | ``` 18 | 19 | You'll also need to install the [knowledge_repo](https://github.com/airbnb/knowledge-repo) Python package from your terminal. 20 | 21 | ``` 22 | [sudo] pip install --upgrade knowledge-repo 23 | ``` 24 | 25 | ## Usage 26 | 27 | The package offers functions, each prefixed with `kr_`, that wrap the `knowledge_base` command line interface. For example, `knowledge_repo init` is replaced with `kr_init`, and `knowledge_repo add` replaced with `kr_add`. 28 | 29 | 30 | ```r 31 | library(knowledgerepo) 32 | 33 | # Initialize a repository 34 | repo_dir <- tempfile() 35 | kr_init(repo_dir) 36 | 37 | # Create a test post 38 | test_file <- tempfile(fileext = ".Rmd") 39 | kr_create(test_file) 40 | 41 | # Create a test post 42 | kr_add(test_file, path = "examples/test_post", repo = repo_dir) 43 | ``` 44 | 45 | Once you've added a remote GitHub repository, you can also submit the post for review. 46 | 47 | 48 | ```r 49 | # Submit it for review 50 | kr_submit("examples/test_post", repo = repo) 51 | ``` 52 | 53 | ## Code of Conduct 54 | 55 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). 56 | By participating in this project you agree to abide by its terms. 57 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | before_build: 14 | - pip install knowledge-repo 15 | 16 | cache: 17 | - C:\RLibrary 18 | - '%LOCALAPPDATA%\pip\Cache' 19 | 20 | # Adapt as necessary starting from here 21 | 22 | build_script: 23 | - travis-tool.sh install_deps 24 | 25 | test_script: 26 | - travis-tool.sh run_tests 27 | 28 | on_failure: 29 | - 7z a failure.zip *.Rcheck\* 30 | - appveyor PushArtifact failure.zip 31 | 32 | artifacts: 33 | - path: '*.Rcheck\**\*.log' 34 | name: Logs 35 | 36 | - path: '*.Rcheck\**\*.out' 37 | name: Logs 38 | 39 | - path: '*.Rcheck\**\*.fail' 40 | name: Logs 41 | 42 | - path: '*.Rcheck\**\*.Rout' 43 | name: Logs 44 | 45 | - path: '\*_*.tar.gz' 46 | name: Bits 47 | 48 | - path: '\*_*.zip' 49 | name: Bits 50 | -------------------------------------------------------------------------------- /knowledgerepo.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man-roxygen/extra-args.R: -------------------------------------------------------------------------------- 1 | #' @param ... Global arguments to \code{knowledge_repo} commands, such as 2 | #' \code{repo} or \code{noupdate} (see Details) 3 | #' 4 | #' @details Global arguments that can be passed to all knowledge_repo 5 | #' commands include: 6 | #' 7 | #' \itemize{ 8 | #' \item{repo}{Path to Knowledge Repository to add to. Can also set 9 | #' \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 10 | #' \item{dev}{Whether to skip passing control to version of code 11 | #' checked out in knowledge repository.} 12 | #' \item{debug}{Whether to enable debug mode.} 13 | #' \item{noupdate}{Whether script should update the repository before 14 | #' performing actions.} 15 | #' \item{version}{Show version and exit.} 16 | #' \item{help}{Show help and exit} 17 | #' } 18 | -------------------------------------------------------------------------------- /man/after_submit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{after_submit} 4 | \alias{after_submit} 5 | \title{Provide a message with context about a path variable, after submitting} 6 | \usage{ 7 | after_submit(repo, path, browse_pr = FALSE) 8 | } 9 | \arguments{ 10 | \item{repo}{Local path to repo} 11 | 12 | \item{path}{Path of knowledge post} 13 | 14 | \item{browse_pr}{Whether to browse to a pull request} 15 | } 16 | \description{ 17 | Provide a message with context about a path variable, after submitting 18 | } 19 | -------------------------------------------------------------------------------- /man/get_remote_link.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{get_remote_link} 4 | \alias{get_remote_link} 5 | \title{Retrieve the remote link of a GitHub repository} 6 | \usage{ 7 | get_remote_link(path) 8 | } 9 | \arguments{ 10 | \item{path}{Path to a local git repository} 11 | } 12 | \description{ 13 | This is useful for linking to a remote pull request 14 | } 15 | -------------------------------------------------------------------------------- /man/kr_add.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_add} 4 | \alias{kr_add} 5 | \title{Add a post to a knowledge repository} 6 | \usage{ 7 | kr_add(filename, path = NULL, update = FALSE, branch = NULL, 8 | squash = FALSE, submit = FALSE, message = NULL, src = NULL, 9 | browse_pr = FALSE, ..., repo = Sys.getenv("KNOWLEDGE_REPO")) 10 | } 11 | \arguments{ 12 | \item{filename}{Filename to add} 13 | 14 | \item{path}{The path of the destination post to be added in the 15 | knowledge repo. Required if the knowledge post does 16 | not specify "path" in its headers.} 17 | 18 | \item{update}{Whether this should update an existing post of the 19 | same name.} 20 | 21 | \item{branch}{The branch to use for this addition, if not the 22 | default (which is the path of the knowledge post).} 23 | 24 | \item{squash}{Automatically suppress all previous commits, and 25 | replace it with this version.} 26 | 27 | \item{submit}{Submit newly added post.} 28 | 29 | \item{message}{Commit message. By default, will use 'Adding post: [title]'} 30 | 31 | \item{src}{Specify additional source files to add to 32 | \code{/orig_src.}} 33 | 34 | \item{browse_pr}{If \code{submit}, whether to browse to a GitHub pull request for 35 | submitting this post.} 36 | 37 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 38 | \code{repo} or \code{noupdate} (see Details)} 39 | 40 | \item{repo}{Repository of the knowledge post to add} 41 | } 42 | \description{ 43 | Add a local file to a knowledge repository. Unless submit = TRUE, this doesn't 44 | (yet) submit the post. 45 | } 46 | \details{ 47 | Global arguments that can be passed to all knowledge_repo 48 | commands include: 49 | 50 | \itemize{ 51 | \item{repo}{Path to Knowledge Repository to add to. Can also set 52 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 53 | \item{dev}{Whether to skip passing control to version of code 54 | checked out in knowledge repository.} 55 | \item{debug}{Whether to enable debug mode.} 56 | \item{noupdate}{Whether script should update the repository before 57 | performing actions.} 58 | \item{version}{Show version and exit.} 59 | \item{help}{Show help and exit} 60 | } 61 | } 62 | \examples{ 63 | 64 | # set up a repository and post 65 | repo <- tempfile() 66 | kr_init(repo) 67 | kr_create("test.Rmd", repo = repo) 68 | 69 | # add to knowledge repo 70 | kr_add("test.Rmd", repo = repo, path = "tests/test") 71 | 72 | # custom commit message 73 | kr_add("test.Rmd", repo = repo, path = "tests/test2", message = "Committing a new post") 74 | 75 | } 76 | -------------------------------------------------------------------------------- /man/kr_command.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_command} 4 | \alias{kr_command} 5 | \title{Run a keybase command on the command line} 6 | \usage{ 7 | kr_command(..., .verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{...}{Arguments to construct a command, either unnamed (positional) 11 | or named} 12 | 13 | \item{.verbose}{Whether to display the output as a message} 14 | } 15 | \description{ 16 | Run a keybase command with the given arguments. Positional 17 | arguments are provided in order, while named arguments are prefixed 18 | with \code{--name}. Arguments passed as TRUE are empty (e.g. 19 | \code{help = TRUE} becomes \code{--help}), while FALSE and NULL are 20 | dropped. 21 | } 22 | \examples{ 23 | 24 | kr_command("create", "Rmd", "test.Rmd") 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/kr_create.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_create} 4 | \alias{kr_create} 5 | \title{Create a new post from a default template} 6 | \usage{ 7 | kr_create(filename, format = NULL, template = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{filename}{Where this file should be created.} 11 | 12 | \item{format}{The format of the knowledge post to be created: 13 | either Rmd, ipynb, or md. By default, retrieved from the extension 14 | of the filename.} 15 | 16 | \item{template}{Optionally, a template to create the knowledge post from.} 17 | 18 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 19 | \code{repo} or \code{noupdate} (see Details)} 20 | } 21 | \description{ 22 | Creates a new post from the built in template, using either 23 | Rmd (default), IPython notebook, or Markdown 24 | } 25 | \details{ 26 | Global arguments that can be passed to all knowledge_repo 27 | commands include: 28 | 29 | \itemize{ 30 | \item{repo}{Path to Knowledge Repository to add to. Can also set 31 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 32 | \item{dev}{Whether to skip passing control to version of code 33 | checked out in knowledge repository.} 34 | \item{debug}{Whether to enable debug mode.} 35 | \item{noupdate}{Whether script should update the repository before 36 | performing actions.} 37 | \item{version}{Show version and exit.} 38 | \item{help}{Show help and exit} 39 | } 40 | } 41 | \examples{ 42 | 43 | # set up a repository and post 44 | repo <- tempfile() 45 | kr_init(repo) 46 | kr_create("test.Rmd", repo = repo) 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/kr_deploy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_deploy} 4 | \alias{kr_deploy} 5 | \title{Deploy a local server} 6 | \usage{ 7 | kr_deploy(port = NULL, dburi = NULL, workers = NULL, timeout = NULL, 8 | config = NULL, engine = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{port}{Specify the port on which to run the web server.} 12 | 13 | \item{dburi}{The SQLAlchemy database uri.} 14 | 15 | \item{workers}{Number of gunicorn worker threads to spin up.} 16 | 17 | \item{timeout}{Specify the timeout (seconds) for the gunicorn web 18 | server.} 19 | 20 | \item{config}{The config file from which to read server configuration.} 21 | 22 | \item{engine}{Which server engine to use when deploying; choose 23 | from: "flask", "gunicorn" (default) or "uwsgi".} 24 | 25 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 26 | \code{repo} or \code{noupdate} (see Details)} 27 | } 28 | \description{ 29 | Deploy a local server 30 | } 31 | \details{ 32 | Global arguments that can be passed to all knowledge_repo 33 | commands include: 34 | 35 | \itemize{ 36 | \item{repo}{Path to Knowledge Repository to add to. Can also set 37 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 38 | \item{dev}{Whether to skip passing control to version of code 39 | checked out in knowledge repository.} 40 | \item{debug}{Whether to enable debug mode.} 41 | \item{noupdate}{Whether script should update the repository before 42 | performing actions.} 43 | \item{version}{Show version and exit.} 44 | \item{help}{Show help and exit} 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /man/kr_init.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_init} 4 | \alias{kr_init} 5 | \title{Initialize a new knowledge repository} 6 | \usage{ 7 | kr_init(repo, tooling_embed = FALSE, tooling_repo = NULL, 8 | tooling_branch = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{repo}{Folder of the repository to create} 12 | 13 | \item{tooling_embed}{Embed a reference version knowledge_repo tooling in 14 | the repository.} 15 | 16 | \item{tooling_repo}{The repository to use (if not the default).} 17 | 18 | \item{tooling_branch}{The branch to use when embedding the tools as a 19 | submodule (default is "master").} 20 | 21 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 22 | \code{repo} or \code{noupdate} (see Details)} 23 | } 24 | \description{ 25 | Initialize a new knowledge repository 26 | } 27 | \details{ 28 | Global arguments that can be passed to all knowledge_repo 29 | commands include: 30 | 31 | \itemize{ 32 | \item{repo}{Path to Knowledge Repository to add to. Can also set 33 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 34 | \item{dev}{Whether to skip passing control to version of code 35 | checked out in knowledge repository.} 36 | \item{debug}{Whether to enable debug mode.} 37 | \item{noupdate}{Whether script should update the repository before 38 | performing actions.} 39 | \item{version}{Show version and exit.} 40 | \item{help}{Show help and exit} 41 | } 42 | } 43 | \examples{ 44 | 45 | repo <- tempfile() 46 | kr_init(repo) 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/kr_preview.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_preview} 4 | \alias{kr_preview} 5 | \title{Preview a post locally} 6 | \usage{ 7 | kr_preview(path, port = NULL, dburi = NULL, config = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{path}{The path of the knowledge post to preview.} 11 | 12 | \item{port}{Specify the port on which to run the web server.} 13 | 14 | \item{dburi}{The SQLAlchemy database uri.} 15 | 16 | \item{config}{Configuration file} 17 | 18 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 19 | \code{repo} or \code{noupdate} (see Details)} 20 | } 21 | \description{ 22 | Preview a post locally 23 | } 24 | \details{ 25 | Global arguments that can be passed to all knowledge_repo 26 | commands include: 27 | 28 | \itemize{ 29 | \item{repo}{Path to Knowledge Repository to add to. Can also set 30 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 31 | \item{dev}{Whether to skip passing control to version of code 32 | checked out in knowledge repository.} 33 | \item{debug}{Whether to enable debug mode.} 34 | \item{noupdate}{Whether script should update the repository before 35 | performing actions.} 36 | \item{version}{Show version and exit.} 37 | \item{help}{Show help and exit} 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /man/kr_runserver.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_runserver} 4 | \alias{kr_runserver} 5 | \title{Show status of knowledge repo} 6 | \usage{ 7 | kr_runserver(...) 8 | } 9 | \arguments{ 10 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 11 | \code{repo} or \code{noupdate} (see Details)} 12 | } 13 | \description{ 14 | Show status of knowledge repo 15 | } 16 | \details{ 17 | Global arguments that can be passed to all knowledge_repo 18 | commands include: 19 | 20 | \itemize{ 21 | \item{repo}{Path to Knowledge Repository to add to. Can also set 22 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 23 | \item{dev}{Whether to skip passing control to version of code 24 | checked out in knowledge repository.} 25 | \item{debug}{Whether to enable debug mode.} 26 | \item{noupdate}{Whether script should update the repository before 27 | performing actions.} 28 | \item{version}{Show version and exit.} 29 | \item{help}{Show help and exit} 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /man/kr_status.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_status} 4 | \alias{kr_status} 5 | \title{Show status of knowledge repo} 6 | \usage{ 7 | kr_status(...) 8 | } 9 | \arguments{ 10 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 11 | \code{repo} or \code{noupdate}} 12 | } 13 | \description{ 14 | Show status of knowledge repo 15 | } 16 | -------------------------------------------------------------------------------- /man/kr_submit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/commands.R 3 | \name{kr_submit} 4 | \alias{kr_submit} 5 | \title{Submit a post to the knowledge base for review} 6 | \usage{ 7 | kr_submit(path, repo = Sys.getenv("KNOWLEDGE_REPO"), browse_pr = FALSE, 8 | master = FALSE, ...) 9 | } 10 | \arguments{ 11 | \item{path}{The path of the knowledge post to submit for review.} 12 | 13 | \item{repo}{Repository of the knowledge post to add} 14 | 15 | \item{browse_pr}{Whether to browse to a GitHub pull request for 16 | submitting this post} 17 | 18 | \item{master}{Whether to submit it on master rather than on a 19 | separate branch (allowing for review). If TRUE, rather than using 20 | the knowlege_base CLI it locally merges to master than pushes. 21 | Works only if you have commit access to master.} 22 | 23 | \item{...}{Global arguments to \code{knowledge_repo} commands, such as 24 | \code{repo} or \code{noupdate} (see Details)} 25 | } 26 | \description{ 27 | Submit a post to the knowledge base for review. This would be done 28 | after adding it with \code{\link{kr_add}} 29 | (assuming submit was FALSE in that command). 30 | } 31 | \details{ 32 | The "direct" option is not supported by the \code{knowledge_repo} 33 | command line interface, and is a shortcut provided by this package. 34 | 35 | Global arguments that can be passed to all knowledge_repo 36 | commands include: 37 | 38 | \itemize{ 39 | \item{repo}{Path to Knowledge Repository to add to. Can also set 40 | \code{KNOWLEDGE_REPO} variable in \code{.Renviron}.} 41 | \item{dev}{Whether to skip passing control to version of code 42 | checked out in knowledge repository.} 43 | \item{debug}{Whether to enable debug mode.} 44 | \item{noupdate}{Whether script should update the repository before 45 | performing actions.} 46 | \item{version}{Show version and exit.} 47 | \item{help}{Show help and exit} 48 | } 49 | } 50 | \examples{ 51 | 52 | # set up a repository and post 53 | repo <- tempfile() 54 | kr_init(repo) 55 | kr_create("test.Rmd", repo = repo) 56 | 57 | # add to knowledge repo 58 | kr_add("test.Rmd", repo = repo, path = "tests/test") 59 | 60 | \dontrun{ 61 | # submit to remote repository 62 | kr_submit("tests/test") 63 | } 64 | 65 | } 66 | --------------------------------------------------------------------------------