Module: Brainiac::Plugins::Github::AppClient
- Defined in:
- lib/brainiac/plugins/github/app_client.rb
Overview
HTTP client that authenticates as a GitHub App (installation).
When app credentials are configured (app_id + private_key_path + installation_id), API calls are made as the App's bot user — so PR comments, reactions, etc. appear with the App's identity rather than a personal user.
Falls back to gh CLI when app credentials are not configured.
Constant Summary collapse
- GITHUB_API =
"https://api.github.com"- TOKEN_EXPIRY_BUFFER =
refresh token 60s before expiry
60
Class Method Summary collapse
-
.configured? ⇒ Boolean
Returns true if GitHub App credentials are fully configured.
-
.create_comment(repo, pr_number, body) ⇒ Hash
POST a comment on an issue or PR.
-
.create_comment_reaction(repo, comment_id, reaction) ⇒ Hash
POST a reaction on an issue comment.
-
.create_review_reaction(repo, review_id, reaction) ⇒ Hash
POST a reaction on a PR review.
-
.get(path) ⇒ Hash
GET request to GitHub API.
-
.post(path, body) ⇒ Hash
POST request to GitHub API.
-
.reset! ⇒ Object
Reset cached token (useful for testing or when credentials change).
Class Method Details
.configured? ⇒ Boolean
Returns true if GitHub App credentials are fully configured.
30 31 32 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 30 def configured? !!(Config.app_id && Config.private_key_path && Config.installation_id) end |
.create_comment(repo, pr_number, body) ⇒ Hash
POST a comment on an issue or PR.
40 41 42 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 40 def create_comment(repo, pr_number, body) post("/repos/#{repo}/issues/#{pr_number}/comments", { body: body }) end |
.create_comment_reaction(repo, comment_id, reaction) ⇒ Hash
POST a reaction on an issue comment.
50 51 52 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 50 def create_comment_reaction(repo, comment_id, reaction) post("/repos/#{repo}/issues/comments/#{comment_id}/reactions", { content: reaction }) end |
.create_review_reaction(repo, review_id, reaction) ⇒ Hash
POST a reaction on a PR review.
60 61 62 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 60 def create_review_reaction(repo, review_id, reaction) post("/repos/#{repo}/pulls/reviews/#{review_id}/reactions", { content: reaction }) end |
.get(path) ⇒ Hash
GET request to GitHub API.
68 69 70 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 68 def get(path) request(:get, path) end |
.post(path, body) ⇒ Hash
POST request to GitHub API.
77 78 79 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 77 def post(path, body) request(:post, path, body) end |
.reset! ⇒ Object
Reset cached token (useful for testing or when credentials change).
82 83 84 85 86 87 |
# File 'lib/brainiac/plugins/github/app_client.rb', line 82 def reset! @mutex.synchronize do @token = nil @token_expires_at = nil end end |