Class: SingularityClient::API

Inherits:
Object
  • Object
show all
Defined in:
lib/singularity_client/api.rb

Overview

Handles the singularity api

Class Method Summary collapse

Class Method Details

.add(config, repo, project, type) ⇒ Object

Add to the singularity config the ‘type’ parameter can be pull_request or push



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/singularity_client/api.rb', line 24

def self.add(config, repo, project, type)
  # This is just to maintain backwards compatability
  type ||= 'pull_request'

  endpoint = (type == 'push') ? 'config/push' : 'config/pull_request'
  post_data = {
    organization: config.organization,
    repo: repo,
    project: project
  }

  request = SingularityClient::Request.new(config)
  request.post(endpoint, post_data)

  puts('success!')
end

.comment(config, repo, pr, comment) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/singularity_client/api.rb', line 41

def self.comment(config, repo, pr, comment)
  # if pr is not a number, pr.to_i will return 0
  # zero is not a valid pull-request identifier
  fail('ERROR invalid pull-request provided') if pr.to_i == 0

  endpoint = 'comment'
  post_data = {
    organization: config.organization,
    repo: repo,
    pull_request: pr,
    message: comment
  }

  request = SingularityClient::Request.new(config)
  request.post(endpoint, post_data)

  puts('success!')
end

.config(config) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/singularity_client/api.rb', line 11

def self.config(config)
  endpoint = 'config'

  request = SingularityClient::Request.new(config)
  response = request.get(endpoint)

  pp(JSON.parse(response.body))
end