IT TIP

GitHub API : 기여한 저장소

itqueen 2020. 12. 12. 12:55
반응형

GitHub API : 기여한 저장소


GitHub API를 통해 GitHub 프로필 페이지에있는 "기여 된 저장소"모듈의 데이터에 액세스 할 수있는 방법이 있습니까? 이상적으로는 웹에서 얻을 수있는 상위 5 개 목록이 아닌 전체 목록입니다.


사용 구글의 BigQuery를GitHub의 아카이브 , 내가 사용하는 풀 요청을 한 모든 저장소를 뽑아 :

SELECT repository_url 
FROM [githubarchive:github.timeline]
WHERE payload_pull_request_user_login ='rgbkrk'
GROUP BY repository_url;

유사한 의미 체계를 사용하여 기여한 리포지토리의 양과 그 안에 있던 언어 만 가져올 수 있습니다.

SELECT COUNT(DISTINCT repository_url) AS count_repositories_contributed_to,
       COUNT(DISTINCT repository_language) AS count_languages_in
FROM [githubarchive:github.timeline]
WHERE payload_pull_request_user_login ='rgbkrk';

보고 된 사용 문제를 포함하여 전체적인 기여를 찾고있는 경우

SELECT COUNT(DISTINCT repository_url) AS count_repositories_contributed_to,
       COUNT(DISTINCT repository_language) AS count_languages_in
FROM [githubarchive:github.timeline]
WHERE actor_attributes_login = 'rgbkrk'
GROUP BY repository_url;

차이점 actor_attributes_loginIssue Events API 에서 비롯됩니다 .

또한 문제 나 PR이 직접 제출되지 않은 자신의 리포지토리를 캡처 할 수도 있습니다.


함께 GraphQL의 API v4를 , 당신은 지금 이러한 사용 REPO 기여를 얻을 수 있습니다 :

{
  viewer {
    repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
      totalCount
      nodes {
        nameWithOwner
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

탐색기에서 시도

출처

기여한 저장소가 100 개 이상인 경우 (귀하의 것을 포함하여) 다음 요청 after: "END_CURSOR_VALUE"repositoriesContributedTo위해에서 지정하는 페이지 매김을 거쳐야합니다 .


얼마 전에 Github 요약자를 위해 이와 같은 것을 구현해 보았습니다 . 사용자가 기여한 저장소를 가져 오는 단계는 다음과 같습니다 (예 : 내 사용자를 사용).

  • 사용자가 제출 한 최근 닫힌 풀 요청 100 개를 검색 합니다. 물론 첫 페이지가 가득 차면 두 번째 페이지를 요청할 수 있습니다.

https://api.github.com/search/issues?q=type:pr+state:closed+author:megawac&per_page=100&page=1

  • 다음으로 각 repos 기여자 에게 요청합니다 . 문제의 사용자가 기여자 목록에 있으면 목록에 저장소를 추가합니다. 예 :

https://api.github.com/repos/jashkenas/underscore/contributors

  • 사용자가보고있는 모든 저장소를 확인할 수도 있습니다. 다시 각 저장소를 확인합니다.repos/:owner/:repo/contributors

https://api.github.com/users/megawac/subscriptions

  • 또한 사용자가 속한 조직의 모든 저장소를 반복합니다.

https://api.github.com/users/megawac/orgs
https://api.github.com/orgs/jsdelivr/repos

  • 사용자가 리포지토리의 기여자로 나열되면 리포지토리를 목록에 추가합니다 (위와 동일한 단계).

이것은 사용자가 풀 요청을 제출하지 않았지만 기여자로 추가 된 저장소를 놓친다. 우리는 검색하여 이러한 저장소를 찾을 확률을 높일 수 있습니다.

1) 열린 모든 문제 (닫힌 pull 요청이 아님)
2) 사용자가 별표 표시 한 repos

분명히, 우리가 원하는 것보다 더 많은 요청이 필요하지만 그들이 당신을 퍼지하게 만들면 무엇을 할 수 있습니까? \ o /


GitHub API에서 제공 하는 검색 을 사용할 수 있습니다 . 쿼리는 다음과 같아야합니다.

https://api.github.com/search/repositories?q=%20+fork:true+user:username

fork 매개 변수를 true로 설정하면 모든 사용자의 저장소를 쿼리 할 수 ​​있습니다.

그러나 사용자가 저장소를 분기했을뿐만 아니라 기여했는지 확인하려면 '검색'요청으로받은 모든 저장소를 반복하고 사용자가 저장소 내에 있는지 확인해야합니다. github는 100 명의 기여자만을 반환하고 이에 대한 해결책이 없기 때문에 상당히 짜증납니다.


나는 문제에 이르렀다. ( GithubAPI : 사용자가 커밋 한 리포지토리 가져 오기 )

내가 찾은 한 가지 실제 해킹은 http://www.githubarchive.org/ 라는 프로젝트가 있다는 것입니다 . 그들은 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, 데이터 스키마는 여기에서 찾을 수 있습니다. https://github.com/igrigorik/githubarchive.org/blob/master/bigquery/schema.js


이 작업을 수행하기 위해 셀레늄 파이썬 스크립트를 작성했습니다.

"""
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)

It uses python and selenium to automate a Chrome browser to login to github, go to your contributions page, click each day and grab the repo name from any contributions. Since this page only shows 1 year's worth of activity, that's all you can get with this script.


There is a new project that claims to list all contributions:

https://github.com/AurelienLourot/github-contribs

It also backs a service to produce more detailed user profiles:

https://ghuser.io/


I didn't see any way of doing it in the API. The closest I could find was to get the latest 300 events from a public user (300 is the limit, unfortunately), and then you can sort those for contributions to other's repositories.

https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user

We need to ask Github to implement this in their API.


As of now GitHub API v3, doesn't provide a way to get the user's current streak.

You may use this to calculate the current streak.

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

참고URL : https://stackoverflow.com/questions/20714593/github-api-repositories-contributed-to

반응형