Class: Dri::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/dri/api_client.rb

Constant Summary collapse

API_URL =
'https://gitlab.com/api/v4'
TESTCASES_PROJECT_ID =
'11229385'
TRIAGE_PROJECT_ID =
'34185524'
GITLAB_PROJECT_ID =
'278964'

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ApiClient

Returns a new instance of ApiClient.



15
16
17
18
# File 'lib/dri/api_client.rb', line 15

def initialize(config)
  profile = config.read
  @token = profile["settings"]["token"]
end

Instance Method Details

#delete_award_emoji(url) ⇒ Object



86
87
88
# File 'lib/dri/api_client.rb', line 86

def delete_award_emoji(url)
  delete_json(url)
end

#fetch_awarded_emojis(url) ⇒ Object



32
33
34
# File 'lib/dri/api_client.rb', line 32

def fetch_awarded_emojis(url)
  fetch_json(url)
end

#fetch_current_triage_issueObject



53
54
55
56
57
58
59
# File 'lib/dri/api_client.rb', line 53

def fetch_current_triage_issue
  url = ["#{API_URL}/projects/"]
  url << "#{TRIAGE_PROJECT_ID}/issues?state=opened"
  url << "&order_by=updated_at"

  fetch_json(url.join)
end

#fetch_failing_testcases(pipeline, state:) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/dri/api_client.rb', line 36

def fetch_failing_testcases(pipeline, state:)
  url = ["#{API_URL}/projects/"]
  url << "#{TESTCASES_PROJECT_ID}/issues?labels=#{pipeline}::failed"
  url << "&state=#{state}&not[labels]=quarantine"
  url << "&scope=all"

  fetch_json(url.join)
end

#fetch_failure_notes(issue_iid:) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/dri/api_client.rb', line 78

def fetch_failure_notes(issue_iid:)
  url = ["#{API_URL}/projects/"]
  url << "#{GITLAB_PROJECT_ID}/issues/"
  url << "#{issue_iid}/notes?per_page=15"

  fetch_json(url.join)
end

#fetch_failures(date:, state:) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/dri/api_client.rb', line 68

def fetch_failures(date:, state:)
  url = ["#{API_URL}/issues"]
  url << "?labels=failure::new"
  url << "&order_by=updated_at&state=#{state}"
  url << "&scope=all"
  url << "&created_after=#{date}"

  fetch_json(url.join)
end


45
46
47
48
49
50
51
# File 'lib/dri/api_client.rb', line 45

def fetch_related_mrs(issue_iid:)
  url = ["#{API_URL}/projects/"]
  url << "#{GITLAB_PROJECT_ID}/issues/"
  url << "#{issue_iid}/related_merge_requests"

  fetch_json(url.join)
end

#fetch_triaged_failures(emoji:, state:) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/dri/api_client.rb', line 24

def fetch_triaged_failures(emoji:, state:)
  url = ["#{API_URL}/issues"]
  url << "?order_by=updated_at&my_reaction_emoji=#{emoji}"
  url << "&scope=all&state=#{state}"

  fetch_json(url.join)
end

#headerObject



20
21
22
# File 'lib/dri/api_client.rb', line 20

def header
  @header ||= { 'Content-Type' => 'application/json', "Authorization" => "Bearer #{@token}" }
end

#post_triage_report_note(iid:, body:) ⇒ Object



61
62
63
64
65
66
# File 'lib/dri/api_client.rb', line 61

def post_triage_report_note(iid:, body:)
  url = ["#{API_URL}/projects/"]
  url << "#{TRIAGE_PROJECT_ID}/issues/#{iid}/notes"

  post_json(url.join, body)
end