Skip to content

Instantly share code, notes, and snippets.

@momolog
Last active May 29, 2019 13:06
Show Gist options
  • Save momolog/71c3a5903c34e9f3b80914714a01b175 to your computer and use it in GitHub Desktop.
Save momolog/71c3a5903c34e9f3b80914714a01b175 to your computer and use it in GitHub Desktop.
githost to gitlab variable transfer
#!/usr/bin/env ruby
# move me to ~/bin/githost-move-vars, make me executable and
# call me like githost-move-vars 101 1258608
require "httparty"
# WARNINGS:
# only works for up to 100 variables
# doesn't copy protected nor masked checkboxes
from_id = ARGV[0] or raise 'no source id given'
to_id = ARGV[1] or raise 'no target id given'
FROM_URL = "https://giantmonkey.githost.io/api/v4/projects/#{from_id}"
TO_URL = "https://gitlab.com/api/v4/projects/#{to_id}"
FROM_HEADERS = {"PRIVATE-TOKEN" => ENV['GITHOST_PERSONAL_API_TOKEN']}
TO_HEADERS = {"PRIVATE-TOKEN" => ENV['GITLAB_PERSONAL_API_TOKEN']}
def get_variables
HTTParty.get "#{FROM_URL}/variables?per_page=100", headers: FROM_HEADERS
end
def update_variable(key, value)
HTTParty.put "#{TO_URL}/variables/#{key}", body: { value: value }, headers: TO_HEADERS
end
def create_variable(key, value)
HTTParty.post "#{TO_URL}/variables", body: { value: value, key: key }, headers: TO_HEADERS
end
puts "Copying #{get_variables.size} variables"
get_variables.each do |variable|
puts "...creating #{variable["key"]}"
create_variable(variable["key"], variable["value"]) || update_variable(variable["key"], variable["value"])
end
puts "finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment