Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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 API:存储库对_Github_Github Api - Fatal编程技术网

GitHub API:存储库对

GitHub API:存储库对,github,github-api,Github,Github Api,有没有办法通过GitHub API访问GitHub概要页面上“存储库贡献给”模块中的数据?理想情况下,完整的列表,而不仅仅是前五名,这显然是您在web上可以获得的所有内容。我在API中没有看到任何方法可以做到这一点。我能找到的最接近的方法是从一个公共用户那里获取最新的300个事件(不幸的是,300是限制),然后您可以对这些事件进行排序,以获得对其他存储库的贡献 我们需要让Github在他们的API中实现这一点 。。。我获取用户参与的存储库(他们不拥有)的步骤如下(以我自己的用户为例): 对于

有没有办法通过GitHub API访问GitHub概要页面上“存储库贡献给”模块中的数据?理想情况下,完整的列表,而不仅仅是前五名,这显然是您在web上可以获得的所有内容。

我在API中没有看到任何方法可以做到这一点。我能找到的最接近的方法是从一个公共用户那里获取最新的300个事件(不幸的是,300是限制),然后您可以对这些事件进行排序,以获得对其他存储库的贡献

我们需要让Github在他们的API中实现这一点

。。。我获取用户参与的存储库(他们不拥有)的步骤如下(以我自己的用户为例):

  • 对于用户提交的最后100个关闭拉取请求。当然,如果第一页已满,您可以请求第二页以获得更旧的prs

  • 接下来,我会要求每一个。如果有问题的用户在参与者列表中,我们会将回购添加到列表中。例如:

  • 我们还可以尝试检查用户正在观看的所有回购协议。我们将再次检查每个回购
    repos/:owner/:repo/contributors

  • 此外,我将迭代用户所在组织的所有回购协议

  • 如果该用户被列为任何回购协议的参与者,我们会将该回购协议添加到该列表中(与上述步骤相同)
如果用户未提交拉取请求,但已添加为参与者,则会错过回购。我们可以通过搜索

1) 任何打开的问题(不仅仅是关闭的拉取请求)
2) 用户主演的回购协议

显然,这需要的请求比我们希望的多得多,但是当他们让您伪造功能时,您能做些什么\o/

我来解决这个问题。()

我发现的一个实际的黑客行为是有一个叫做 他们记录2011年开始的所有公共事件。不理想,但可能会有帮助

例如,在您的案例中:

SELECT  payload_pull_request_head_repo_clone_url 
FROM [githubarchive:github.timeline]
WHERE payload_pull_request_base_user_login='outoftime'
GROUP BY payload_pull_request_head_repo_clone_url;
如果我没有弄错的话,给出您要求的回购清单:

https://github.com/jreidthompson/noaa.git
https://github.com/kkrol89/sunspot.git
https://github.com/rterbush/sunspot.git
https://github.com/ottbot/cassandra-cql.git
https://github.com/insoul/cequel.git
https://github.com/mcordell/noaa.git
https://github.com/hackhands/sunspot_rails.git
https://github.com/lgierth/eager_record.git
https://github.com/jnicklas/sunspot.git
https://github.com/klclee/sunspot.git
https://github.com/outoftime/cequel.git
您可以在此处使用bigquery:bigquery.cloud.google.com,可以在此处找到数据模式:

使用,我提取了我向使用发出提取请求的所有存储库:

选择存储库\u url
来自[githubarchive:github.timeline]
其中有效负载\u拉\u请求\u用户\u登录='rgbkrk'
按存储库地址分组;
您可以使用类似的语义来提取您贡献的存储库数量以及它们所使用的语言:

选择COUNT(不同存储库的url)作为COUNT\u存储库的贡献对象,
将(不同的存储库语言)计数为中的计数语言
来自[githubarchive:github.timeline]
其中,有效载荷\u pull\u request\u user\u login='rgbkrk';
如果您正在寻找总体贡献,其中包括报告使用的问题

选择COUNT(不同存储库的url)作为COUNT\u存储库的贡献对象,
将(不同的存储库语言)计数为中的计数语言
来自[githubarchive:github.timeline]
其中actor\u attributes\u login='rgbkrk'
按存储库地址分组;
区别在于
actor\u attributes\u login
,它来自

您可能还想获取自己的回购协议,这些回购协议可能没有您自己提交的问题或PRs。

您可以使用。您的查询应该如下所示:

fork参数设置为true可确保查询所有用户的回购,包括fork


但是,如果您想确保用户不仅参与了分叉存储库,而且还参与了该存储库,那么您应该迭代通过“搜索”请求获得的每个repo,并检查用户是否在其中。这很糟糕,因为github只返回100个贡献者,没有解决方案…

