英文:
How can I see a list of all of my GitHub comments, including ones on commits (and not using an API)?
问题
https://github.com/notifications/subscriptions 没有帮助,因为我看不到评论的实际消息。
https://github.com/search?q=involves%3A%40me&type=pullrequests 似乎也不对。
https://github.com/search?q=commenter%3A%40me&type=commits 说“在搜索提交时不支持评论者限定符”。
https://github.com/search?q=commenter%3A%40me&type=pullrequests&s=updated&o=desc 是我的最佳选择吗?
英文:
What GitHub page and query could I use?
https://github.com/notifications/subscriptions isn't helpful because I can't see the actual message of the comments.
https://github.com/search?q=involves%3A%40me&type=pullrequests doesn't seem to be right, either.
https://github.com/search?q=commenter%3A%40me&type=commits says "The commenter qualifier is not supported when searching commits."
Is https://github.com/search?q=commenter%3A%40me&type=pullrequests&s=updated&o=desc my best option?
答案1
得分: 1
不使用API似乎无法实现这一点,GitHub搜索语法似乎无法支持。
进一步筛选我的评论中未得到回应的评论可能会更好。"回应"这个词有点不清楚,因为"回应"可能不总是以直接回复的形式出现,而可能是在同一线程中的另一个对话中。
作为一个更简单的替代方案,你可以尝试获取你在每个问题上发表的最后一条评论,并检查是否是你自己的。如果最后一条评论是你自己的,那么可以视为未得到回应...尽管在线程中可能还有其他地方的回应。
即使考虑使用GitHub API,也没有一个端点可以获取特定用户在不同存储库中的所有评论。获取特定用户发表的所有评论没有直接的方法。你将不得不使用这些端点来获取个别存储库、问题、拉取请求和提交上的评论,然后按用户进行过滤。这可能涉及大量的API请求,特别是如果用户与许多不同的存储库进行了交互。
但是,为了说明给定存储库的问题和PR的API方法:
(请将:username
、:owner
、:repo
和:token
替换为你的GitHub用户名、存储库所有者的用户名、存储库名称和你的个人访问令牌)
github_unresponded_comments.py
import requests
import time
username = ':username' # 你的GitHub用户名
owner = ':owner' # 存储库所有者
repo = ':repo' # 存储库名称
token = ':token' # 你的GitHub个人访问令牌
headers = {
'Authorization': f'token {token}',
}
# 获取存储库中的所有问题
response = requests.get(f'https://api.github.com/repos/{owner}/{repo}/issues', headers=headers)
issues = response.json()
# 获取存储库中的所有拉取请求
response = requests.get(f'https://api.github.com/repos/{owner}/{repo}/pulls', headers=headers)
pulls = response.json()
# 连接问题和拉取请求
items = issues + pulls
unresponded_comments = []
# 现在检查每个问题/拉取请求,看看你的评论是否是最后一个
for item in items:
time.sleep(1) # 防止超出速率限制
comments_url = item['comments_url']
response = requests.get(comments_url, headers=headers)
comments = response.json()
if comments:
# 检查最后一条评论是否来自用户
last_comment = comments[-1]
if last_comment['user']['login'] == username:
unresponded_comments.append(last_comment)
# 打印所有未得到回应的评论
for comment in unresponded_comments:
print(f"未得到回应的评论在问题 {comment['html_url']}: {comment['body']}")
这将检查存储库中的问题和拉取请求,并找到最后一条评论是由指定用户发表的那些。
cd /path/to/the/directory
python github_unresponded_comments.py
英文:
> And no using the API
Then... it does not seem supported by GitHub search syntax alone.
> I'd further be able to filter to comments from me that have not been responded to.
"Responded to"? That seems unclear, considering the "response" may not always come in the form of a direct reply, and could be part of another conversation in the same thread.
As a simpler alternative, you could try and get the last comment on each issue you have commented on and check if it is yours. If the last comment is yours, it could be seen as not responded to... even though, again, a response might be somewhere else in the thread.
Even if you were to consider the GitHub API, there is no endpoint for getting all comments by a specific user across different repositories.
And there is not a straightforward way to get all comments made by a specific user. You would have to use these endpoints to get comments on individual repositories, issues, pull requests, and commits, then filter them by user. That could potentially involve a very large number of API requests, especially if the user has interacted with many different repositories.
Still, to illustrate the API approach for issues and PR of a given repository:
(Do replace :username
, :owner
, :repo
, and :token
with your GitHub username, repository owner's username, repository name, and your personal access token respectively)
github_unresponded_comments.py
import requests
import time
username = ':username' # your GitHub username
owner = ':owner' # the owner of the repository
repo = ':repo' # the repository name
token = ':token' # your GitHub personal access token
headers = {
'Authorization': f'token {token}',
}
# Get all issues from the repo
response = requests.get(f'https://api.github.com/repos/{owner}/{repo}/issues', headers=headers)
issues = response.json()
# Get all pull requests from the repo
response = requests.get(f'https://api.github.com/repos/{owner}/{repo}/pulls', headers=headers)
pulls = response.json()
# Concatenate issues and pull requests
items = issues + pulls
unresponded_comments = []
# Now check each issue/pull request to see if your comment is the last one
for item in items:
time.sleep(1) # to prevent hitting the rate limit
comments_url = item['comments_url']
response = requests.get(comments_url, headers=headers)
comments = response.json()
if comments:
# Check if the last comment is from the user
last_comment = comments[-1]
if last_comment['user']['login'] == username:
unresponded_comments.append(last_comment)
# Print all comments that haven't been responded to
for comment in unresponded_comments:
print(f"Unresponded comment in issue {comment['html_url']}: {comment['body']}")
That would check both issues and pull requests in a repository and find the ones where the last comment was made by the specified user.
cd /path/to/the/directory
python github_unresponded_comments.py
But it does not handle pagination or rate limits
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论