Skip to content

Instantly share code, notes, and snippets.

@asinghvi17 asinghvi17/mkprojects.jl
Last active May 1, 2019

Embed
What would you like to do?
Create Project.tomls for an entire organization's repos.
#!/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
You can’t perform that action at this time.