Class: Wassup::Panes::GitHub::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/wassup/panes/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(org:, repo: nil, query:, show_repo: true, show_username: false, show_interactions: false) ⇒ Search

Returns a new instance of Search.



62
63
64
65
66
67
68
69
# File 'lib/wassup/panes/github.rb', line 62

def initialize(org:, repo: nil, query:, show_repo: true, show_username: false, show_interactions: false)
  @org = org
  @repo = repo
  @query = query
  @show_repo = show_repo
  @show_username = show_username
  @show_interactions = show_interactions
end

Instance Attribute Details

#orgObject

Returns the value of attribute org.



55
56
57
# File 'lib/wassup/panes/github.rb', line 55

def org
  @org
end

#queryObject

Returns the value of attribute query.



57
58
59
# File 'lib/wassup/panes/github.rb', line 57

def query
  @query
end

#repoObject

Returns the value of attribute repo.



56
57
58
# File 'lib/wassup/panes/github.rb', line 56

def repo
  @repo
end

#show_interactionsObject

Returns the value of attribute show_interactions.



60
61
62
# File 'lib/wassup/panes/github.rb', line 60

def show_interactions
  @show_interactions
end

#show_repoObject

Returns the value of attribute show_repo.



58
59
60
# File 'lib/wassup/panes/github.rb', line 58

def show_repo
  @show_repo
end

#show_usernameObject

Returns the value of attribute show_username.



59
60
61
# File 'lib/wassup/panes/github.rb', line 59

def show_username
  @show_username
end

Instance Method Details

#configure(pane) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wassup/panes/github.rb', line 71

def configure(pane)
  pane.content do |content|
    # Uses GitHub's /search/issues API
    # Docs - https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
    issues_or_prs = Helpers::GitHub.issues(org: org, repo: repo, q: query)
    issues_or_prs.each do |issue_or_pr|
      display = if issue_or_pr.has_key?('pull_request')
                  Helpers::GitHub::Formatter.pr(issue_or_pr, show_repo: show_repo, show_username: show_username, show_interactions: show_interactions)
                else
                  Helpers::GitHub::Formatter.issue(issue_or_pr, show_repo: show_repo, show_username: show_username, show_interactions: show_interactions)
                end
      content.add_row(display, issue_or_pr)
    end
  end
  pane.selection('enter', 'Open in browser') do |pr|
    `open #{pr['html_url']}`
  end
end