Last active
May 1, 2019 19:23
-
-
Save asinghvi17/f20d14fa20743ef70414fc21703a9555 to your computer and use it in GitHub Desktop.
Create Project.tomls for an entire organization's repos.
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" mkproj.jl <packages names (WITH .jl)>... | |
### | |
## 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 | |
## | |
const USER = "YOURNAMEHERE" # FIXME fill out | |
const ORG = "YOURORGHERE" # FIXME fill out | |
# import packages | |
using GitHub | |
# setup | |
printstyled("Downloading", bold = true, color = 2) | |
println(" `gen_project.jl`") | |
# gen_project.jl | |
const PROJ_SCRIPT = download(raw"https://raw.githubusercontent.com/JuliaLang/Pkg.jl/master/bin/gen_project.jl"); | |
# the packages to download and generate Project.tomls for | |
const PKGS = ARGS; | |
# the current directory (where the script was invoked): | |
const CWD = pwd(); | |
# 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 = GitHub.repo.(ORG * "/" .* PKGS) # get info on repos | |
forks = GitHub.create_fork.(repos, auth = auth) # fork repos to user | |
printstyled("Repos have been forked\n\n", bold = true, color = 2) | |
fork_urls = getproperty.(forks, :url) # get the fork URLs | |
fustrs = string.(fork_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) | |
for pkg in PKGS # clone! | |
cd(pkg) | |
run(`git add Project.toml`) | |
run(`git commit -a -m "Add Project.toml"`) | |
run(`git push`) | |
cd("..") | |
end | |
GitHub.create_pull_request.( | |
repos, | |
params = Dict( | |
:title => "Add Project.toml", | |
: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