use*_*981 62 github github-api
我们正在开发一个项目,我们需要在GitHub帐户的存储库中显示一个人的所有项目.
任何人都可以建议,如何使用他的git-user名称显示特定人员的所有git存储库的名称?
Fre*_*ung 37
你可以使用github api.点击https://api.github.com/users/USERNAME/repos将列出该用户的公共存储库.
BeR*_*ive 34
使用Github API:
/users/:user/repos
这将为您提供所有用户的公共存储库.如果您需要查找私有存储库,则需要以特定用户身份进行身份验证.然后,您可以使用REST调用:
/user/repos
找到所有用户的回购.
要在Python中执行此操作,请执行以下操作:
USER='AUSER'
API_TOKEN='ATOKEN'
GIT_API_URL='https://api.github.com'
def get_api(url):
    try:
        request = urllib2.Request(GIT_API_URL + url)
        base64string = base64.encodestring('%s/token:%s' % (USER, API_TOKEN)).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string)
        result = urllib2.urlopen(request)
        result.close()
    except:
        print 'Failed to get api request from %s' % url
传递给函数的url是REST url,如上例所示.如果您不需要进行身份验证,则只需修改方法即可删除添加Authorization标头.然后,您可以使用简单的GET请求获取任何公共API.
ken*_*orb 31
请尝试以下curl命令列出存储库:
GHUSER=CHANGEME; curl "https://api.github.com/users/$GHUSER/repos?per_page=100" | grep -o 'git@[^"]*'
要列出克隆的URL,请运行:
GHUSER=CHANGEME; curl -s "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -w clone_url | grep -o '[^"]\+://.\+.git'
如果它是私有的,则需要添加API密钥(access_token=GITHUB_API_TOKEN),例如:
curl "https://api.github.com/users/$GHUSER/repos?access_token=$GITHUB_API_TOKEN" | grep -w clone_url
要克隆它们,请参阅:如何从GitHub一次克隆所有repos?
Gro*_*ify 11
这是 repos API 的完整规范:
https://developer.github.com/v3/repos/#list-repositories-for-a-user
GET /users/:username/repos
查询字符串参数:
前 5 个记录在上面的 API 链接中。对于参数page和per_page被记录在其他地方,并在一个完整的描述是有用的。
type(string): 可以是all, owner, 之一member。默认:ownersort(string): 可以是created, updated, pushed, 之一full_name。默认:full_namedirection(string): 可以是asc或 之一desc。默认值:asc使用时full_name,否则descpage (整数):当前页面per_page (整数):每页记录数由于这是一个 HTTP GET API,除了 cURL 之外,您可以简单地在浏览器中进行尝试。例如:
https://api.github.com/users/grokify/repos?per_page=2&page=2
您可能需要一个 jsonp 解决方案:
https://api.github.com/users/[user name]/repos?callback=abc
如果您使用 jQuery:
$.ajax({
  url: "https://api.github.com/users/blackmiaool/repos",
  jsonp: true,
  method: "GET",
  dataType: "json",
  success: function(res) {
    console.log(res)
  }
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>小智 7
如果安装了jq,则可以使用以下命令列出用户的所有公共存储库
curl -s https://api.github.com/users/<username>/repos | jq '.[]|.html_url'
gh命令您可以为此使用github cli:
$ gh api users/:owner/repos
或者
gh api orgs/:orgname/repos
对于您需要的所有存储库--paginate,您可以将其与--jq仅显示name每个存储库结合使用:
gh api orgs/:orgname/repos --paginate  --jq '.[].name' | sort
现在可以选择使用很棒的GraphQL API Explorer。
我想要一份我的组织的所有活动存储库及其各自语言的列表。这个查询就是这样做的:
{
  organization(login: "ORG_NAME") {
    repositories(isFork: false, first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
      pageInfo {
        endCursor
      }
      nodes {
        name
        updatedAt
        languages(first: 5, orderBy: {field: SIZE, direction: DESC}) {
          nodes {
            name
          }
        }
        primaryLanguage {
          name
        }
      }
    }
  }
}
NPM 模块repos为某些用户或组获取所有公共 repos 的 JSON。您可以直接运行它,npx因此您无需安装任何东西,只需选择一个组织或用户(此处为“W3C”):
$ npx repos W3C W3Crepos.json
这将创建一个名为 W3Crepos.json 的文件。Grep 足以例如获取存储库列表:
$ grep full_name W3Crepos.json
优点:
缺点:
npx(或者npm如果您想真正安装它)。使用 Python 检索 GitHub 用户的所有公共存储库的列表:
import requests
username = input("Enter the github username:")
request = requests.get('https://api.github.com/users/'+username+'/repos')
json = request.json()
for i in range(0,len(json)):
  print("Project Number:",i+1)
  print("Project Name:",json[i]['name'])
  print("Project URL:",json[i]['svn_url'],"\n")
如果寻找组织的回购协议 -
api.github.com/orgs/$NAMEOFORG/repos
例子:
curl https://api.github.com/orgs/arduino-libraries/repos
您还可以添加 per_page 参数来获取所有名称,以防出现分页问题 -
curl https://api.github.com/orgs/arduino-libraries/repos?per_page=100
| 归档时间: | 
 | 
| 查看次数: | 56508 次 | 
| 最近记录: |