Skip to content

Commit

Permalink
Adds List organization memberships for the authenticated user (#3040)
Browse files Browse the repository at this point in the history
This endpoint described in [the
docs](https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-organization-memberships-for-the-authenticated-user)
was missing. This adds it as a method in the AuthenticatedUser class
which returns a list of Memeberships.
  • Loading branch information
eduramirezh authored Oct 27, 2024
1 parent 612ba68 commit cf44395
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions github/AuthenticatedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,17 @@ def get_migrations(self) -> PaginatedList[Migration]:
headers={"Accept": Consts.mediaTypeMigrationPreview},
)

def get_organization_memberships(self) -> PaginatedList[Membership]:
"""
:calls: `GET /user/memberships/orgs/ <https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user>`_
"""
return PaginatedList(
github.Membership.Membership,
self._requester,
"/user/memberships/orgs",
None,
)

def get_organization_membership(self, org: str) -> Membership:
"""
:calls: `GET /user/memberships/orgs/{org} <https://docs.github.com/en/rest/reference/orgs#get-an-organization-membership-for-the-authenticated-user>`_
Expand Down
11 changes: 11 additions & 0 deletions tests/AuthenticatedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,14 @@ def testInstallations(self):
self.assertEqual(installations[0].target_id, 3344556)
self.assertEqual(installations[0].target_type, "User")
self.assertEqual(installations.totalCount, 1)

def testGetMemberships(self):
membership_data = self.user.get_organization_memberships()
self.assertListKeyEqual(
membership_data,
lambda e: e.organization.login,
["aneyem-github", "nko4", "geoservel", "iic2154-uc-cl", "nnodes", "sushiclm"],
)
self.assertListKeyEqual(
membership_data, lambda e: e.role, ["member", "member", "admin", "member", "member", "admin"]
)
10 changes: 10 additions & 0 deletions tests/ReplayData/AuthenticatedUser.testGetMemberships.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
https
GET
api.github.com
None
/user/memberships/orgs
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('Date', 'Mon, 09 Sep 2024 14:56:03 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"64a96e0eaa998b8a898ced522b64494c065bb32b4c0768d689b9b98b2fa849c1"'), ('X-OAuth-Scopes', 'gist, read:org, repo, workflow'), ('X-Accepted-OAuth-Scopes', 'admin:org, read:org, repo, user, write:org'), ('x-oauth-client-id', '178c6fc778ccc68e1d6a'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('x-github-api-version-selected', '2022-11-28'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4977'), ('X-RateLimit-Reset', '1725895359'), ('X-RateLimit-Used', '23'), ('X-RateLimit-Resource', 'core'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked'), ('Server', 'github.com'), ('X-GitHub-Request-Id', '2721:3E994B:103429F2:106C9200:66DF0C83')]
[{"url":"https://api.github.com/orgs/aneyem-github/memberships/eduramirezh","state":"active","role":"member","organization_url":"https://api.github.com/orgs/aneyem-github","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"aneyem-github","id":1649871,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2NDk4NzE=","url":"https://api.github.com/orgs/aneyem-github","repos_url":"https://api.github.com/orgs/aneyem-github/repos","events_url":"https://api.github.com/orgs/aneyem-github/events","hooks_url":"https://api.github.com/orgs/aneyem-github/hooks","issues_url":"https://api.github.com/orgs/aneyem-github/issues","members_url":"https://api.github.com/orgs/aneyem-github/members{/member}","public_members_url":"https://api.github.com/orgs/aneyem-github/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/1649871?v=4","description":null}},{"url":"https://api.github.com/orgs/nko4/memberships/eduramirezh","state":"active","role":"member","organization_url":"https://api.github.com/orgs/nko4","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"nko4","id":3877928,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM4Nzc5Mjg=","url":"https://api.github.com/orgs/nko4","repos_url":"https://api.github.com/orgs/nko4/repos","events_url":"https://api.github.com/orgs/nko4/events","hooks_url":"https://api.github.com/orgs/nko4/hooks","issues_url":"https://api.github.com/orgs/nko4/issues","members_url":"https://api.github.com/orgs/nko4/members{/member}","public_members_url":"https://api.github.com/orgs/nko4/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/3877928?v=4","description":null}},{"url":"https://api.github.com/orgs/geoservel/memberships/eduramirezh","state":"active","role":"admin","organization_url":"https://api.github.com/orgs/geoservel","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"geoservel","id":6774673,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NzQ2NzM=","url":"https://api.github.com/orgs/geoservel","repos_url":"https://api.github.com/orgs/geoservel/repos","events_url":"https://api.github.com/orgs/geoservel/events","hooks_url":"https://api.github.com/orgs/geoservel/hooks","issues_url":"https://api.github.com/orgs/geoservel/issues","members_url":"https://api.github.com/orgs/geoservel/members{/member}","public_members_url":"https://api.github.com/orgs/geoservel/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/6774673?v=4","description":null}},{"url":"https://api.github.com/orgs/iic2154-uc-cl/memberships/eduramirezh","state":"active","role":"member","organization_url":"https://api.github.com/orgs/iic2154-uc-cl","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"iic2154-uc-cl","id":7002324,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwMDIzMjQ=","url":"https://api.github.com/orgs/iic2154-uc-cl","repos_url":"https://api.github.com/orgs/iic2154-uc-cl/repos","events_url":"https://api.github.com/orgs/iic2154-uc-cl/events","hooks_url":"https://api.github.com/orgs/iic2154-uc-cl/hooks","issues_url":"https://api.github.com/orgs/iic2154-uc-cl/issues","members_url":"https://api.github.com/orgs/iic2154-uc-cl/members{/member}","public_members_url":"https://api.github.com/orgs/iic2154-uc-cl/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/7002324?v=4","description":""}},{"url":"https://api.github.com/orgs/nnodes/memberships/eduramirezh","state":"active","role":"member","organization_url":"https://api.github.com/orgs/nnodes","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"nnodes","id":12845538,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyODQ1NTM4","url":"https://api.github.com/orgs/nnodes","repos_url":"https://api.github.com/orgs/nnodes/repos","events_url":"https://api.github.com/orgs/nnodes/events","hooks_url":"https://api.github.com/orgs/nnodes/hooks","issues_url":"https://api.github.com/orgs/nnodes/issues","members_url":"https://api.github.com/orgs/nnodes/members{/member}","public_members_url":"https://api.github.com/orgs/nnodes/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/12845538?v=4","description":""}},{"url":"https://api.github.com/orgs/sushiclm/memberships/eduramirezh","state":"active","role":"admin","organization_url":"https://api.github.com/orgs/sushiclm","user":{"login":"eduramirezh","id":1679647,"node_id":"MDQ6VXNlcjE2Nzk2NDc=","avatar_url":"https://avatars.githubusercontent.com/u/1679647?v=4","gravatar_id":"","url":"https://api.github.com/users/eduramirezh","html_url":"https://github.com/eduramirezh","followers_url":"https://api.github.com/users/eduramirezh/followers","following_url":"https://api.github.com/users/eduramirezh/following{/other_user}","gists_url":"https://api.github.com/users/eduramirezh/gists{/gist_id}","starred_url":"https://api.github.com/users/eduramirezh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduramirezh/subscriptions","organizations_url":"https://api.github.com/users/eduramirezh/orgs","repos_url":"https://api.github.com/users/eduramirezh/repos","events_url":"https://api.github.com/users/eduramirezh/events{/privacy}","received_events_url":"https://api.github.com/users/eduramirezh/received_events","type":"User","site_admin":false},"organization":{"login":"sushiclm","id":22522358,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyNTIyMzU4","url":"https://api.github.com/orgs/sushiclm","repos_url":"https://api.github.com/orgs/sushiclm/repos","events_url":"https://api.github.com/orgs/sushiclm/events","hooks_url":"https://api.github.com/orgs/sushiclm/hooks","issues_url":"https://api.github.com/orgs/sushiclm/issues","members_url":"https://api.github.com/orgs/sushiclm/members{/member}","public_members_url":"https://api.github.com/orgs/sushiclm/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/22522358?v=4","description":null}}]

0 comments on commit cf44395

Please sign in to comment.