Class: GitlabApi::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/git/gitlab/api/issue.rb,
lib/git/gitlab/apiclient.rb,
lib/git/gitlab/api/authorize.rb,
lib/git/gitlab/api/mergerequest.rb

Direct Known Subclasses

GitlabKernel

Defined Under Namespace

Modules: Authorize, Issue, Mergerequest

Constant Summary collapse

API_VERSION =
"v3"
USER_AGENT =
"nyonyonyonyonyo! Gitlab nyo!!"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApiClient

Returns a new instance of ApiClient.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/git/gitlab/apiclient.rb', line 13

def initialize
  @repository = Grit::Repo.new(`git rev-parse --show-toplevel`.chomp)
  config = @repository.config

  url = config["gitlab.url"]
  if url == nil
    raise "Plase set 'git config gitlab.url ${Gitlab URL}'"
  end

  token = config["gitlab.token"]
  if token == nil
    raise "Please set 'git config gitlab.token ${Gitlab Token}'"
  end

  Gitlab.configure do |config|
    config.endpoint       = "#{url}/api/#{API_VERSION}"
    config.private_token  = token
    config.user_agent     = USER_AGENT
  end

  @client = Gitlab.client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/git/gitlab/apiclient.rb', line 11

def client
  @client
end

#repositoryObject (readonly)

Returns the value of attribute repository.



11
12
13
# File 'lib/git/gitlab/apiclient.rb', line 11

def repository
  @repository
end

Instance Method Details

#project_idObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/git/gitlab/apiclient.rb', line 36

def project_id
  pid = if @repository.config.keys.include? "gitlab.projectid"
      @repository.config["gitlab.projectid"].to_i
    else
      @repository.config["gitlab.project"]
    end

  if pid == nil
    raise "Please set 'git config gitlab.projectid ${Gitlab Project id}' of git config gitlab.project ${NAMESPACE/PROJECT}"
  end

  begin
    @client.project( URI.encode_www_form_component(pid.to_s)).id
  rescue Gitlab::Error::NotFound => e
    raise GitlabApi::Error::ProjectIdNotFound, "Can not find #{pid} Project."
  end

end