Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#333] refactor classes to be vcs independent #330

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 61 additions & 64 deletions 0pdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
require_relative 'objects/job_starred'
require_relative 'objects/job_commiterrors'
require_relative 'objects/log'
require_relative 'objects/github'
require_relative 'objects/clients/github'
require_relative 'objects/vcs/github'
require_relative 'objects/user_error'
require_relative 'objects/git_repo'
require_relative 'objects/github_invitations'
require_relative 'objects/github_tickets'
require_relative 'objects/github_tagged_tickets'
require_relative 'objects/tickets'
require_relative 'objects/tagged_tickets'
require_relative 'objects/emailed_tickets'
require_relative 'objects/logged_tickets'
require_relative 'objects/commit_tickets'
Expand All @@ -61,13 +62,22 @@
require_relative 'objects/s3'
require_relative 'objects/dynamo'

# # Delete later
require_relative 'test/fake_log'
require_relative 'test/fake_repo'
require_relative 'test/fake_github'
require_relative 'test/fake_storage'
require_relative 'test/fake_tickets'

ENV['RACK_ENV'] = 'test'

configure do
Haml::Options.defaults[:format] = :xhtml
config = if ENV['RACK_ENV'] == 'test'
{
'testing' => true,
'testing' => false,
'github' => {
'token' => '--the-token--',
'token' => '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',
'client_id' => '?',
'client_secret' => '?'
},
Expand Down Expand Up @@ -104,7 +114,7 @@
end
end
set :server_settings, timeout: 25
set :github, Github.new(config).client
set :github, GithubClient.new(config)
set :dynamo, Dynamo.new(config).aws
set :glogin, GLogin::Auth.new(
config['github']['client_id'],
Expand Down Expand Up @@ -223,6 +233,7 @@
get '/log-item' do
repo = repo_name(params[:repo])
tag = params[:tag]
vcs = params[:vcs]
error 404 if tag.nil?
log = Log.new(settings.dynamo, repo)
error 404 unless log.exists(tag)
Expand Down Expand Up @@ -308,65 +319,10 @@
end
name = repo_name(json['repository']['full_name'])
unless ENV['RACK_ENV'] == 'test'
repo = repo(name)
JobDetached.new(
repo,
JobCommitErrors.new(
name,
settings.github,
json['head_commit']['id'],
JobEmailed.new(
name,
settings.github,
repo,
JobRecorded.new(
name,
settings.github,
JobStarred.new(
name,
settings.github,
Job.new(
repo,
storage(name),
SentryTickets.new(
EmailedTickets.new(
name,
CommitTickets.new(
name,
repo,
settings.github,
json['head_commit']['id'],
GithubTaggedTickets.new(
name,
settings.github,
repo,
LoggedTickets.new(
Log.new(settings.dynamo, name),
name,
MilestoneTickets.new(
name,
repo,
settings.github,
GithubTickets.new(
name,
settings.github,
repo
)
)
)
)
)
)
)
)
)
)
)
)
).proceed
puts "GitHub hook from #{name}"
process_request(github)
puts "GitHub hook from #{github.repo.name}"
end
"Thanks #{name}"
"Thanks #{github.repo.name}"
end

get '/css/*.css' do
Expand Down Expand Up @@ -463,3 +419,44 @@ def storage(repo)
)
)
end

