Skip to content

Commit

Permalink
Restore fetch changesets functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Dec 6, 2024
1 parent 0b31ada commit ff7e05e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/controllers/sys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ def repo_auth
end
end

def fetch_changesets
projects = []
if params[:id]
projects << Project.active.has_module(:repository).find_by!(identifier: params[:id])
else
projects = Project.active.has_module(:repository)
.includes(:repository).references(:repositories)
end
projects.each do |project|
if project.repository
project.repository.fetch_changesets
end

Check notice on line 57 in app/controllers/sys_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/controllers/sys_controller.rb#L55-L57 <Style/SafeNavigation>

Use safe navigation (`&.`) instead of checking if an object exists before calling the method.
Raw output
app/controllers/sys_controller.rb:55:7: C: Style/SafeNavigation: Use safe navigation (`&.`) instead of checking if an object exists before calling the method.
end
head :ok
rescue ActiveRecord::RecordNotFound
head :not_found
end

Check notice on line 62 in app/controllers/sys_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/controllers/sys_controller.rb#L46-L62 <Metrics/AbcSize>

Assignment Branch Condition size for fetch_changesets is too high. [<3, 18, 5> 18.92/17]
Raw output
app/controllers/sys_controller.rb:46:3: C: Metrics/AbcSize: Assignment Branch Condition size for fetch_changesets is too high. [<3, 18, 5> 18.92/17]

private

def authorized?(project, user)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@

scope controller: "sys" do
match "/sys/repo_auth", action: "repo_auth", via: %i[get post]
get "/sys/fetch_changesets", action: "fetch_changesets"
match "/sys/projects", to: proc { [410, {}, [""]] }, via: :all
match "/sys/fetch_changesets", to: proc { [410, {}, [""]] }, via: :all
match "/sys/projects/:id/repository/update_storage", to: proc { [410, {}, [""]] }, via: :all
end

Expand Down
48 changes: 48 additions & 0 deletions spec/controllers/sys_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,52 @@
end
end
end

describe "#fetch_changesets" do
let(:params) { { id: repository_project.identifier } }

before do
request.env["HTTP_AUTHORIZATION"] =
ActionController::HttpAuthentication::Basic.encode_credentials(
valid_user.login,
valid_user_password
)

allow_any_instance_of(Repository::Subversion).to receive(:fetch_changesets).and_return(true)

Check notice on line 507 in spec/controllers/sys_controller_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/controllers/sys_controller_spec.rb#L507 <RSpec/AnyInstance>

Avoid stubbing using `allow_any_instance_of`.
Raw output
spec/controllers/sys_controller_spec.rb:507:7: C: RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.

get "fetch_changesets", params: params.merge({ key: api_key })
end

context "with a project identifier" do
it "is successful" do
expect(response)
.to have_http_status(:ok)
end
end

context "without a project identifier" do
let(:params) { {} }

it "is successful" do
expect(response)
.to have_http_status(:ok)
end
end

context "for an unknown project" do
let(:params) { { id: 0 } }

it "returns 404" do
expect(response)
.to have_http_status(:not_found)
end
end

context "when disabled", with_settings: { sys_api_enabled?: false } do
it "is 403 forbidden" do
expect(response)
.to have_http_status(:forbidden)
end
end
end
end

0 comments on commit ff7e05e

Please sign in to comment.