SUBSCRIPTIONS_URL refactorings
The following discussion from gitlab!43812 (merged) should be addressed:
-
@brodock started a discussion: On a different note, I'm curious why we decided to start storing all those globals here instead of a more dedicated location.
Looking at
SUBSCRIPTIONS_URL
usage, I found we are "building URLs" all over the place, literally hard-codding and concatenating things when needed with at least 28 matches. It suggests me that we should move those to a dedicated place.An obvious refactor here could start with moving constants to another level and building URL specific methods:
module EE module Subscriptions SUBSCRIPTIONS_URL = ENV.fetch('CUSTOMER_PORTAL_URL', ::Gitlab.dev_or_test_env? ? 'https://customers.stg.gitlab.com' : 'https://customers.gitlab.com').freeze def self.customer_portal_url(path) "#{SUBSCRIPTIONS_URL}/#{path}".freeze end def self.customer_portal_more_minutes_url custmer_portal_url('buy_pipeline_minutes') end def self.customer_portal_more_storage_url custmer_portal_url('buy_storage') end end end
and so on
Availability & Testing
As this refactor is recommending a nice generic library to determine the URLs, a unit spec should accompany the new module to ensure quality.
- If CUSTOMER_PORTAL_URL is set to
the_url
...EE::Subscription
-
#customer_portal_url('/test')
ishttps://the_url/test
-
#customer_portal_more_minutes_url
ishttps://the_url/buy_pipeline_minutes
-
#customer_portal_more_storage_url
ishttps://the_url/buy_storage
-
- If CUSTOMER_PORTAL_URL is not set ...
- When dev env ...
-
#customer_portal_url('/test')
ishttps://customers.stg.gitlab.com/test
-
#customer_portal_more_minutes_url
ishttps://customers.stg.gitlab.com/buy_pipeline_minutes
-
#customer_portal_more_storage_url
ishttps://customers.stg.gitlab.com/buy_storage
-
- When test env ...
-
#customer_portal_url('/test')
ishttps://customers.gitlab.com/test
-
#customer_portal_more_minutes_url
ishttps://ccustomers.gitlab.com/buy_pipeline_minutes
-
#customer_portal_more_storage_url
ishttps://customers.gitlab.com/buy_storage
-
- When dev env ...
Edited by Dan Davison