Class: Houston::Adapters::VersionControl::GitAdapter::GithubRepo

Inherits:
RemoteRepo
  • Object
show all
Defined in:
app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb

Constant Summary

Constants inherited from RemoteRepo

RemoteRepo::RETRY_COOLDOWN

Instance Attribute Summary

Attributes inherited from Repo

#location

Instance Method Summary collapse

Methods inherited from RemoteRepo

#before_update, #clone!, #git_path, #initialize, #origin, #pull!, #refresh!

Methods inherited from Repo

#all_commit_times, #all_commits, #ancestors, #ancestors_until, #branch, #branches, #branches_at, #changes, #commits_between, #exists?, #find_file, #git_path, #initialize, #native_commit, #read_file, #ref, #refresh!, #to_s

Constructor Details

This class inherits a constructor from Houston::Adapters::VersionControl::GitAdapter::RemoteRepo

Instance Method Details

#add_labels_to(labels, issue_number) ⇒ Object Also known as: add_label_to



69
70
71
72
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 69

def add_labels_to(labels, issue_number)
  issue_number = issue_number.number if issue_number.respond_to? :number
  Houston.github.add_labels_to_an_issue repo_name, issue_number, Array(labels)
end

#commit_range_url(sha0, sha1) ⇒ Object



23
24
25
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 23

def commit_range_url(sha0, sha1)
  "#{project_url}/compare/#{sha0}...#{sha1}"
end

#commit_status_url(sha) ⇒ Object



27
28
29
30
31
32
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 27

def commit_status_url(sha)
  # GitHub requires the full 40-character sha
  sha = native_commit(sha).sha if sha.length < 40
  path = Addressable::URI.parse(project_url).path[1..-1]
  "https://api.github.com/repos/#{path}/statuses/#{sha}"
end

#commit_url(sha) ⇒ Object



19
20
21
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 19

def commit_url(sha)
  "#{project_url}/commit/#{sha}"
end

#create_commit_status(sha, status = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 38

def create_commit_status(sha, status={})
  status = OpenStruct.new(status) if status.is_a?(Hash)
  unless %w{pending success failure error}.member?(status.state)
    raise ArgumentError, ":state must be either 'pending', 'success', 'failure', or 'error'"
  end

  target_url = status.url if status.respond_to?(:url)
  target_url = status.target_url if status.respond_to?(:target_url)

  Houston.github.create_status(repo_name, sha, status.state, {
    context: status.context,
    target_url: target_url,
    description: status.description })
end

#create_pull_request(base: nil, head: nil, title: nil, body: nil, options: {}) ⇒ Object



61
62
63
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 61

def create_pull_request(base: nil, head: nil, title: nil, body: nil, options: {})
  Houston.github.create_pull_request(repo_name, base, head, title, body, options)
end

#issues(options = {}) ⇒ Object



65
66
67
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 65

def issues(options={})
  Houston.github.issues(repo_name, options)
end

#project_urlObject



8
9
10
11
12
13
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 8

def project_url
  location
    .gsub(/^git@(?:www\.)?github.com:/, "https://github.com/")
    .gsub(/^git:/, "https:")
    .gsub(/\.git$/, "")
end

#pull_requests(options = {}) ⇒ Object

GitHub API



57
58
59
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 57

def pull_requests(options={})
  Houston.github.pull_requests(repo_name, options)
end

#pulls_urlObject



15
16
17
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 15

def pulls_url
  "#{project_url}/pulls"
end

#remove_label_from(label, issue_number) ⇒ Object



75
76
77
78
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 75

def remove_label_from(label, issue_number)
  issue_number = issue_number.number if issue_number.respond_to? :number
  Houston.github.remove_label repo_name, issue_number, label
end

#repo_nameObject



34
35
36
# File 'app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb', line 34

def repo_name
  Addressable::URI.parse(location).path[0...-4].gsub(/^\//, "")
end