Class: Readiness::SupportSuperFormProcessor::NamespaceAvailability

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/support_super_form_processor/namespace_availability.rb

Overview

Defines the class NamespaceAvailability within the module Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.42

Class Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Class Method Details

.group_checksObject

Perform the group checks for a Namesquatting Availability check request

Author:

  • Jason Colyer

Since:

  • 1.0.42



57
58
59
60
61
62
63
64
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 57

def self.group_checks
  group = Readiness::GitLab::Groups.new
  group.id = namespace.id
  projects = Readiness::GitLab::Groups.projects(@gitlab_admin_client, group, ["archived=false", "include_subgroups=true"])
  detection = projects.detect { |p| (Date.today - 2.years) < Date.parse(p.last_activity_at) }
  namespace_may_be_available if detection.nil?
  namespace_not_available
end

.namespaceObject

Sets the global variable namespace

Author:

  • Jason Colyer

Since:

  • 1.0.42



107
108
109
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 107

def self.namespace
  @namespace ||= Readiness::GitLab::Namespaces.find!(@gitlab_admin_client, namespace_to_check)
end

.namespace_does_not_existObject

Handles the case where the namespace does not exist

Author:

  • Jason Colyer

Since:

  • 1.0.42



116
117
118
119
120
121
122
123
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 116

def self.namespace_does_not_exist
  issue = Readiness::GitLab::Issues.new
  issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}"
  issue.description = namespace_does_not_exist_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.namespace_does_not_exist_messageObject

Returns the issue description for a case where the namespace does not exist

Author:

  • Jason Colyer

Since:

  • 1.0.42



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 179

def self.namespace_does_not_exist_message
  <<~STRING
    ## Namespace Availability Check for #{CGI.escape(namespace_to_check)}

    Greetings @#{requester.username} !

    We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have been unable to locate the namespace on gitlab.com. This would mean it is not currently in use at all and should be available at this exact moment in time.

    /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username} 
  STRING
end

.namespace_may_be_availableObject

Handles the case where the namespace may be available

Author:

  • Jason Colyer

Since:

  • 1.0.42



144
145
146
147
148
149
150
151
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 144

def self.namespace_may_be_available
  issue = Readiness::GitLab::Issues.new
  issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}"
  issue.description = namespace_may_be_available_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.namespace_may_be_available_messageObject

Returns the issue description for a case where the namespace may be available

Author:

  • Jason Colyer

Since:

  • 1.0.42



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 200

def self.namespace_may_be_available_message
  <<~STRING
    ## Namespace Availability Check for #{CGI.escape(namespace_to_check)}

    Greetings @#{requester.username} !

    We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have determined it _may_ be available for release at this time.

    Please note this only reflects the _possibility_ of release _at this exact time_. Any number of factors or events could change in the future to change this determination.

    /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username} 
  STRING
end

.namespace_not_availableObject

Handles the case where the namespace is not available

Author:

  • Jason Colyer

Since:

  • 1.0.42



130
131
132
133
134
135
136
137
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 130

def self.namespace_not_available
  issue = Readiness::GitLab::Issues.new
  issue.title = "Namespace Availability Check - #{CGI.escape(namespace_to_check)}"
  issue.description = namespace_not_available_message
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.namespace_not_available_messageObject

Returns the issue description for a case where the namespace is not available

Author:

  • Jason Colyer

Since:

  • 1.0.42



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 158

def self.namespace_not_available_message
  <<~STRING
    ## Namespace Availability Check for #{CGI.escape(namespace_to_check)}

    Greetings @#{requester.username} !

    We have looked into the availability of the namespace #{CGI.escape(namespace_to_check)} and have determined it will not be available for release at this time.

    /label ~"AutomatedRequests::Namespace Availability Check" ~p4 ~administrative ~"Stage::Completed"

    /iteration [cadence:"Customer Support Operations"] --current

    /assign @#{requester.username} 
  STRING
end

.namespace_to_checkObject

Sets the global variable namespace_to_check

Author:

  • Jason Colyer

Since:

  • 1.0.42



80
81
82
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 80

def self.namespace_to_check
  @namespace_to_check ||= ENV.fetch('NAMESPACE')
end

.process!(client, admin_client) ⇒ Object

Process a Namesquatting Availability check request

Author:

  • Jason Colyer

Since:

  • 1.0.42



18
19
20
21
22
23
24
25
26
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 18

def self.process!(client, admin_client)
  @gitlab_client = client
  @gitlab_admin_client = admin_client
  requester
  namespace_does_not_exist unless Readiness::GitLab::Namespaces.exists?(@gitlab_admin_client, namespace_to_check)
  namespace_not_available if Readiness::GitLab::Namespaces.is_paid?(@gitlab_admin_client, namespace)
  user_checks if namespace.kind. == 'user'
  group_checks if namespace.kind == 'group'
end

.projectObject

Sets the global variable project

Author:

  • Jason Colyer

Since:

  • 1.0.42



98
99
100
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 98

def self.project
  @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 68534119)
end

.requesterObject

Sets the global variable requester

Author:

  • Jason Colyer

Since:

  • 1.0.42



71
72
73
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 71

def self.requester
  @requester ||= Readiness::SupportSuperFormProcessor::Shared.gitlab_user_check(@gitlab_admin_client, requester_email)
end

.requester_emailObject

Sets the global variable requester_email

Author:

  • Jason Colyer

Since:

  • 1.0.42



89
90
91
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 89

def self.requester_email
  @requester_email ||= ENV.fetch('REQUESTER_EMAIL')
end

.user_checksObject

Perform the user checks for a Namesquatting Availability check request

Author:

  • Jason Colyer

Since:

  • 1.0.42



33
34
35
36
37
38
39
40
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 33

def self.user_checks
  search = Readiness::GitLab::Users.search_by_username(@gitlab_admin_client, namespace_to_check)
  user = search.detect { |s| s.username.downcase == namespace_to_check.downcase }
  namespace_may_be_available if user.confirmed_at.nil? && user_created_recently?(user)
  namespace_not_available if (Date.today - 2.years) < Date.parse(user.)
  namespace_not_available if Readiness::GitLab::Users.only_maintainer?(@gitlab_admin_client, user)
  namespace_may_be_available
end

.user_created_recently?(user) ⇒ Boolean

Determines if a user was created recently

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.42



48
49
50
# File 'lib/support_readiness/support_super_form_processor/namespace_availability.rb', line 48

def self.user_created_recently?(user)
  (Date.today - 90.days) < Date.parse(user.created_at)
end