Created
May 5, 2019 15:02
-
-
Save asinghvi17/cb7891e356bcf6054ca296a051f4d68d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env julia | |
### USAGE | |
# GITHUB_AUTH="MY_GITHUB_AUTH_TOKEN_HERE" FILENAME.jl <per-package usage> | |
### | |
## NOTE: | |
# To set this up, you will need to change the two constants below | |
# to the user who will fork, | |
# and the organization which owns the repos. | |
# IMPORTANT - you will need a GITHUB AUTHENTICATION TOKEN! | |
# see https://github.com/settings/tokens | |
## | |
## To change the script to be downloaded, simply change the download URL. | |
const USER = "asinghvi17" # FIXME fill out | |
const ORG = "JuliaDiffEq" # FIXME fill out | |
const FILES = "CITATION.bib" | |
const COMMITMSG = "Add Project.toml" | |
# The script must take as argument a diretory (or just `.`) and make the requisite changes to it. | |
# It must clean up before exiting - no artifacts should remain. | |
# Everything in the repo will be committed in one commit. | |
const SCRIPT_URL = raw"https://raw.githubusercontent.com/JuliaLang/Pkg.jl/master/bin/gen_project.jl" # currently `gen_project.jl`, change at your leisure | |
# setup | |
printstyled("Downloading", bold = true, color = 2) | |
println(" script from " * SCRIPT_URL) | |
const SCRIPT = download(SCRIPT_URL); # download script and store path | |
# import packages | |
using GitHub | |
## define necessary functions | |
""" | |
getOriginalRepos(orgname, args...)::Array{GitHub.Repo, 1} | |
This function gets the repos to be changed. | |
Please change its implementation to fit your needs. | |
""" | |
function getOriginalRepos(orgname, args...)::Array{GitHub.Repo, 1} | |
return GitHub.repos(ORG)[1] # get info on repos | |
end | |
""" | |
doWork(args...)::Array{GitHub.Repo, 1} | |
This function is a wrapper around whatever changes you need to be made. | |
The implementation here will execute a downloaded script. | |
Please change its implementation to fit your needs. | |
""" | |
function doWork(args...) | |
script_path = args[1] | |
run(`$script_path .`) | |
end | |
# authenticate with Github | |
auth = GitHub.authenticate(ENV["GITHUB_AUTH"]) # you need to have GITHUB_AUTH set in ENV | |
printstyled("Authenticated\n\n", color = 2, bold = true) | |
repos = getOriginalRepos(ORG) | |
writables = GitHub.create_fork.(repos, auth = auth) # fork repos to user | |
printstyled("Repos have been forked\n\n", bold = true, color = 2) | |
PKGS = getproperty.(writables, :name) # get the fork URLs | |
writable_urls = getproperty.(writables, :url) # get the fork URLs | |
writablestrs = string.(writable_urls) # convert URLs to Strings | |
printstyled("Cloning\n\n", bold = true, color = 2) | |
for pkg in PKGS # clone! | |
run(`git clone --depth 1 https://github.com/$USER/$pkg`) | |
end | |
# include(PROJ_SCRIPT) # run `gen_project.jl` | |
# | |
# rm(PROJ_SCRIPT) | |
const LOGFILE = expanduser("~/Desktop/DiffEqRepos.txt") | |
for pkg in PKGS # clone and work then push | |
cd(pkg) | |
doWork() | |
run(`git add $FILES`) | |
run(`git commit -a -m '$COMMITMSG'`) | |
run(`git push`) | |
cd("..") | |
end | |
open("LOGFILE", "w") do logfile | |
write(logfile, join(PKGS, "\n")) | |
end | |
nrepos = repos | |
GitHub.create_pull_request.( | |
nrepos, | |
params = Dict( | |
:title => "Add CITATION.bib", | |
:head => USER * ":master", | |
:base => "master", | |
:body => "Automated PR, please ping $USER if something went weird" | |
), | |
auth = auth | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment