Class: Dependagrab::GithubClient
- Inherits:
-
Object
- Object
- Dependagrab::GithubClient
- Defined in:
- lib/dependagrab/github_client.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #grab ⇒ Object
-
#initialize(options = {}) ⇒ GithubClient
constructor
A new instance of GithubClient.
Constructor Details
#initialize(options = {}) ⇒ GithubClient
Returns a new instance of GithubClient.
6 7 8 9 10 |
# File 'lib/dependagrab/github_client.rb', line 6 def initialize(={}) @repo = .fetch(:repo) @owner = .fetch(:owner) @token = [:token] || default_github_token end |
Instance Attribute Details
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
4 5 6 |
# File 'lib/dependagrab/github_client.rb', line 4 def owner @owner end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'lib/dependagrab/github_client.rb', line 4 def repo @repo end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/dependagrab/github_client.rb', line 4 def token @token end |
Instance Method Details
#grab ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dependagrab/github_client.rb', line 12 def grab result = { alerts: [] } query_variables = { repo: repo, owner: owner } has_next_page = true # always run query at least once while(has_next_page) response = GHAPI::Client.query(GHAPI::Query, variables: query_variables, context: { api_token: token } ) validate_response!(response) response.original_hash['data']['repository']['vulnerabilityAlerts']['nodes'].each do |alert| result[:alerts].append( parse_alert(alert) ) end # Sets the last position for pagination query_variables[:after_cursor] = response.data.repository.vulnerability_alerts.page_info.end_cursor has_next_page = response.data.repository.vulnerability_alerts.page_info.has_next_page end result end |