Class: Aidp::Watch::RepositoryClient

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/watch/repository_client.rb

Overview

Lightweight adapter around GitHub for watch mode. Prefers the GitHub CLI (works for private repositories) and falls back to public REST endpoints when the CLI is unavailable.

Defined Under Namespace

Classes: BinaryChecker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner:, repo:, gh_available: nil, binary_checker: BinaryChecker.new) ⇒ RepositoryClient

Returns a new instance of RepositoryClient.



37
38
39
40
41
42
# File 'lib/aidp/watch/repository_client.rb', line 37

def initialize(owner:, repo:, gh_available: nil, binary_checker: BinaryChecker.new)
  @owner = owner
  @repo = repo
  @binary_checker = binary_checker
  @gh_available = gh_available.nil? ? @binary_checker.gh_cli_available? : gh_available
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



24
25
26
# File 'lib/aidp/watch/repository_client.rb', line 24

def owner
  @owner
end

#repoObject (readonly)

Returns the value of attribute repo.



24
25
26
# File 'lib/aidp/watch/repository_client.rb', line 24

def repo
  @repo
end

Class Method Details

.parse_issues_url(issues_url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/aidp/watch/repository_client.rb', line 26

def self.parse_issues_url(issues_url)
  case issues_url
  when %r{\Ahttps://github\.com/([^/]+)/([^/]+)(?:/issues)?/?\z}
    [$1, $2]
  when %r{\A([^/]+)/([^/]+)\z}
    [$1, $2]
  else
    raise ArgumentError, "Unsupported issues URL: #{issues_url}"
  end
end

Instance Method Details

#add_labels(number, *labels) ⇒ Object



76
77
78
# File 'lib/aidp/watch/repository_client.rb', line 76

def add_labels(number, *labels)
  gh_available? ? add_labels_via_gh(number, labels.flatten) : add_labels_via_api(number, labels.flatten)
end

#create_pull_request(title:, body:, head:, base:, issue_number:, draft: false, assignee: nil) ⇒ Object



72
73
74
# File 'lib/aidp/watch/repository_client.rb', line 72

def create_pull_request(title:, body:, head:, base:, issue_number:, draft: false, assignee: nil)
  gh_available? ? create_pull_request_via_gh(title: title, body: body, head: head, base: base, issue_number: issue_number, draft: draft, assignee: assignee) : raise("GitHub CLI not available - cannot create PR")
end

#fetch_ci_status(number) ⇒ Object



107
108
109
# File 'lib/aidp/watch/repository_client.rb', line 107

def fetch_ci_status(number)
  gh_available? ? fetch_ci_status_via_gh(number) : fetch_ci_status_via_api(number)
end

#fetch_issue(number) ⇒ Object



56
57
58
# File 'lib/aidp/watch/repository_client.rb', line 56

def fetch_issue(number)
  gh_available? ? fetch_issue_via_gh(number) : fetch_issue_via_api(number)
end

#fetch_pr_comments(number) ⇒ Object



119
120
121
# File 'lib/aidp/watch/repository_client.rb', line 119

def fetch_pr_comments(number)
  gh_available? ? fetch_pr_comments_via_gh(number) : fetch_pr_comments_via_api(number)
end

#fetch_pull_request(number) ⇒ Object

PR-specific operations



95
96
97
# File 'lib/aidp/watch/repository_client.rb', line 95

def fetch_pull_request(number)
  gh_available? ? fetch_pull_request_via_gh(number) : fetch_pull_request_via_api(number)
end

#fetch_pull_request_diff(number) ⇒ Object



99
100
101
# File 'lib/aidp/watch/repository_client.rb', line 99

def fetch_pull_request_diff(number)
  gh_available? ? fetch_pull_request_diff_via_gh(number) : fetch_pull_request_diff_via_api(number)
end

#fetch_pull_request_files(number) ⇒ Object



103
104
105
# File 'lib/aidp/watch/repository_client.rb', line 103

def fetch_pull_request_files(number)
  gh_available? ? fetch_pull_request_files_via_gh(number) : fetch_pull_request_files_via_api(number)
end

#find_comment(number, header_text) ⇒ Object



64
65
66
# File 'lib/aidp/watch/repository_client.rb', line 64

def find_comment(number, header_text)
  gh_available? ? find_comment_via_gh(number, header_text) : find_comment_via_api(number, header_text)
end

#full_repoObject



48
49
50
# File 'lib/aidp/watch/repository_client.rb', line 48

def full_repo
  "#{owner}/#{repo}"
end

#gh_available?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/aidp/watch/repository_client.rb', line 44

def gh_available?
  @gh_available
end

#list_issues(labels: [], state: "open") ⇒ Object



52
53
54
# File 'lib/aidp/watch/repository_client.rb', line 52

def list_issues(labels: [], state: "open")
  gh_available? ? list_issues_via_gh(labels: labels, state: state) : list_issues_via_api(labels: labels, state: state)
end

#list_pull_requests(labels: [], state: "open") ⇒ Object



115
116
117
# File 'lib/aidp/watch/repository_client.rb', line 115

def list_pull_requests(labels: [], state: "open")
  gh_available? ? list_pull_requests_via_gh(labels: labels, state: state) : list_pull_requests_via_api(labels: labels, state: state)
end

#most_recent_label_actor(number) ⇒ Object



90
91
92
# File 'lib/aidp/watch/repository_client.rb', line 90

def most_recent_label_actor(number)
  gh_available? ? most_recent_label_actor_via_gh(number) : nil
end

#post_comment(number, body) ⇒ Object



60
61
62
# File 'lib/aidp/watch/repository_client.rb', line 60

def post_comment(number, body)
  gh_available? ? post_comment_via_gh(number, body) : post_comment_via_api(number, body)
end

#post_review_comment(number, body, commit_id: nil, path: nil, line: nil) ⇒ Object



111
112
113
# File 'lib/aidp/watch/repository_client.rb', line 111

def post_review_comment(number, body, commit_id: nil, path: nil, line: nil)
  gh_available? ? post_review_comment_via_gh(number, body, commit_id: commit_id, path: path, line: line) : post_review_comment_via_api(number, body, commit_id: commit_id, path: path, line: line)
end

#remove_labels(number, *labels) ⇒ Object



80
81
82
# File 'lib/aidp/watch/repository_client.rb', line 80

def remove_labels(number, *labels)
  gh_available? ? remove_labels_via_gh(number, labels.flatten) : remove_labels_via_api(number, labels.flatten)
end

#replace_labels(number, old_labels:, new_labels:) ⇒ Object



84
85
86
87
88
# File 'lib/aidp/watch/repository_client.rb', line 84

def replace_labels(number, old_labels:, new_labels:)
  # Remove old labels and add new ones atomically where possible
  remove_labels(number, *old_labels) unless old_labels.empty?
  add_labels(number, *new_labels) unless new_labels.empty?
end

#update_comment(comment_id, body) ⇒ Object



68
69
70
# File 'lib/aidp/watch/repository_client.rb', line 68

def update_comment(comment_id, body)
  gh_available? ? update_comment_via_gh(comment_id, body) : update_comment_via_api(comment_id, body)
end