Skip to content

Commit

Permalink
[#312] sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
mbao01 committed May 27, 2022
2 parents 08fc5ba + a0d77a9 commit 5189973
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 268 deletions.
6 changes: 3 additions & 3 deletions 0pdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
end
end
set :server_settings, timeout: 25
set :github, GithubClient.new(config)
set :github, Github.new(config).client
set :dynamo, Dynamo.new(config).aws
set :glogin, GLogin::Auth.new(
config['github']['client_id'],
Expand Down Expand Up @@ -229,8 +229,8 @@
xml = repo.xml
xml.xpath('//processing-instruction("xml-stylesheet")').remove
xml.to_s
rescue StandardError
error 400, "Could not get snapshot for #{name}"
rescue Exec::Error => e
error 400, "Could not get snapshot for #{name}: #{e.message}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem 'glogin', '0.7.0'
gem 'haml', '5.2.1'
gem 'mail', '2.7.1'
gem 'mocha', '1.11.2', require: false
gem 'nokogiri', '1.13.4'
gem 'nokogiri', '1.13.6'
gem 'octokit', '4.20.0'
gem 'pdd', '0.20.6'
gem 'rack', '2.2.3'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ GEM
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.13.4)
nokogiri (1.13.6)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.13.4-x86_64-darwin)
nokogiri (1.13.6-x86_64-darwin)
racc (~> 1.4)
octokit (4.20.0)
faraday (>= 0.9)
Expand Down Expand Up @@ -172,7 +172,7 @@ DEPENDENCIES
haml (= 5.2.1)
mail (= 2.7.1)
mocha (= 1.11.2)
nokogiri (= 1.13.4)
nokogiri (= 1.13.6)
octokit (= 4.20.0)
pdd (= 0.20.6)
rack (= 2.2.3)
Expand Down
14 changes: 8 additions & 6 deletions objects/clients/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
# Github client
# API: http://octokit.github.io/octokit.rb/method_list.html
#
class GithubClient
def self.new(config = {})
client = if config['testing']
class Github
def initialize(config = {})
@config = config
end

def client
client = if @config['testing']
require_relative '../../test/fake_github'
FakeGithub.new
else
args = {}
args[:access_token] = config['github']['token'] if config['github']
args[:access_token] = @config['github']['token'] if @config['github']
Octokit.connection_options = {
request: {
timeout: 20,
Expand All @@ -45,7 +49,5 @@ def self.new(config = {})
puts "#{tp.defined_class}##{tp.method_id}()" if tp.defined_class == client.class
end.enable
client
rescue Octokit::NotFound
puts 'Issue with account not found'
end
end
11 changes: 5 additions & 6 deletions objects/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ class Log
def initialize(dynamo, repo)
@dynamo = dynamo
@repo = repo
@id = Base64.encode64(@repo).gsub(%r{[\s=\/]+}, '')
end

def put(tag, text)
@dynamo.put_item(
table_name: '0pdd-events',
item: {
'repo' => @id,
'repo' => @repo,
'time' => Time.now.to_i,
'tag' => tag,
'text' => "#{text} /#{VERSION}"
Expand All @@ -53,7 +52,7 @@ def get(tag)
select: 'ALL_ATTRIBUTES',
limit: 1,
expression_attribute_values: {
':r' => @id,
':r' => @repo,
':t' => tag
},
key_condition_expression: 'repo=:r and tag=:t'
Expand All @@ -67,7 +66,7 @@ def exists(tag)
select: 'ALL_ATTRIBUTES',
limit: 1,
expression_attribute_values: {
':r' => @id,
':r' => @repo,
':t' => tag
},
key_condition_expression: 'repo=:r and tag=:t'
Expand All @@ -78,7 +77,7 @@ def delete(time, tag)
@dynamo.delete_item(
table_name: '0pdd-events',
key: {
'repo' => @id,
'repo' => @repo,
'time' => time
},
expression_attribute_values: {
Expand All @@ -98,7 +97,7 @@ def list(since = Time.now.to_i)
'#time' => 'time'
},
expression_attribute_values: {
':r' => @id,
':r' => @repo,
':t' => since
},
key_condition_expression: 'repo=:r and #time<:t'
Expand Down
2 changes: 1 addition & 1 deletion objects/tickets/milestone_tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def submit(puzzle)
`#{parent[:milestone][:title]}` from issue ##{num}."
)
end
rescue StandardError => e
rescue Octokit::Error => e
@vcs.add_comment(
submitted[:number],
"For some reason I wasn't able to set milestone \
Expand Down
4 changes: 2 additions & 2 deletions objects/tickets/tagged_tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def submit(puzzle)
begin
needed.each { |t| @vcs.add_label(t, 'F74219') }
@vcs.add_labels_to_an_issue(issue_id, tags)
rescue StandardError => e
rescue Octokit::Error => e
@vcs.add_comment(
issue_id,
"I can't create #{@vcs.name} labels `#{needed.join('`, `')}`. \
Expand All @@ -53,7 +53,7 @@ def submit(puzzle)
[list of collaborators](#{@vcs.collaborators_link}):\
\n\n```#{e.class.name}\n#{e.message}\n#{e.backtrace.join("\n")}\n```"
)
rescue StandardError => e
rescue Octokit::NotFound => e
@vcs.add_comment(
issue_id,
"For some reason I wasn't able to add #{@vcs.name} labels \
Expand Down
2 changes: 2 additions & 0 deletions objects/tickets/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def notify(issue, message)
issue,
"@#{@vcs.issue(issue)[:author][:username]} #{message}"
)
rescue Octokit::NotFound => e
puts "The issue most probably is not found, can't comment: #{e.message}"
end

def submit(puzzle)
Expand Down
Loading

0 comments on commit 5189973

Please sign in to comment.