简体   繁体   English

如何通过api获取github编辑问题历史和问题评论?

[英]How to get github edit history of issue and issue comments via api?

我只找到api获取问题列表,问题内容,​​问题评论列表和内容,没有问题内容编辑历史,没有问题评论编辑历史。

No, this cannot currently be done purely from the API.不,这目前不能完全通过 API 完成。

However, if we reverse engineer the way GitHub loads past edits in the web interface, and do a bit of scraping, we can accomplish the same thing without the API.然而,如果我们对 GitHub 在 Web 界面中加载过去编辑的方式进行逆向工程,并进行一些抓取,我们可以在没有 API 的情况下完成同样的事情。 Unfortunately, this means that we don't have the reliability of an API - GitHub's web interface is liable to change at any time, breaking our code.不幸的是,这意味着我们没有 API 的可靠性 - GitHub 的 Web 界面可能随时更改,从而破坏我们的代码。 But it's better than nothing!但总比没有好!

So, first we need a log of all the edits for a comment.所以,首先我们需要一个评论所有编辑的日志。 Let's do this with the comment https://github.com/seisvelas/crypsee/issues/1#issue-874033952 (from a test repo provided by the gentleman who set the bounty on this question).让我们用评论https://github.com/seisvelas/crypsee/issues/1#issue-874033952 (来自为这个问题设置赏金的绅士提供的测试回购)来做到这一点。 On order to get a log of this issue's comments, we will need to base64 encode the issue number with '05:' then the word 'Issue' at the beginning.为了得到这个问题的评论日志,我们需要用'05:'对问题编号进行base64编码,然后在开头加上单词'Issue'。 Why '05:'?为什么是'05:'? I have no idea.我不知道。 But it's always there and it won't work with out it.但它总是在那里,没有它就行不通。 So we'll be base64 encoding the string "05:Issue874033952", which gives us MDU6SXNzdWU4NzQwMzM5NTI=所以我们将对字符串“05:Issue874033952”进行base64编码,这给了我们MDU6SXNzdWU4NzQwMzM5NTI=

Great, now we insert MDU6SXNzdWU4NzQwMzM5NTI= into this URL scheme: https://github.com/_render_node/{BASE64 ENCODING HERE}/comments/comment_edit_history_log , resulting in a link to https://github.com/_render_node/MDU6SXNzdWU4NzQwMzM5NTI=/comments/comment_edit_history_log太好了,现在我们将MDU6SXNzdWU4NzQwMzM5NTI=插入到这个 URL 方案中: https://github.com/_render_node/{BASE64 ENCODING HERE}/comments/comment_edit_history_log ,导致链接到https://github.com/_render_node/MDU6SXNzdwMz5Mz5M评论/comment_edit_history_log

Following that link, we see an edit history, but not the contents of the edits themselves:在该链接之后,我们会看到编辑历史记录,但不会看到编辑内容本身:

编辑历史截图

However, this gives us the information we need!然而,这为我们提供了我们需要的信息! If we look at the HTML, we see that all edits prior to the current edit are defined as buttons with a link to that edit:如果我们查看 HTML,我们会看到当前编辑之前的所有编辑都定义为带有该编辑链接的按钮:

<button 
    type="button" 
    class="btn-link dropdown-item p-2" 
    role="menuitem" 
    data-edit-history-url="/user_content_edits/MDE1OlVzZXJDb250ZW50RWRpdElzc3VlRWRpdDo1MzIxODcxNzE="
>

The URL pointed to by the data-edit-history-url is the same URL loaded via the browser's networking tab when clicking to view a past edit in the web interface! data-edit-history-url指向的 URL 与在 Web 界面中单击查看过去的编辑时通过浏览器的网络选项卡加载的 URL 相同!

Unfortunately , if you attempt to view that page on it's own, you get a 404. It is intended to be viewed only from the web interface.不幸的是,如果您尝试自行查看该页面,则会收到 404。它只能从 Web 界面查看。 But that's no problem, just go to the web interface, view one of the edits, and copy the headers it sends along.但这没问题,只需转到 Web 界面,查看其中一项编辑内容,然后复制它随附的标题即可。 In my case I'm using Chromium, so I just find the request to the edit in my networking tab, right click and hit 'copy as Fetch request (nodejs)' and viola, with those headers I'm good to go!就我而言,我使用的是 Chromium,所以我只需在我的网络选项卡中找到编辑请求,右键单击并点击“复制为 Fetch 请求(nodejs)”和 viola,这些标题我很高兴!

For example, for the comment we've been using this whole time, I make that request and get back a bunch of HTML.例如,对于我们一直在使用的评论,我提出该请求并返回一堆 HTML。 The content of the original edit is near the end:原始编辑的内容接近尾声:

      <ins><p class="rich-diff-level-zero">before edit</p></ins>

There it is!就在那里! I could write a script to automate this, but then I'd be doing everything for you :3 Suffice it to say that with a day's work of cleverly organized scraping, this is roughly what you must to in order to view these revisions.我可以编写一个脚本来自动执行此操作,但随后我会为您做所有事情:3 可以说,通过一天的巧妙组织的抓取工作,这大致是您查看这些修订所必须执行的操作。 If someone does make such a tool, the OSINT community will surely be immensely grateful!如果有人制作了这样的工具,OSINT 社区肯定会非常感激!

To see the features of github api, it is better to read the following link要查看github api的功能,最好阅读以下链接

The best source to get the answer:获得答案的最佳来源:

https://docs.github.com/en/rest/reference/issues https://docs.github.com/en/rest/reference/issues

Check the issues you mentioned, ie issue comments , edit history issue , etc. in the link above在上面的链接中检查您提到的问题,即issue commentsedit history issue

As far as I saw it is possible to receive issue comments but I did not see a section for edit history issue据我所知,可以收到issue comments但我没有看到edit history issue的部分

I also suggest you see the following links for the edit history issue : https://github.com/isaacs/github/issues/954我还建议您查看以下有关edit history issue链接: https : //github.com/isaacs/github/issues/954

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM