Class: PullRequestAi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pull_request_ai/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(openai_api_key: nil, openai_api_endpoint: nil, github_api_endpoint: nil, github_access_token: nil, bitbucket_api_endpoint: nil, bitbucket_app_password: nil, bitbucket_username: nil, api_version: nil, model: nil, temperature: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pull_request_ai/client.rb', line 5

def initialize(
  openai_api_key: nil,
  openai_api_endpoint: nil,
  github_api_endpoint: nil,
  github_access_token: nil,
  bitbucket_api_endpoint: nil,
  bitbucket_app_password: nil,
  bitbucket_username: nil,
  api_version: nil,
  model: nil,
  temperature: nil
)
  PullRequestAi.configuration.openai_api_key = openai_api_key if openai_api_key
  PullRequestAi.configuration.openai_api_endpoint = openai_api_endpoint if openai_api_endpoint
  PullRequestAi.configuration.github_api_endpoint = github_api_endpoint if github_api_endpoint
  PullRequestAi.configuration.github_access_token = github_access_token if github_access_token
  PullRequestAi.configuration.bitbucket_api_endpoint = bitbucket_api_endpoint if bitbucket_api_endpoint
  PullRequestAi.configuration.bitbucket_app_password = bitbucket_app_password if bitbucket_app_password
  PullRequestAi.configuration.bitbucket_username = bitbucket_username if bitbucket_username
  PullRequestAi.configuration.api_version = api_version if api_version
  PullRequestAi.configuration.model = model if model
  PullRequestAi.configuration.temperature = temperature if temperature
end

Instance Method Details

#ai_clientObject



37
38
39
# File 'lib/pull_request_ai/client.rb', line 37

def ai_client
  @ai_client ||= PullRequestAi::OpenAi::Client.new
end

#ai_interpreterObject



41
42
43
# File 'lib/pull_request_ai/client.rb', line 41

def ai_interpreter
  @ai_interpreter ||= PullRequestAi::OpenAi::Interpreter.new
end

#current_opened_pull_requests(base) ⇒ Object



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

def current_opened_pull_requests(base)
  repo_reader.repository_slug.bind do |slug|
    repo_reader.current_branch.bind do |branch|
      repo_client.opened_pull_requests(slug, branch, base)
    end
  end
end

#destination_branchesObject



53
54
55
# File 'lib/pull_request_ai/client.rb', line 53

def destination_branches
  repo_reader.destination_branches
end

#flatten_current_changes(to_branch) ⇒ Object



71
72
73
# File 'lib/pull_request_ai/client.rb', line 71

def flatten_current_changes(to_branch)
  repo_reader.flatten_current_changes(to_branch)
end

#open_pull_request(to_base, title, description) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/pull_request_ai/client.rb', line 57

def open_pull_request(to_base, title, description)
  repo_reader.repository_slug.bind do |slug|
    repo_reader.current_branch.bind do |branch|
      repo_client.open_pull_request(slug, branch, to_base, title, description)
    end
  end
end

#repo_clientObject



33
34
35
# File 'lib/pull_request_ai/client.rb', line 33

def repo_client
  @repo_client ||= PullRequestAi::Repo::Client.client_from_host(repo_reader.repository_host)
end

#repo_readerObject



29
30
31
# File 'lib/pull_request_ai/client.rb', line 29

def repo_reader
  @repo_reader ||= PullRequestAi::Repo::Reader.new
end

#suggested_description(type, summary, changes) ⇒ Object



75
76
77
78
# File 'lib/pull_request_ai/client.rb', line 75

def suggested_description(type, summary, changes)
  chat_message = ai_interpreter.chat_message(type, summary, changes)
  ai_client.predicted_completions(chat_message)
end

#update_pull_request(number, base, title, description) ⇒ Object



65
66
67
68
69
# File 'lib/pull_request_ai/client.rb', line 65

def update_pull_request(number, base, title, description)
  repo_reader.repository_slug.bind do |slug|
    repo_client.update_pull_request(slug, number, base, title, description)
  end
end