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

Incorrect Organizations path when using an org ID vs org name in 'update_organization_membership' #1249

Closed
tjl2 opened this issue Apr 30, 2020 · 0 comments · Fixed by #1255
Closed
Labels
Type: Bug Something isn't working as documented

Comments

@tjl2
Copy link

tjl2 commented Apr 30, 2020

It looks like the path being used in line 704 of the update_organization_membership method is hardcoded, instead of using Organization.path:

def update_organization_membership(org, options = {})
options = options.dup
if user = options.delete(:user)
options.delete(:state)
put "orgs/#{org}/memberships/#{user}", options
else
options.delete(:role)
patch "user/memberships/orgs/#{org}", options
end
end

I found that this was giving me 404 errors when trying to use this method with an org ID against a GHES server:

[6] pry(main)> c.update_org_membership(12, user: 'some-user')              
Octokit::NotFound: PUT https://[MY-GHES-SERVER]/api/v3/orgs/12/memberships/some-user: 404 - Not Found // See: https://developer.github.com/enterprise/2.20/v3/orgs/members/#add-or-update-organization-membership
from /Users/tim/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/octokit-4.8.0/lib/octokit/response/raise_error.rb:16:in `on_complete'

I've worked around this by ensuring I use the org's name when I use the method instead of the ID, but I believe the method should be rewritten as follows, so that it can accept both (as it is in organization_membership, for example):

def update_organization_membership(org, options = {})
  if user = options.delete(:user)
    put "#{Orgnaization.path}/memberships/#{user}", options
  else
    patch "user/memberships/orgs/#{org}", options
  end
end
@tarebyte tarebyte added the bug label Apr 30, 2020
@nickfloyd nickfloyd added Type: Bug Something isn't working as documented and removed bug labels Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants