Skip to content

Instantly share code, notes, and snippets.

@jimhester
Created December 13, 2018 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimhester/22ec4601daa6ce7e93487e18ef063350 to your computer and use it in GitHub Desktop.
Save jimhester/22ec4601daa6ce7e93487e18ef063350 to your computer and use it in GitHub Desktop.
Programmatically make a fix, fork and open a PR
library(gh)
library(tidyverse)
library(processx)
me <- "jimhester"
title <- "Remove default assets"
branch_name <- "remove-default_assets"
search <- gh("GET /search/code", q = "default_assets user:tidyverse")
items <- tibble(
owner = map_chr(search$items, c("repository", "owner", "login")),
name = map_chr(search$items, c("repository", "name")),
file = map_chr(search$items, "path"),
url = map_chr(search$items, c("repository", "html_url"))
)
filter <- dplyr::filter
items %>%
filter(file == "_pkgdown.yml") %>%
select(-file) %>%
tail(n=-1) %>%
pwalk(function(owner, name, url) {
message(str_glue("Processing {owner}/{name}"))
run("git", c("clone", url))
withr::with_dir(name, {
# Create branch
run("git", c("checkout", "-b", branch_name))
# Make change
read_lines("_pkgdown.yml") %>%
discard(grepl("default_assets", .)) %>%
write_lines("_pkgdown.yml")
# Commit the change
run("git", c("commit", "-m", title, "--", "_pkgdown.yml"))
# Create fork
gh("POST /repos/:owner/:repo/forks", owner = owner, repo = name)
ssh_url <- str_glue("git@github.com:{me}/{name}.git")
# Push to fork
run("git", c("push", ssh_url, "HEAD"))
# Create PR
gh("POST /repos/:owner/:repo/pulls", owner = owner, repo = name, title = title, head = paste0(me, ":", branch_name), base = "master", maintainer_can_modify = TRUE)
})
fs::dir_delete(name)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment