ubiquity / ubiquibot

Putting the 'A' in 'DAO'
https://github.com/marketplace/ubiquibot
MIT License
17 stars 61 forks source link

Proposal: refactor `getOpenedPullRequestsForAnIssue` #679

Open 0x4007 opened 1 year ago

0x4007 commented 1 year ago

This relies on the "closing keywords" notation in the opening comment, but a more robust way (not everybody uses closing keywords) would be to check any "link" events in the timeline

https://github.com/ubiquity/ubiquibot/blob/879d066391146229b8fcbf81c324dd5c7a59df4b/src/helpers/issue.ts#L596-L609

ChatGPT

As of my knowledge cutoff in September 2021, GitHub API does not provide a direct way to get the linked issues of a pull request. However, you can still use the GitHub API to check the timeline of an issue or pull request to see if there is any link event. The linked pull request or issue will be in the 'source' or 'target' of the link event.

  1. Check the Issue Timeline: Use the GET /repos/:owner/:repo/issues/:issue_number/timeline endpoint to get the timeline events of an issue.

  2. Check the Pull Request Timeline: Use the GET /repos/:owner/:repo/pulls/:pull_number/timeline endpoint to get the timeline events of a pull request.

The timeline of an issue or pull request contains all events that have occurred in its lifecycle, including comments, labels, and links to other issues or pull requests.

For example, you can check the timeline of an issue to see if there is any 'linked' event that links it to a pull request.

Here is an example using curl to get the timeline of an issue:

curl -X GET -H "Authorization: token YOUR_ACCESS_TOKEN" \
-H "Accept: application/vnd.github.mockingbird-preview" \
"https://api.github.com/repos/:owner/:repo/issues/:issue_number/timeline"

Replace YOUR_ACCESS_TOKEN, :owner, :repo, and :issue_number with your own values.

You will need to go through the response and look for any 'linked' events to find the associated pull request. The linked pull request will be in the 'source' or 'target' of the link event.

Remember to be mindful of the rate limits imposed by GitHub on its API. Unauthenticated requests are limited to 60 requests per hour, while authenticated requests are limited to 5000 requests per hour.

As of my last update, this is the most accurate information I have. However, it's always a good idea to consult the official documentation for the most current information.

Just be sure to monitor unlink events.

wannacfuture commented 1 year ago

what about refactoring getOpenedPullrequestForAnissue using gitLinkedPrParser on https://github.com/ubiquity/ubiquibot/pull/657 ?

even it is depending on the dom elements on the page, I'm not too sure about what chatGPT said, lol