def process_request(vcs)
JobDetached.new(
vcs,
JobCommitErrors.new(
vcs,
JobEmailed.new(
vcs,
JobRecorded.new(
vcs,
JobStarred.new(
vcs,
Job.new(
vcs,
storage(vcs.repo.name),
SentryTickets.new(
EmailedTickets.new(
vcs,
CommitTickets.new(
vcs,
TaggedTickets.new(
vcs,
LoggedTickets.new(
vcs,
Log.new(settings.dynamo, vcs.repo.name),
MilestoneTickets.new(
vcs,
Tickets.new(vcs)
)
)
)
)
)
)
)
)
)
)
)
).proceed
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem 'aws-sdk-dynamodb', '1.59.0'
gem 'aws-sdk-s3', '1.90.0'
gem 'codecov', '0.5.1'
gem 'glogin', '0.7.0'
gem 'gitlab', '4.18.0'
gem 'haml', '5.2.1'
gem 'mail', '2.7.1'
gem 'mocha', '1.11.2', require: false
Expand Down
55 changes: 36 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,80 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.537.0)
aws-sdk-core (3.124.0)
aws-partitions (1.579.0)
aws-sdk-core (3.130.2)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-dynamodb (1.59.0)
aws-sdk-core (~> 3, >= 3.112.0)
aws-sigv4 (~> 1.1)
aws-sdk-kms (1.52.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sdk-kms (1.56.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.90.0)
aws-sdk-core (~> 3, >= 3.112.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.4.0)
aws-sigv4 (1.5.0)
aws-eventstream (~> 1, >= 1.0.2)
base58 (0.2.3)
codecov (0.5.1)
simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.1.9)
concurrent-ruby (1.1.10)
differ (0.1.2)
docile (1.4.0)
faraday (1.8.0)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
ffi (1.15.4)
faraday-retry (1.0.3)
ffi (1.15.5)
gitlab (4.18.0)
httparty (~> 0.18)
terminal-table (>= 1.5.1)
glogin (0.7.0)
base58 (= 0.2.3)
haml (5.2.1)
temple (>= 0.8.0)
tilt
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
jmespath (1.4.0)
jmespath (1.6.1)
mail (2.7.1)
mini_mime (>= 0.1.1)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
mocha (1.11.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
Expand All @@ -82,24 +96,24 @@ GEM
octokit (4.20.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.21.0)
parser (3.0.3.1)
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
pdd (0.20.6)
nokogiri (~> 1.10)
rainbow (~> 3.0)
slop (~> 4.6)
power_assert (2.0.1)
public_suffix (4.0.6)
public_suffix (4.0.7)
racc (1.6.0)
rack (2.2.3)
rack-protection (2.1.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rainbow (3.0.0)
rainbow (3.1.1)
rake (13.0.3)
rb-fsevent (0.11.0)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
rubocop (0.69.0)
Expand Down Expand Up @@ -129,7 +143,7 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
simplecov_json_formatter (0.1.4)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -141,11 +155,13 @@ GEM
rack-protection (= 2.1.0)
sinatra (= 2.1.0)
tilt (~> 2.0)
slop (4.9.1)
slop (4.9.2)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
temple (0.8.2)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
test-unit (3.4.0)
power_assert
tilt (2.0.10)
Expand All @@ -168,6 +184,7 @@ DEPENDENCIES
aws-sdk-dynamodb (= 1.59.0)
aws-sdk-s3 (= 1.90.0)
codecov (= 0.5.1)
gitlab (= 4.18.0)
glogin (= 0.7.0)
haml (= 5.2.1)
mail (= 2.7.1)
Expand Down
46 changes: 23 additions & 23 deletions objects/github.rb → objects/clients/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@
# Github client
# API: http://octokit.github.io/octokit.rb/method_list.html
#
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']
Octokit.connection_options = {
request: {
timeout: 20,
open_timeout: 20
class GithubClient
def self.new(config = {})
begin
client = if config['testing']
require_relative '../../test/fake_github'
FakeGithub.new
else
args = {}
args[:access_token] = config['github']['token'] if config['github']
Octokit.connection_options = {
request: {
timeout: 20,
open_timeout: 20
}
}
}
Octokit.auto_paginate = true
Octokit::Client.new(args)
Octokit.auto_paginate = true
Octokit::Client.new(args)
end
TracePoint.new(:call) do |tp|
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
TracePoint.new(:call) do |tp|
puts "#{tp.defined_class}##{tp.method_id}()" if tp.defined_class == client.class
end.enable
client
end
end
Loading