Skip to content

Commit

Permalink
rubocopにより修正
Browse files Browse the repository at this point in the history
  • Loading branch information
akias committed Sep 30, 2017
1 parent 3eb828e commit c073d48
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 55 deletions.
6 changes: 3 additions & 3 deletions github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def create(query)
# test the auth token
def test_authentication
load_token
return false if !@token || @token.length == 0
res = get "/"
!res.has_key?('error')
return false if !@token || @token.empty?
res = get '/'
!res.key?('error')
end
end
8 changes: 4 additions & 4 deletions github/cache/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# get the data in cache
class Github
module Cache
# Load method
module Load
include Update
# get token which store in token file
Expand All @@ -11,13 +12,12 @@ def load_token

# get current repositories in current repositories file
def load_current_repo
#raise InvalidToken unless test_authentication
@current_repo = File.read(@current_repo_file) if File.exists?(@current_repo_file)
end

# get all repositories in cache file
def load_and_cache_user_repos
if File.exists?(@cache_file)
if File.exist?(@cache_file)
JSON.parse(File.read(@cache_file))
else
cache_all_repos_for_user
Expand All @@ -26,7 +26,7 @@ def load_and_cache_user_repos

# get all issues data to cache file
def load_and_cache_user_issues
if File.exists?(@issue_cache_file)
if File.exist?(@issue_cache_file)
JSON.parse(File.read(@issue_cache_file))
else
cache_all_issues_for_repo
Expand All @@ -35,7 +35,7 @@ def load_and_cache_user_issues

# get all closed issues data to cache file
def load_and_cache_user_close_issues
if File.exists?(@close_issue_cache_file)
if File.exist?(@close_issue_cache_file)
JSON.parse(File.read(@close_issue_cache_file))
else
cache_all_close_issues_for_repo
Expand Down
21 changes: 10 additions & 11 deletions github/cache/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
# store token and current_repo
class Github
module Cache
# Store date method
module Store
include Load
# stor the token write in @token_file
def store_token(token)
if token && token.length > 0
File.open(@token_file, 'w') do |f|
f.write(token)
end
load_token
rebuild_user_repos_cache
return unless token && !token.empty?
File.open(@token_file, 'w') do |f|
f.write(token)
end
load_token
rebuild_user_repos_cache
end

# store current_repo write in @current_repo_file
def store_current_repo(repo)
if repo && repo.length > 0
File.open(@current_repo_file, 'w') do |f|
f.write(repo)
end
return unless repo && !repo.empty?
File.open(@current_repo_file, 'w') do |f|
f.write(repo)
end
end
end
end
end
end
16 changes: 7 additions & 9 deletions github/cache/update.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class Github
module Cache
# update cache method
module Update
# upadate all repositoriese cache
def rebuild_user_repos_cache
File.delete(@cache_file) if File.exists?(@cache_file)
File.delete(@cache_file) if File.exist?(@cache_file)
cache_all_repos_for_user
end

# upadate all issues cache of current repo
def rebuild_user_issues_cache
File.delete(@issue_cache_file) if File.exists?(@issue_cache_file)
File.delete(@issue_cache_file) if File.exist?(@issue_cache_file)
cache_all_issues_for_repo
end

# upadate all closed issues cache of current repo
def rebuild_user_close_issues_cache
File.delete(@all_issue_cache_file) if File.exists?(@all_issue_cache_file)
File.delete(@all_issue_cache_file) if File.exist?(@all_issue_cache_file)
cache_all_close_issues_for_repo
end

# put all repositorise data to cache file
def cache_all_repos_for_user
#raise InvalidToken unless test_authentication
repos = []
repos += get_user_repos
get_user_orgs.each do |org|
Expand Down Expand Up @@ -72,7 +72,6 @@ def get_org_repos(org)

# put all issues data to cache file
def cache_all_issues_for_repo
#raise InvalidToken unless test_authentication
issues = []
issues += get_repo_issues
File.open(@issue_cache_file, 'w') do |f|
Expand All @@ -93,10 +92,9 @@ def get_repo_issues
[]
end
end

# put all closed issues data to cache file
def cache_all_close_issues_for_repo
#raise InvalidToken unless test_authentication
issues = []
issues += get_repo_close_issues
File.open(@all_issue_cache_file, 'w') do |f|
Expand All @@ -108,8 +106,8 @@ def cache_all_close_issues_for_repo

# communicate with github to get closed issues of user
def get_repo_close_issues
#'state' => 'closed' is the parameters of 'get' default is 'opend'
res = get "/repos/#{load_current_repo}/issues", { 'state' => 'closed'}
# 'state' => 'closed' is the parameters of 'get' default is 'opend'
res = get "/repos/#{load_current_repo}/issues", 'state' => 'closed'
if res.is_a?(Array)
res.map do |issue|
{ 'name' => "#{issue['title']}[closed]", 'url' => issue['html_url'] }
Expand Down
6 changes: 3 additions & 3 deletions github/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def get(path, params = {})

