Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save waiting-for-dev/1ddb9829d88c7b9ec3a23d5ee359f9e1 to your computer and use it in GitHub Desktop.
Save waiting-for-dev/1ddb9829d88c7b9ec3a23d5ee359f9e1 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'octokit'
require 'faraday/retry'
class Updater
attr_reader :client
SOLIDUSIO = 'solidusio'
SOLIDUSIO_CONTRIB = 'solidusio-contrib'
ORGANIZATIONS = [
SOLIDUSIO,
SOLIDUSIO_CONTRIB
].freeze
SOLIDUSIO_EXTENSIONS = %w[
solidus_i18n
solidus_auth_devise
solidus_braintree
solidus_paypal_braintree
solidus_affirm
solidus_support
solidus_stripe
].freeze
SOLIDUSIO_CONTRIB_EXTENSIONS = %w[
solidus_multi_domain
solidus_signifyd
solidus_asset_variant_options
solidus_virtual_gift_card
solidus_globalize
solidus_editor
solidus_easypost
solidus_social
solidus_related_products
solidus_comments
solidus_sale_prices
solidus_sitemap
solidus_log_viewer
solidus_papertrail
solidus_print_invoice
solidus_product_feed
solidus_product_assembly
solidus_shipping_labeler
solidus_reviews
solidus_static_content
solidus_prototypes
solidus_geocoding
solidus_klarna_payments
solidus_subscriptions
solidus_redirector
solidus_volume_pricing
solidus_expedited_exchanges
solidus_tax_cloud
solidus_shipwire
solidus_handling_fees
solidus_digital
solidus_abandoned_carts
solidus_reports
solidus_searchkick
solidus_recently_viewed
solidus_jwt
solidus_quiet_logistics
solidus_gdpr
solidus_shipments_add_product
solidus_drip
solidus_importer
solidus_content
solidus_affirm_v2
solidus_paypal_commerce_platform
solidus_webhooks
solidus_klaviyo
solidus_feeds
solidus_tracking
solidus_shipstation
solidus_paypal_marketplace
solidus_razorpay
solidus_bolt
].freeze
EXCEPTIONS = [
# Meta-gem is broken down in the Gemfile
'solidusio/solidus_auth_devise',
# Only depends on solidus_core
'solidusio/solidus_support',
# Only depends on master
'solidusio-contrib/solidus_shipments_add_product'
].freeze
DONE = %w[
].freeze
def self.extensions
SOLIDUSIO_EXTENSIONS.map { |extension| "#{SOLIDUSIO}/#{extension}" } +
SOLIDUSIO_CONTRIB_EXTENSIONS.map { |extension| "#{SOLIDUSIO_CONTRIB}/#{extension}" }
end
def self.extensions_to_update
extensions - EXCEPTIONS - DONE
end
def initialize(client: Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN']))
@client = client
end
def call
self.class.extensions_to_update.each do |org_and_name|
name = org_and_name.split('/').last
system <<~SHELL
git clone git@github.com:#{org_and_name}.git
SHELL
gemfile_path = "#{name}/Gemfile"
content = File.read(gemfile_path)
new_content = content.gsub /^gem.*solidus.*github.*branch.*$/, <<~RUBY.chomp
solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2')
%w[solidusio/solidus solidusio/solidus_frontend]
else
%w[solidusio/solidus] * 2
end
gem 'solidus', github: solidus_git, branch: branch
gem 'solidus_frontend', github: solidus_frontend_git, branch: branch
RUBY
File.open(gemfile_path, 'w') { |file| file.write(new_content) }
system <<~SHELL
cd #{name}
gh repo fork --remote-name fork
git remote set-url fork git@github.com:waiting-for-dev/#{name}.git
git checkout -b waiting-for-dev/support_forked_solidus_frontend
git add Gemfile
git commit -m 'Update to use forked solidus_frontend when needed'
git push --set-upstream fork
gh pr create -f
gh pr view -w
SHELL
end
end
# This plus manual filtering has been used to get the list of extensions
#
# TODO: If an organization has more than 100 repos, update to support pagination
def list_repositories
ORGANIZATIONS.each do |organization|
client.organization_repositories(organization, per_page: 100).each do |repo|
next unless repo.archived
puts repo.name
end
puts 30 * '-'
end
end
end
Updater.new.()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment