Class: RailsErrorDashboard::Services::CodebergIssueClient
Overview
Codeberg/Gitea/Forgejo REST API client for issue management.
Codeberg runs Forgejo (hard fork of Gitea). The API is compatible with Gitea’s /api/v1/ endpoints. Works with any Gitea or Forgejo instance.
API Docs: docs.gitea.com/development/api-usage Codeberg: codeberg.org/api/swagger Auth: Personal access token
Constant Summary
IssueTrackerClient::MAX_BODY_LENGTH, IssueTrackerClient::REQUEST_TIMEOUT
Instance Attribute Summary
#api_url, #repo, #token
Instance Method Summary
collapse
for, from_config
Constructor Details
#initialize(token:, repo:, api_url: nil) ⇒ CodebergIssueClient
Returns a new instance of CodebergIssueClient.
14
15
16
17
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 14
def initialize(token:, repo:, api_url: nil)
super
@api_url = api_url || "https://codeberg.org/api/v1"
end
|
Instance Method Details
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 56
def (number:, body:)
response = http_post(
"#{@api_url}/repos/#{@repo}/issues/#{number}/comments",
{ body: truncate_body(body) },
)
if response[:status] == 201
success_response(url: response[:body]["html_url"])
else
error_response("Codeberg API error (#{response[:status]})")
end
end
|
#close_issue(number:) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 36
def close_issue(number:)
response = http_patch(
"#{@api_url}/repos/#{@repo}/issues/#{number}",
{ state: "closed" },
)
response[:status] == 201 ? success_response({}) : error_response("Codeberg API error (#{response[:status]})")
end
|
#create_issue(title:, body:, labels: []) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 19
def create_issue(title:, body:, labels: [])
response = http_post(
"#{@api_url}/repos/#{@repo}/issues",
{ title: title, body: truncate_body(body) },
)
if response[:status] == 201
data = response[:body]
success_response(url: data["html_url"], number: data["number"])
else
error_response("Codeberg API error (#{response[:status]}): #{response[:body]&.dig("message") || response[:error]}")
end
end
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 70
def (number:, per_page: 10)
response = http_get(
"#{@api_url}/repos/#{@repo}/issues/#{number}/comments?limit=#{per_page}",
)
if response[:status] == 200
= (response[:body] || []).map { |c|
{
author: c.dig("user", "login"),
avatar_url: c.dig("user", "avatar_url"),
body: c["body"],
created_at: c["created_at"],
url: c["html_url"]
}
}
success_response(comments: )
else
error_response("Codeberg API error (#{response[:status]})")
end
end
|
#fetch_issue(number:) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 92
def fetch_issue(number:)
response = http_get(
"#{@api_url}/repos/#{@repo}/issues/#{number}",
)
if response[:status] == 200
data = response[:body]
success_response(
state: data["state"],
title: data["title"],
assignees: (data["assignees"] || []).map { |a|
{ login: a["login"], avatar_url: a["avatar_url"] }
},
labels: (data["labels"] || []).map { |l|
{ name: l["name"], color: l["color"] }
}
)
else
error_response("Codeberg API error (#{response[:status]})")
end
end
|
#reopen_issue(number:) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/rails_error_dashboard/services/codeberg_issue_client.rb', line 46
def reopen_issue(number:)
response = http_patch(
"#{@api_url}/repos/#{@repo}/issues/#{number}",
{ state: "open" },
)
response[:status] == 201 ? success_response({}) : error_response("Codeberg API error (#{response[:status]})")
end
|