From e8736be7ea0daa9d30bdee931584c8e8cd1a493a Mon Sep 17 00:00:00 2001 From: Jeff McFadden Date: Fri, 17 May 2024 15:18:37 -0700 Subject: [PATCH] Standard --- Rakefile | 4 ++-- lib/ghx.rb | 9 +++++++++ lib/ghx/dependabot.rb | 2 +- lib/ghx/issue.rb | 29 +++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index 09b166a..2480d0e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,2 @@ -require 'bundler' -Bundler::GemHelper.install_tasks \ No newline at end of file +require "bundler" +Bundler::GemHelper.install_tasks diff --git a/lib/ghx.rb b/lib/ghx.rb index b442ed0..15ed9df 100644 --- a/lib/ghx.rb +++ b/lib/ghx.rb @@ -3,6 +3,15 @@ require "json" require "octokit" +class Hash + def symbolize_keys! + keys.each do |key| + self[key.to_sym] = delete(key) + end + self + end +end + require_relative "version" require_relative "ghx/graphql_client" require_relative "ghx/rest_client" diff --git a/lib/ghx/dependabot.rb b/lib/ghx/dependabot.rb index 5782a4f..eba3708 100644 --- a/lib/ghx/dependabot.rb +++ b/lib/ghx/dependabot.rb @@ -1,7 +1,7 @@ module GHX module Dependabot def self.get_alerts(owner:, repo:) - GHX.rest_get("repos/#{owner}/#{repo}/dependabot/alerts?state=open&per_page=100").map do |alert| + GHX.rest_client.get("repos/#{owner}/#{repo}/dependabot/alerts?state=open&per_page=100").map do |alert| GHX::Dependabot::Alert.new(alert) end end diff --git a/lib/ghx/issue.rb b/lib/ghx/issue.rb index 1437586..5647be9 100644 --- a/lib/ghx/issue.rb +++ b/lib/ghx/issue.rb @@ -2,6 +2,17 @@ module GHX class Issue attr_accessor :owner, :repo, :number, :title, :body, :state, :state_reason, :author, :assignees, :labels, :milestone, :created_at, :updated_at, :closed_at + def self.search(owner:, repo:, query:) + data = GHX.rest_client.get("search/issues?q=#{URI.encode_www_form_component(query)}+is:issue+repo:#{owner}/#{repo}") + data.fetch("items").to_a.map do |issue_data| + new(owner: owner, repo: repo, **issue_data) + end + rescue => e + GHX.logger.error "Error searching for issues with query: #{e.message}" + GHX.logger.error "Received data: #{data}" + [] + end + def self.find(owner:, repo:, number:) response_data = GHX.rest_client.get("repos/#{owner}/#{repo}/issues/#{number}") new(owner: owner, repo: repo, **response_data) @@ -46,14 +57,16 @@ def update end def update_attributes(hash) - self.number = hash["number"] - self.title = hash["title"] - self.body = hash["body"] - self.state = hash["state"] - self.state_reason = hash["state_reason"] - self.labels = hash["labels"] - self.milestone = hash["milestone"] - self.assignees = hash["assignees"] + hash.symbolize_keys! + + self.number = hash[:number] + self.title = hash[:title] + self.body = hash[:body] + self.state = hash[:state] + self.state_reason = hash[:state_reason] + self.labels = hash[:labels] + self.milestone = hash[:milestone] + self.assignees = hash[:assignees] end end end