Skip to content

Commit

Permalink
Merge pull request #255 from sensu/issue_254
Browse files Browse the repository at this point in the history
Add URL for parent assets not on Bonsai
  • Loading branch information
pzupan authored Dec 20, 2019
2 parents b9640ff + 46aa0c5 commit 1e997fb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get install -y nodejs apt-transport-https

RUN apt-get install -y xvfb nano build-essential libpq-dev wget postgresql-9.6 postgresql-client postgresql-contrib
RUN apt-get install -y xvfb nano build-essential libpq-dev wget postgresql-client postgresql-contrib

RUN rm -rf /var/lib/apt/lists/*

Expand Down
2 changes: 1 addition & 1 deletion app/views/extensions/_extension.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<% if parent_extension.present? %>
<%= link_to "#{extension.parent_owner_name}/#{extension.parent_name}", owner_scoped_extension_url(parent_extension) %>
<% else %>
<span><%= extension.parent_owner_name %>/<%= extension.parent_name %></span>
<span><%= link_to extension.parent_html_url, extension.parent_html_url, target: '_blank' %> (it does not yet have a Bonsai asset).</span>
<% end %>
</span>

Expand Down
1 change: 1 addition & 0 deletions app/views/extensions/_main_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<%= link_to "#{extension.parent_owner_name}/#{extension.parent_name}", owner_scoped_extension_url(parent_extension) %>
<% else %>
<span><%= extension.parent_owner_name %>/<%= extension.parent_name %></span>
<p>This asset is forked from an upstream project at <%= link_to extension.parent_html_url, extension.parent_html_url, target: '_blank' %> but does not yet have a Bonsai asset. Please contact <%= extension.parent_owner_name %> and see if they need help getting assets listed here</p>
<% end %>
</p>
<% end %>
Expand Down
17 changes: 10 additions & 7 deletions app/workers/extract_extension_parent_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ def perform(extension_id)
if repo_parent.present?
parent_name = repo_parent[:name]
parent_owner_name = repo_parent[:owner][:login]
parent_html_url = repo_parent[:html_url]

@extension.update(
parent_name: parent_name,
parent_owner_name: parent_owner_name,
parent_html_url: parent_html_url
)

parent = Extension.find_by(owner_name: parent_owner_name, lowercase_name: parent_name)
if parent.present?
@extension.update_attributes(
parent: parent,
parent_name: parent_name,
parent_owner_name: parent_owner_name
)
end
@extension.update(parent: parent) if parent.present?

end

end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20191211193119_add_parent_html_url_to_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddParentHtmlUrlToExtension < ActiveRecord::Migration[5.2]
def change
add_column :extensions, :parent_html_url, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_10_23_155343) do
ActiveRecord::Schema.define(version: 2019_12_11_193119) do

# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -364,6 +364,7 @@
t.string "parent_name"
t.string "parent_owner_name"
t.string "compilation_error"
t.string "parent_html_url"
t.index ["enabled"], name: "index_extensions_on_enabled"
t.index ["github_organization_id"], name: "index_extensions_on_github_organization_id"
t.index ["name"], name: "index_extensions_on_name"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
ports:
- 5433:5432
volumes:
- 'postgres:/var/lib/postgresql/data'
- postgres:/var/lib/postgresql/data
redis:
image: redis
ports:
Expand Down
49 changes: 31 additions & 18 deletions spec/workers/extract_extension_parent_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,48 @@

let(:parent_name ) {"sensu-plugins-http"}
let(:parent_owner_name) {"sensu-plugins"}
let(:parent_html_url) {"https://github.com/sensu-plugins/sensu-plugins-http"}

let(:parent_extension) { create :extension }

let(:name) {"sensu-plugins-http"}
let(:owner_name) {"jspaleta"}

let(:extension) { create :extension }
let(:extension) { create :extension, name: name, lowercase_name: name, owner_name: owner_name }

subject { ExtractExtensionParentWorker.new }

before do
allow(subject).to receive_message_chain(:octokit, :repo).and_return(repo_json)
# factory seems to override lowercase_name
parent_extension.update(
name: parent_name,
lowercase_name: parent_name,
owner_name: parent_owner_name
)
extension.update(
name: name,
lowercase_name: name,
owner_name: owner_name
)
end

it "updates the extension with the parent if one is present" do
subject.perform( extension.id )
extension.reload
expect( extension.parent_id ).to eq( parent_extension.id )
expect( extension.parent_name ).to eq( parent_name )
expect( extension.parent_owner_name ).to eq( parent_owner_name )
describe 'no parent present on local' do

it "updates the extension with the parent info if present in repo" do
subject.perform( extension.id )
extension.reload
expect( extension.parent_id ).to eq( nil )
expect( extension.parent_name ).to eq( parent_name )
expect( extension.parent_owner_name ).to eq( parent_owner_name )
expect( extension.parent_html_url).to eq( parent_html_url )
end

end

describe 'parent present on local ' do
before do
parent_extension.update(
name: parent_name,
lowercase_name: parent_name,
owner_name: parent_owner_name
)
end

it "updates the extension with the parent if one is present" do
subject.perform( extension.id )
extension.reload
expect( extension.parent_id ).to eq( parent_extension.id )
end
end

end
Expand Down Expand Up @@ -66,6 +77,8 @@ def repo_json
"id": 10713628,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjEwNzEzNjI4",
},
"html_url": "https://github.com/sensu-plugins/sensu-plugins-http",
},

}
end

0 comments on commit 1e997fb

Please sign in to comment.