Skip to content

Comments

Include role in owners api response#5821

Open
jakebills1 wants to merge 8 commits intorubygems:masterfrom
jakebills1:include-role-in-owners-api-response
Open

Include role in owners api response#5821
jakebills1 wants to merge 8 commits intorubygems:masterfrom
jakebills1:include-role-in-owners-api-response

Conversation

@jakebills1
Copy link

Addresses #5816 by including the role of each member of a gem in the response to /api/v1/gems/:gem_id/owners.json

Note: There could be a better solution to this, but I found it difficult to work around the User#payload method. It looks like using serializers was discussed in the past but rejected. #1027 (comment) As this is my first PR here, I am absolutely open to feedback or better approaches.

@simi
Copy link
Contributor

simi commented Jul 19, 2025

Hello, you're right there is no pattern established to compose payload so it is in-lined usually.

def render_rubygems(versions)
rubygems = versions.includes(:dependencies, :gem_download, rubygem: %i[linkset gem_download]).map do |version|
version.rubygem.payload(version)
end

def checksums_payload(checksums_file)
ShasumFormat.parse(checksums_file).transform_values do |checksum|
{ VersionManifest::DEFAULT_DIGEST => checksum }
end
end

@codecov
Copy link

codecov bot commented Jul 19, 2025

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.03%. Comparing base (652a258) to head (1c70b9e).

Files with missing lines Patch % Lines
app/controllers/api/v1/owners_controller.rb 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5821      +/-   ##
==========================================
- Coverage   38.67%   38.03%   -0.64%     
==========================================
  Files         486      486              
  Lines       10698    10760      +62     
==========================================
- Hits         4137     4093      -44     
- Misses       6561     6667     +106     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

rescue_from ActiveRecord::RecordNotFound, with: :render_not_found

def show
payload = @rubygem.owners.map { |owner| owner.payload.merge("role" => owner.ownerships.find_by(rubygem: @rubygem).role) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to make this more SQL effective. Now it seems to trigger additional query per each owner.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @simi
I believe my latest commit reduces it back down to one query

@gjtorikian
Copy link
Contributor

Is the codecov decrease a blocker for this? I was looking into solving ruby/rubygems#9267 which this PR depends on.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the v1 owners endpoint to include each gem member’s ownership role in the /api/v1/gems/:gem_id/owners.(json|yaml) response, addressing #5816.

Changes:

  • Modify Api::V1::OwnersController#show to render a custom owners payload including role.
  • Add an owners_payload helper to assemble the response data.
  • Add a functional test asserting role is present in the JSON response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
app/controllers/api/v1/owners_controller.rb Switches owners response rendering to a custom payload that includes role.
test/functional/api/v1/owners_controller_test.rb Adds a JSON test asserting returned owner fields now include role.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +102 to +115
context "GET /api/v1/gems/:gem/owners.json" do
setup do
@user = create(:user, public_email: true)
@rubygem = create(:rubygem, owners: [@user])
get :show, params: { rubygem_id: @rubygem.slug }, format: :json
@user_payload = JSON.parse(@response.body).first
end
should "include associated users id, handle, email, and role in response" do
assert_equal "owner", @user_payload["role"]
assert_equal @user.id, @user_payload["id"]
assert_equal @user.handle, @user_payload["handle"]
assert_equal @user.email, @user_payload["email"]
end
end
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test only asserts the default "owner" role in the JSON response. Since this PR changes the API contract to include roles, it should also cover at least one non-default role (e.g., a maintainer) and ideally exercise the YAML format too, so regressions in role selection/serialization are caught.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants