Skip to content

Commit

Permalink
[yegor256#312] resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mbao01 authored and Doldrums committed Apr 15, 2022
1 parent 7a4b20b commit a414872
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 331 deletions.
4 changes: 2 additions & 2 deletions 0pdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
raise "Invalid content-type: \"#{request.content_type}\""
end
)
github = GithubHelper.new(settings.github, json, settings.config)
github = GithubRepo.new(settings.github, json, settings.config)
return 'Thanks' unless github.is_valid
unless ENV['RACK_ENV'] == 'test'
process_request(github)
Expand Down Expand Up @@ -368,7 +368,7 @@
raise "Invalid content-type: \"#{request.content_type}\""
end
)
gitlab = GitlabHelper.new(settings.gitlab, json, settings.config)
gitlab = GitlabRepo.new(settings.gitlab, json, settings.config)
return 'Thanks' unless gitlab.is_valid
unless ENV['RACK_ENV'] == 'test'
process_request(gitlab)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end
desc 'Sleep endlessly after the start of DynamoDB Local server'
task :sleep do
loop do
sleep(3600)
sleep(5)
puts 'Still alive...'
end
end
Expand Down
6 changes: 3 additions & 3 deletions dynamodb-local/tables/0pdd-events.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"TableName": "0pdd-events",
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeName": "repo",
"AttributeType": "S"
},
{
Expand All @@ -16,7 +16,7 @@
],
"KeySchema": [
{
"AttributeName": "id",
"AttributeName": "repo",
"KeyType": "HASH"
},
{
Expand All @@ -33,7 +33,7 @@
"IndexName": "tags",
"KeySchema": [
{
"AttributeName": "id",
"AttributeName": "repo",
"KeyType": "HASH"
},
{
Expand Down
2 changes: 1 addition & 1 deletion objects/clients/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.new(config = {})
begin
client = if config['testing']
require_relative '../../test/fake_gitlab'
FakeGitlab.new # TODO:: implement fake gitlab
FakeGitlab.new
else
token = config['gitlab']['token'] if config['gitlab']
Gitlab.client(
Expand Down
20 changes: 9 additions & 11 deletions objects/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def initialize(dynamo, repo, vcs_name = 'github')
@dynamo = dynamo
@repo = repo
@vcs_name = (vcs_name || 'github').downcase
# TODO: Must perform seamless migration of existing DB
@id = Base64.encode64(@repo + @vcs_name).gsub(/[\s=\/]+/, '')
@id = @vcs_name == 'github' ? @repo : Base64.encode64(@repo + @vcs_name).gsub(/[\s=\/]+/, '')

raise 'You need to specify your cloud VCS' unless [
'gitlab',
Expand All @@ -45,9 +44,8 @@ def put(tag, text)
@dynamo.put_item(
table_name: '0pdd-events',
item: {
'id' => @id,
'repo' => @id,
'vcs' => @vcs_name,
'repo' => @repo,
'time' => Time.now.to_i,
'tag' => tag,
'text' => "#{text} /#{VERSION}"
Expand All @@ -62,10 +60,10 @@ def get(tag)
select: 'ALL_ATTRIBUTES',
limit: 1,
expression_attribute_values: {
':i' => @id,
':r' => @id,
':t' => tag
},
key_condition_expression: 'id=:i and tag=:t'
key_condition_expression: 'repo=:r and tag=:t'
).items[0]
end

Expand All @@ -76,18 +74,18 @@ def exists(tag)
select: 'ALL_ATTRIBUTES',
limit: 1,
expression_attribute_values: {
':i' => @id,
':r' => @id,
':t' => tag
},
key_condition_expression: 'id=:i and tag=:t'
key_condition_expression: 'repo=:r and tag=:t'
).items.empty?
end

def delete(time, tag)
@dynamo.delete_item(
table_name: '0pdd-events',
key: {
'id' => @id,
'repo' => @id,
'time' => time
},
expression_attribute_values: {
Expand All @@ -107,10 +105,10 @@ def list(since = Time.now.to_i)
'#time' => 'time'
},
expression_attribute_values: {
':i' => @id,
':r' => @id,
':t' => since
},
key_condition_expression: 'id=:i and #time<:t'
key_condition_expression: 'repo=:r and #time<:t'
)
end
end
57 changes: 24 additions & 33 deletions objects/puzzles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,35 @@ def group(xml)
end

def expose(xml, tickets)
exceptions = [] # TODO: Send exceptions to the user's email or admin
seen = []
Kernel.loop do
begin
puzzles = xml.xpath(
'//puzzle[@alive="false" and issue
and issue != "unknown" and not(issue/@closed)' +
seen.map { |i| "and id != '#{i}'" }.join(' ') + ']'
)
break if puzzles.empty?
puzzle = puzzles[0]
puzzle.search('issue')[0]['closed'] = Time.now.iso8601 if tickets.close(puzzle)
save(xml)
rescue Exception => e
exceptions << e
end
puzzles = xml.xpath(
'//puzzle[@alive="false" and issue
and issue != "unknown" and not(issue/@closed)' +
seen.map { |i| "and id != '#{i}'" }.join(' ') + ']'
)
break if puzzles.empty?
puzzle = puzzles[0]
puzzle.search('issue')[0]['closed'] = Time.now.iso8601 if tickets.close(puzzle)
save(xml)
end
seen = []
Kernel.loop do
begin
puzzles = xml.xpath(
'//puzzle[@alive="true" and (not(issue) or issue="unknown")' +
seen.map { |i| "and id != '#{i}'" }.join(' ') + ']'
)
break if puzzles.empty?
puzzle = puzzles[0]
id = puzzle.xpath('id')[0].text
seen << id
issue = tickets.submit(puzzle)
next if issue.nil?
puzzle.search('issue').remove
puzzle.add_child(
"<issue href='#{issue[:href]}'>#{issue[:number]}</issue>"
)
save(xml)
rescue Exception => e
exceptions << e
end
puzzles = xml.xpath(
'//puzzle[@alive="true" and (not(issue) or issue="unknown")' +
seen.map { |i| "and id != '#{i}'" }.join(' ') + ']'
)
break if puzzles.empty?
puzzle = puzzles[0]
id = puzzle.xpath('id')[0].text
seen << id
issue = tickets.submit(puzzle)
next if issue.nil?
puzzle.search('issue').remove
puzzle.add_child(
"<issue href='#{issue[:href]}'>#{issue[:number]}</issue>"
)
save(xml)
end
end
end
4 changes: 2 additions & 2 deletions objects/vcs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# SOFTWARE.

#
# VCS - provides a uniform interface to work with different VCSes
# AbstractVCS - provides a uniform interface to work with different VCSes
#
module VCS
class AbstractVCS
attr_reader :is_valid, :repo, :name

def initialize(client, json, config = {})
Expand Down
5 changes: 2 additions & 3 deletions objects/vcs/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
require_relative '../clients/gitlab'

#
# Github helper
# Github repo
# API: https://github.com/NARKOZ/gitlab
#
class GithubHelper
include VCS # important to include this module
class GithubRepo < AbstractVCS
attr_reader :is_valid, :repo, :name

def initialize(client, json, config = {})
Expand Down
5 changes: 2 additions & 3 deletions objects/vcs/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
require_relative '../clients/gitlab'

#
# Gitlab client
# Gitlab repo
# API: https://github.com/NARKOZ/gitlab
#
class GitlabHelper
include VCS
class GitlabRepo < AbstractVCS
attr_reader :is_valid, :repo, :name

def initialize(client, json, config = {})
Expand Down
Loading

0 comments on commit a414872

Please sign in to comment.