Created
March 24, 2024 14:46
-
-
Save t3yamoto/ac19748846e00405acbd5f1ff56fbdc2 to your computer and use it in GitHub Desktop.
GitHubの指定Organization、期間内に作成したPR数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# 設定 | |
token = '' # あなたのPersonal Access Tokenを設定してください | |
organization = '' # 調べたいOrganization名を設定してください | |
user = '' # 調べたいGitHubユーザー名を設定してください | |
start_date = '2023-09-01' # 開始日 | |
end_date = '2024-02-29' # 終了日 | |
headers = {'Authorization': f'token {token}'} | |
# organizationのリポジトリを取得 | |
repos_url = f'https://api.github.com/orgs/{organization}/repos' | |
repos_response = requests.get(repos_url, headers=headers) | |
repos = repos_response.json() | |
# リポジトリごとにコントリビューションを検索 | |
contributions = 0 | |
for repo in repos: | |
repo_name = repo['name'] | |
pulls_url = f'https://api.github.com/repos/{organization}/{repo_name}/pulls?state=all&per_page=100' | |
while pulls_url: | |
pulls_response = requests.get(pulls_url, headers=headers) | |
pulls = pulls_response.json() | |
for pull in pulls: | |
if pull['user']['login'] == user and start_date <= pull['created_at'] <= end_date: | |
contributions += 1 | |
pulls_url = pulls_response.links.get('next', {}).get('url', None) | |
print(f'指定期間内のコントリビューション数: {contributions}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment