Module: GitlabCli::Util

Defined in:
lib/gitlab_cli/util.rb,
lib/gitlab_cli/util/project.rb,
lib/gitlab_cli/util/snippet.rb,
lib/gitlab_cli/util/projects.rb,
lib/gitlab_cli/util/snippets.rb

Defined Under Namespace

Classes: Project, Projects, Snippet, Snippets

Class Method Summary collapse

Class Method Details

.check_response_code(response) ⇒ Object

Check RestClient response code



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab_cli/util.rb', line 36

def self.check_response_code(response)
  if response =~ /401/
    ## Unauthorized
    GitlabCli.ui.error "User token was not present or is not valid."
    exit 1
  elsif response =~ /403/
    ## Forbidden
    GitlabCli.ui.error "You are not authorized to complete this action"
    exit 1
  elsif response =~ /404/
    ## Not found
    GitlabCli.ui.error "Resource could not be found."
    exit 1
  elsif response =~ /405/
    ## Method not allowed
    GitlabCli.ui.error "This request is not supported."
    exit 1
  elsif response =~ /409/
    ## Conflicting resource
    GitlabCli.ui.error "A conflicting resource already exists."
    exit 1
  elsif response =~ /500/
    ## Server error
    GitlabCli.ui.error "Oops.  Something went wrong. Please try again."
  end
  response
end

.get_project_id(project) ⇒ Object

Internal methods Get project id



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab_cli/util.rb', line 13

def self.get_project_id(project)
  projects = GitlabCli::Util::Projects.get_all
  project = projects.detect do |p|
    p.path_with_namespace == project
  end
  
  unless project
    GitlabCli.ui.error "Invalid project name or id."
    exit 1
  end
  project.id
end

.numeric?(string) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gitlab_cli/util.rb', line 31

def self.numeric?(string)
  Float(string) != nil rescue false
end

.url_tokenObject

Construct private token for URL



27
28
29
# File 'lib/gitlab_cli/util.rb', line 27

def self.url_token
  "?private_token=#{GitlabCli::Config[:private_token]}"
end