0

如何使用 Python 和 GitHub API 获取特定团队(或存储库)的用户详细信息(用户名、电子邮件、位置)?这些团队不公开,但我是我正在尝试检查的团队的成员(为老板准备报告)。

我试过使用像 github3py 这样的库,到目前为止没有任何运气。

import github3
g = github3.login(GH_USERNAME, GH_PASSWORD)
members = g.orgs.team(GH_TEAM)

for u in members
    print u.login
    print u.name
    print u.email
4

2 回答 2

2

您可以使用PyGithub.

安装

pip install PyGithub

获得这样的团队成员:

from github import Github
g = Github(GH_USERNAME, GH_PASSWORD)
org = g.get_organization(GH_ORG) //GH_ORG is organization name
teams = org.get_teams()
for t in teams:
    if t.name == GH_TEAM:
        for m in t.get_members():
            print(m.login)

希望它可以帮助你。

于 2017-05-21T21:23:00.723 回答
1

感谢您使用github3.py.

你应该做的是以下几点:

  1. 登录 GitHub

    import github3
    g = github3.login(GH_USERNAME, GH_PASSWORD)
    
  2. 检索您的组织

    organization = g.organization('my-organization-name')
    
  3. 寻找你的团队

    for team in organization.teams():
        if team.name == 'my-team-name':
            break
    else:
        raise SystemExit('Could not find team named "my-team-name"')
    
  4. 使用团队枚举成员

    for member in team.members():
         print('{}\t{}'.format(member.login, member.name))
    

    请注意,GitHub 的 API 在枚举对象列表(例如,团队成员)时不会返回所有信息。您可能需要致电member.refresh()以检索有关团队成员的完整用户信息。

如果您有团队的 ID,那么步骤 3 可能更容易:

team = organization.team(1234)
于 2017-05-22T21:38:24.947 回答