-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from katilingban/dev
create add logo function
- Loading branch information
Showing
14 changed files
with
312 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Contributing | ||
|
||
## Bugs | ||
|
||
* Submit an issue on the [issues page](https://github.com/katilingban/pakete/issues) | ||
|
||
## Code contributions | ||
|
||
* Fork this repository to your Github account | ||
|
||
* Clone your version on your account down to your machine from your account | ||
|
||
``` | ||
git clone https://github.com/<yourgithubusername>/pakete.git | ||
``` | ||
|
||
* Make sure to track progress upstream i.e., on our version of `pakete` | ||
at `katilingban/pakete`, by doing | ||
|
||
``` | ||
git remote add upstream https://github.com/katilingban/pakete.git | ||
``` | ||
|
||
* Before making changes make sure to pull changes in from `upstream` by doing | ||
either `git fetch upstream` then merge later or `git pull upstream` to fetch | ||
and merge in one step | ||
|
||
* Make your changes on a new feature branch | ||
|
||
* Please write a test or tests for your changes if they affect code and not just | ||
documentation | ||
|
||
* Push up changes to your account | ||
|
||
* Submit a pull request at `katilingban/pakete` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' | ||
#' Add contributing document | ||
#' | ||
#' @param repo Short remote git repository name. If NULL, is determined based | ||
#' on current git settings. | ||
#' | ||
#' @returns A CONTRIBUTING.md file in the `.github` directory | ||
#' | ||
#' @examples | ||
#' if (interactive()) add_contributing("katilingban/pakete") | ||
#' | ||
#' @export | ||
#' | ||
#' | ||
|
||
add_contributing <- function(repo = NULL) { | ||
## Get repo name ---- | ||
repo_name <- stringr::str_extract(string = repo, pattern = "[^/]*$") | ||
|
||
## Read template ---- | ||
contrib_lines <- readLines( | ||
con = system.file("templates", "CONTRIBUTING.md", package = "pakete") | ||
) | ||
|
||
## Replace {{repo}} ---- | ||
contrib_lines <- contrib_lines |> | ||
stringr::str_replace_all(pattern = "\\{\\{repo\\}\\}", replacement = repo) | ||
|
||
## Replace {{repo_name}} ---- | ||
contrib_lines <- contrib_lines |> | ||
stringr::str_replace_all( | ||
pattern = "\\{\\{repo_name\\}\\}", replacement = repo_name | ||
) | ||
|
||
withr::with_output_sink( | ||
new = ".github/CONTRIBUTING.md", | ||
code = writeLines(text = contrib_lines, con = ".github/CONTRIBUTING.md") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' | ||
#' Add HTML snippet for package hex sticker in README | ||
#' | ||
#' @param repo Short remote git repository name. If NULL, is determined based | ||
#' on current git settings. | ||
#' | ||
#' @returns An entry to the first level header section of the README of the | ||
#' repository. | ||
#' | ||
#' @examples | ||
#' if (interactive()) add_logo() | ||
#' | ||
#' @export | ||
#' | ||
|
||
add_logo <- function(repo = NULL) { | ||
## Get repo name ---- | ||
repo_name <- stringr::str_extract(string = repo, pattern = "[^/]*$") | ||
|
||
## Check if logo is available ---- | ||
#if (file.exists("man/figures/logo.png")) | ||
|
||
logo_text <- "<img src='man/figures/logo.png' width='200px' align='right' />" | ||
|
||
## Determine which file to append badge to ---- | ||
if (file.exists("README.Rmd")) { | ||
path <- "README.Rmd" | ||
} else { | ||
path <- "README.md" | ||
} | ||
|
||
## Read file in path ---- | ||
readme_lines <- readLines(path, encoding = "UTF-8") | ||
|
||
if (any(stringr::str_detect(string = readme_lines, pattern = logo_text))) | ||
return(FALSE) | ||
|
||
## Get start and end line of badges ---- | ||
header_line <- stringr::str_detect( | ||
readme_lines, pattern = paste0("# ", repo_name, ":") | ||
) |> | ||
(\(x) seq_len(length(x))[x])() | ||
|
||
## Create replacement text ---- | ||
readme_lines[header_line] <- paste0(readme_lines[header_line], " ", logo_text) | ||
|
||
## Append replacement text ---- | ||
writeLines(text = readme_lines, con = path) | ||
|
||
## Return TRUE if badge was added ---- | ||
TRUE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Contributing | ||
|
||
## Bugs | ||
|
||
* Submit an issue on the [issues page](https://github.com/{{repo}}/issues) | ||
|
||
## Code contributions | ||
|
||
* Fork this repository to your Github account | ||
|
||
* Clone your version on your account down to your machine from your account | ||
|
||
``` | ||
git clone https://github.com/<yourgithubusername>/{{repo_name}}.git | ||
``` | ||
|
||
* Make sure to track progress upstream i.e., on our version of `{{repo_name}}` | ||
at `{{repo}}`, by doing | ||
|
||
``` | ||
git remote add upstream https://github.com/{{repo}}.git | ||
``` | ||
|
||
* Before making changes make sure to pull changes in from `upstream` by doing | ||
either `git fetch upstream` then merge later or `git pull upstream` to fetch | ||
and merge in one step | ||
|
||
* Make your changes on a new feature branch | ||
|
||
* Please write a test or tests for your changes if they affect code and not just | ||
documentation | ||
|
||
* Push up changes to your account | ||
|
||
* Submit a pull request at `{{repo}}` |
Oops, something went wrong.