Class: GhCliClient

Inherits:
Object
  • Object
show all
Defined in:
lib/github_workflow/gh_cli_client.rb

Instance Method Summary collapse

Instance Method Details

#commits_for_range(commit_range, owner: nil, repo: nil) ⇒ Object



24
25
26
27
# File 'lib/github_workflow/gh_cli_client.rb', line 24

def commits_for_range(commit_range, owner: nil, repo: nil)
  # https://docs.github.com/en/rest/commits/commits#compare-two-commits
  request("'#{path_base(owner, repo)}/compare/#{commit_range}'")
end

#convert_issue_to_pr(id, head:, base:, owner: nil, repo: nil, draft: true) ⇒ Object



20
21
22
# File 'lib/github_workflow/gh_cli_client.rb', line 20

def convert_issue_to_pr(id, head:, base:, owner: nil, repo: nil, draft: true)
  request("'#{path_base(owner, repo)}/pulls'", args: {issue: id.to_i, head: head, base: base, draft: draft})
end

#create_issue(title:, body: '', owner: nil, repo: nil) ⇒ Object



16
17
18
# File 'lib/github_workflow/gh_cli_client.rb', line 16

def create_issue(title:, body: '', owner: nil, repo: nil)
  request("'#{path_base(owner, repo)}/issues'", args: {title: title, body: body})
end

#get_issue(id, owner: nil, repo: nil) ⇒ Object



4
5
6
# File 'lib/github_workflow/gh_cli_client.rb', line 4

def get_issue(id, owner: nil, repo: nil)
  request("'#{path_base(owner, repo)}/issues/#{id}'")
end

#get_pr(id, owner: nil, repo: nil) ⇒ Object



8
9
10
# File 'lib/github_workflow/gh_cli_client.rb', line 8

def get_pr(id, owner: nil, repo: nil)
  request("'#{path_base(owner, repo)}/pulls/#{id}'")
end

#get_prs_list(owner: nil, repo: nil) ⇒ Object



12
13
14
# File 'lib/github_workflow/gh_cli_client.rb', line 12

def get_prs_list(owner: nil, repo: nil)
  request("'#{path_base(owner, repo)}/pulls?per_page=100'")
end

#get_repo_infoObject



33
34
35
36
37
38
39
40
41
# File 'lib/github_workflow/gh_cli_client.rb', line 33

def get_repo_info
  @repo_info ||= begin
    result = `gh repo view --json owner,name -q ".owner.login,.name"`.split("\n").compact
    {
      owner: result[0],
      repo: result[1]
    }
  end
end

#get_statuses(branch: '{branch}', owner: nil, repo: nil) ⇒ Object



29
30
31
# File 'lib/github_workflow/gh_cli_client.rb', line 29

def get_statuses(branch: '{branch}', owner: nil, repo: nil)
  request("'#{path_base(owner, repo)}/statuses/#{branch}'")
end

#latest_remote_commit(owner:, repo:) ⇒ Object



43
44
45
46
# File 'lib/github_workflow/gh_cli_client.rb', line 43

def latest_remote_commit(owner:, repo:)
  result = `gh browse -R '#{owner}/#{repo}' -n -c`
  result.split("/").last.strip
end