json = JSON.parse(res.body)

return { 'error' => json['message'] } unless res.kind_of? Net::HTTPSuccess
return { 'error' => json['message'] } unless res.is_a? Net::HTTPSuccess

if json.is_a?(Array)
json_all.concat json
uri = URI((res['link'].match /<([^>]+)>;\s*rel="next"/ )[1]) rescue nil
uri = URI((res['link'].match /<([^>]+)>;\s*rel="next"/)[1])
break if uri.nil?
else
json_all = json
Expand All @@ -31,7 +31,7 @@ def get(path, params = {})
json_all
end

def post(path,query)
def post(path, query)
uri = URI.parse("#{@base_uri}#{path}")
http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
Expand Down
41 changes: 18 additions & 23 deletions github/search.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
require_relative 'request'

# search method
module Search
include Request
# search all repositories in github
def search_all_repos(query)
return [] if !query || query.length == 0
#raise InvalidToken unless test_authentication

return [] if !query || query.empty?
parts = query.split('/', 2)

if parts.length == 1 and parts[0].length > 0
res = get '/search/repositories', { 'q' => query }
if parts.length == 1 && !parts[0].empty?
res = get '/search/repositories', 'q' => query

if res.is_a?(Hash) and res.has_key?('items')
if res.is_a?(Hash) && res.key?('items')
res['items'].map do |repo|
{ 'name' => repo['full_name'], 'url' => repo['html_url'] }
end
else
[]
end
elsif parts.length == 2 and parts[0].length > 0
elsif parts.length == 2 && !parts[0].empty?
user = parts[0]
user_query = parts[1]
res = get "/users/#{user}/repos"
Expand All @@ -41,23 +40,21 @@ def search_all_repos(query)

# search all issues in github
def search_all_issues(query)
return [] if !query || query.length == 0
#raise InvalidToken unless test_authentication
return [] if !query || query.empty?

parts = query.split('/', 2)

if parts.length == 1 and parts[0].length > 0
res = get "/orgs/#{load_current_repo}/issues", { 'q' => query }
if parts.length == 1 && !parts[0].empty
res = get "/orgs/#{load_current_repo}/issues", 'q' => query

if res.is_a?(Hash) and res.has_key?('items')
if res.is_a?(Hash) && res.key?('items')
res['items'].map do |issue|
{ 'name' => issue['title'], 'url' => issue['html_url'] }
end
else
[]
end
elsif parts.length == 2 and parts[0].length > 0
user = parts[0]
elsif parts.length == 2 && !parts[0].empty?
user_query = parts[1]
res = get "/users/#{load_current_repo}/issues"

Expand All @@ -78,25 +75,23 @@ def search_all_issues(query)

# search all closed issues in github
def search_all_close_issues(query)
return [] if !query || query.length == 0
#raise InvalidToken unless test_authentication
return [] if !query || query.empty?

parts = query.split('/', 2)

if parts.length == 1 and parts[0].length > 0
res = get "/orgs/#{load_current_repo}/issues", { 'state' => 'closed' }
if parts.length == 1 && !parts[0].empty
res = get "/orgs/#{load_current_repo}/issues", 'state' => 'closed'

if res.is_a?(Hash) and res.has_key?('items')
if res.is_a?(Hash) && res.key?('items')
res['items'].map do |issue|
{ 'name' => "#{issue['title']}[closed]", 'url' => issue['html_url'] }
end
else
[]
end
elsif parts.length == 2 and parts[0].length > 0
user = parts[0]
elsif parts.length == 2 && !parts[0].empty?
user_query = parts[1]
res = get "/users/#{load_current_repo}/issues", { 'state' => 'closed' }
res = get "/users/#{load_current_repo}/issues", 'state' => 'closed'

if res.is_a?(Array)
repos = res.select do |repo|
Expand All @@ -105,7 +100,7 @@ def search_all_close_issues(query)
repos.map do |issue|
{ 'name' => "#{issue['title']}[closed]", 'url' => issue['html_url'] }
end
else˜
else
[]
end
else
Expand Down
5 changes: 3 additions & 2 deletions xml_builder.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class Item < Struct.new(:uid, :arg, :title, :subtitle, :valid, :icon); end

# alfred output
class XmlBuilder
attr_reader :output

def initialize
@output = '<?xml version="1.0"?>'"\n"
@output = '<?xml version="1.0"?>\n'
end

def self.build(&block)
Expand All @@ -14,7 +15,7 @@ def self.build(&block)
end

def items(&block)
@output << '<items>'"\n"
@output << '<items>\n'
yield(self)
@output << '</items>'
end
Expand Down

0 comments on commit c073d48

Please sign in to comment.