我编写了一个selenium python脚本来实现这一点

"""
Get all your repos contributed to for the past year.

This uses Selenium and Chrome to login to github as your user, go through 
your contributions page, and grab the repo from each day's contribution page.

Requires python3, selenium, and Chrome with chromedriver installed.

Change the username variable, and run like this:

GITHUB_PASS="mypassword" python3 github_contributions.py
"""

import os
import sys
import time
from pprint import pprint as pp
from urllib.parse import urlsplit
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

username = 'jessejoe'
password = os.environ['GITHUB_PASS']

repos = []
driver = webdriver.Chrome()
driver.get('https://github.com/login')

driver.find_element_by_id('login_field').send_keys(username)
password_elem = driver.find_element_by_id('password')
password_elem.send_keys(password)
password_elem.submit()

# Wait indefinitely for 2-factor code
if 'two-factor' in driver.current_url:
    print('2-factor code required, go enter it')
while 'two-factor' in driver.current_url:
    time.sleep(1)

driver.get('https://github.com/{}'.format(username))

# Get all days that aren't colored gray (no contributions)
contrib_days = driver.find_elements_by_xpath(
    "//*[@class='day' and @fill!='#eeeeee']")

for day in contrib_days:
    day.click()
    # Wait until done loading
    WebDriverWait(driver, 10).until(
        lambda driver: 'loading' not in driver.find_element_by_css_selector('.contribution-activity').get_attribute('class'))

    # Get all contribution URLs
    contribs = driver.find_elements_by_css_selector('.contribution-activity a')
    for contrib in contribs:
        url = contrib.get_attribute('href')
        # Only care about repo owner and name from URL
        repo_path = urlsplit(url).path
        repo = '/'.join(repo_path.split('/')[0:3])
        if repo not in repos:
            repos.append(repo)
    # Have to click something else to remove pop-up on current day
    driver.find_element_by_css_selector('.vcard-fullname').click()

driver.quit()
pp(repos)
它使用python和selenium自动使用Chrome浏览器登录github,转到您的贡献页面,每天单击并从任何贡献中获取回购名称。由于此页面仅显示1年的活动价值,因此使用此脚本您只能获得这些内容。

现在,您可以使用以下方式获得这些已贡献的回购:

{
观众{
repositoriesContributedTo(第一个:100,贡献类型:[提交、发布、请求、存储库]){
总数
节点{
所有者姓名
}
页面信息{
结束光标
下一页
}
}
}
}


如果您有超过100份已提交的回购协议(包括您的),您将必须在下一个请求中的“repositories contributed to”中的“END\u CURSOR\u VALUE”之后进行分页,指定

到目前为止,GitHub API v3没有提供获取用户当前连载的方法

您可以使用它来计算当前条纹

https://github.com/users/<username>/contributions.json
https://github.com/users//contributions.json

有一个新项目声称要列出所有贡献:

它还支持服务以生成更详细的用户配置文件:


您可能会通过GitHub的GraphQLAPI获得去年左右的数据,如中所示

2011年发生的一切都可以在GitHub归档中找到,如中所述。 然而,BigQuery的语法和GitHub的API似乎已经发生了变化,其中显示的示例在2020年8月不再有效

下面是我如何找到我出资的所有回购协议

选择不同的repo.name
从(
从'githubarchive.year.2011'中选择*
从'githubarchive.year.2012'中选择*
从'githubarchive.year.2013'中选择*
从'githubarchive.year.2014'中选择*
从'githubarchive.year.2015'中选择*
从'githubarchive.year.2016'中选择*
从'githubarchive.year.2017'中选择*
从'githubarchive.year.2018'中选择*`
)
其中(类型='PushEvent'
或类型='PullRequestEvent')
A.
#!/bin/bash
ghjq() { # <endpoint> <filter>
  # filter all pages of authenticated requests to https://api.github.com
  gh api --paginate "$1" | jq -r "$2"
}
repos="$(
  ghjq users/$GH_USER/repos .[].full_name
  ghjq "search/issues?q=is:pr+author:$GH_USER+is:merged" \
    '.items[].repository_url | sub(".*github.com/repos/"; "")'
  ghjq users/$GH_USER/subscriptions .[].full_name
  for org in "$(ghjq users/$GH_USER/orgs .[].login)"; do
    ghjq orgs/$org/repos .[].full_name
  done
)"
repos="$(echo "$repos" | sort -u)"
# print repo if user is a contributor
for repo in $repos; do
  if [[ $(ghjq repos/$repo/contributors "[.[].login | test(\"$GH_USER\")] | any") == "true" ]]; then
    echo $repo
  fi
done