Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检索一个人的所有GitHub存储库的列表?_Github_Github Api - Fatal编程技术网

如何检索一个人的所有GitHub存储库的列表?

如何检索一个人的所有GitHub存储库的列表?,github,github-api,Github,Github Api,我们正在进行一个项目,需要在GitHub帐户上显示一个人存储库中的所有项目 任何人都可以建议,如何使用特定人员的git用户名显示其所有git存储库的名称?您可以使用。点击https://api.github.com/users/USERNAME/repos将列出用户用户名的公共存储库。使用: /users/:user/repos 这将为您提供用户的所有公共存储库。如果需要查找私有存储库,则需要作为特定用户进行身份验证。然后,您可以使用REST调用: /user/repos 查找所有用户的回购协议

我们正在进行一个项目,需要在GitHub帐户上显示一个人存储库中的所有项目

任何人都可以建议,如何使用特定人员的git用户名显示其所有git存储库的名称?

您可以使用。点击
https://api.github.com/users/USERNAME/repos
将列出用户用户名的公共存储库。

使用:

/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,如上面的示例所示。如果您不需要进行身份验证,那么只需修改该方法以删除添加授权标头即可。然后,您可以使用一个简单的get请求获取任何公共api url。

尝试使用以下
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\u token=GITHUB\u API\u token
),例如:

curl "https://api.github.com/users/$GHUSER/repos?access_token=$GITHUB_API_TOKEN" | grep -w clone_url
如果用户是组织,则使用
/orgs/:username/repos
返回所有存储库

要克隆它们,请参见:


另请参见:

您可能需要一个jsonp解决方案:

https://api.github.com/users/[用户名]/repos?callback=abc

如果使用jQuery:

$.ajax({
url:“https://api.github.com/users/blackmiaool/repos",
jsonp:没错,
方法:“获取”,
数据类型:“json”,
成功:功能(res){
console.log(res)
}
});
如果已安装,则可以使用以下命令列出用户的所有公共回购

curl -s https://api.github.com/users/<username>/repos | jq '.[]|.html_url'
curl-shttps://api.github.com/users//repos |jq.[]..html_url'
JSON分页 下面的JS代码是在控制台中使用的

username = "mathieucaroff";

w = window;
Promise.all(Array.from(Array(Math.ceil(1+184/30)).keys()).map(p =>
    fetch(`//api.github.com/users/{username}/repos?page=${p}`).then(r => r.json())
)).then(all => {
    w.jo = [].concat(...all);
    // w.jo.sort();
    // w.jof = w.jo.map(x => x.forks);
    // w.jow = w.jo.map(x => x.watchers)
})

答案是“/users/:user/repo”,但我在一个开源项目中有所有的代码,可以用来在服务器上支持web应用程序

我启动了一个名为GitHub的项目,它与列出所有回购协议的GitHub API进行通信

它是一个开源web应用程序,由Node.js构建,利用GitHub API在众多GitHub存储库中查找、创建和删除分支

它可以为组织或单个用户设置

我在read me中也有一个逐步设置的方法。

NPM模块为某些用户或组的所有公共回购获取JSON。您可以直接从
npx
运行此程序,因此无需安装任何东西,只需选择一个组织或用户(此处为“W3C”):

$npx repos W3C W3Crepos.json
这将创建一个名为W3Crepos.json的文件。Grep足以获取回购协议列表:

$grep全名W3Crepos.json
优点:

  • 与100多家回购协议合作(这个问题的许多答案都没有)
  • 没什么可打的
缺点:

  • 需要
    npx
    (或
    npm
    ,如果您想真正安装它)

使用Python检索GitHub用户的所有公共存储库列表:

导入请求
用户名=输入(“输入github用户名:”)
请求=请求。获取('https://api.github.com/users/“+username+”/repos')
json=request.json()
对于范围(0,len(json))中的i:
打印(“项目编号:”,i+1)
打印(“项目名称:”,json[i]['Name'])
打印(“项目URL:,json[i]['svn_URL'],“\n”)

要获取用户的100个公共存储库的url:

$.getJSON(“https://api.github.com/users/suhailvs/repos?per_page=100,函数(json){
var resp='';
$.each(json,函数(索引,值){
resp=resp+index++'+value['html_url']+'-';
控制台日志(resp);
});
});
HTML

<div class="repositories"></div>

以下是repos API的完整规范:

GET/users/:用户名/repos

查询字符串参数:

前5项记录在上面的API链接中。
页面
每页
的参数记录在其他地方,在完整描述中非常有用

  • 类型
    (字符串):可以是
    所有
    所有者
    成员
    中的一个。默认值:
    owner
  • 排序
    (字符串):可以是
    创建
    更新
    推式
    全名
    中的一种。默认值:
    全名
  • direction
    (字符串):可以是
    asc
    desc
    之一。默认值:
    asc
    当使用
    full\u name
    时,否则
    desc
  • 页面
    (整数):当前页面
  • 每页
    (整数):每页记录数
由于这是一个HTTPGETAPI,除了cURL之外,您还可以在浏览器中简单地进行尝试。例如:

curl "https://api.github.com/users/$GHUSER/repos?access_token=$GITHUB_API_TOKEN" | grep -w clone_url

现在有一个选项可以使用真棒

我想要一份我的组织的所有活动回购协议及其各自语言的列表。此查询只执行以下操作:

{
  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
        }
      }
    }
  }
}


如果寻找一个组织的回购协议-

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

您也可以使用新的花式:

$gh api用户/:所有者/repos
它也会很好地打印输出,这将使可读性更高

装置 下面是一个可以复制并粘贴到shell中的示例:

wget "https://github.com/cli/cli/releases/download/v1.11.0/gh_1.11.0_macOS_amd64.tar.gz"
tar -xvf gh_1.11.0_macOS_amd64.tar.gz
cd gh_1.11.0_macOS_amd64/bin
gh auth login
gh repo list --limit 200
使用:

注意:这将包括与您共享的所有公共、私人和其他人的回购协议

参考资料:


这将只给出结果集的第一个“页面”,即se
wget "https://github.com/cli/cli/releases/download/v1.11.0/gh_1.11.0_macOS_amd64.tar.gz"
tar -xvf gh_1.11.0_macOS_amd64.tar.gz
cd gh_1.11.0_macOS_amd64/bin
gh auth login
gh repo list --limit 200
gh auth login

gh api graphql --paginate -f query='
query($endCursor: String) {
    viewer {
    repositories(first: 100, after: $endCursor) {
        nodes { nameWithOwner }
        pageInfo {
        hasNextPage
        endCursor
        }
    }
    }
}
' | jq ".[] | .viewer | .repositories | .nodes | .[] | .nameWithOwner"