ubiquity / ubiquibot

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

Associating Issues With Pull Requests V2 #917

Closed 0x4007 closed 4 months ago

0x4007 commented 5 months ago

Our old approach involved scraping the DOM from a public issue view. This does not work on private repositories (we could not extract an auth token from the app private key authenticated octokit client.)

After some research by @wannacfuture and I, we came to the conclusion that the only way to do this is to read the events of an issue and pull request e.g. https://api.github.com/repos/ubiquibot/production/issues/77/timeline https://api.github.com/repos/ubiquibot/production/issues/78/timeline

And cross reference the connected or cross-referenced events e.g.

Issue

  {
    "id": 11683241476,
    "node_id": "COE_lADOJkXFU85-DOthzwAAAAK4YB4E",
    "url": "https://api.github.com/repos/ubiquibot/production/issues/events/11683241476",
    "actor": {
      "login": "pavlovcik",
      "id": 4975670,
      "node_id": "MDQ6VXNlcjQ5NzU2NzA=",
      "avatar_url": "https://avatars.githubusercontent.com/u/4975670?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/pavlovcik",
      "html_url": "https://github.com/pavlovcik",
      "followers_url": "https://api.github.com/users/pavlovcik/followers",
      "following_url": "https://api.github.com/users/pavlovcik/following{/other_user}",
      "gists_url": "https://api.github.com/users/pavlovcik/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/pavlovcik/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/pavlovcik/subscriptions",
      "organizations_url": "https://api.github.com/users/pavlovcik/orgs",
      "repos_url": "https://api.github.com/users/pavlovcik/repos",
      "events_url": "https://api.github.com/users/pavlovcik/events{/privacy}",
      "received_events_url": "https://api.github.com/users/pavlovcik/received_events",
      "type": "User",
      "site_admin": false
    },
    "event": "connected",
    "commit_id": null,
    "commit_url": null,
    "created_at": "2024-02-02T12:00:52Z",
    "performed_via_github_app": null
  }

Pull Request

  {
    "id": 11683241469,
    "node_id": "COE_lADOJkXFU85-DO11zwAAAAK4YB39",
    "url": "https://api.github.com/repos/ubiquibot/production/issues/events/11683241469",
    "actor": {
      "login": "pavlovcik",
      "id": 4975670,
      "node_id": "MDQ6VXNlcjQ5NzU2NzA=",
      "avatar_url": "https://avatars.githubusercontent.com/u/4975670?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/pavlovcik",
      "html_url": "https://github.com/pavlovcik",
      "followers_url": "https://api.github.com/users/pavlovcik/followers",
      "following_url": "https://api.github.com/users/pavlovcik/following{/other_user}",
      "gists_url": "https://api.github.com/users/pavlovcik/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/pavlovcik/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/pavlovcik/subscriptions",
      "organizations_url": "https://api.github.com/users/pavlovcik/orgs",
      "repos_url": "https://api.github.com/users/pavlovcik/repos",
      "events_url": "https://api.github.com/users/pavlovcik/events{/privacy}",
      "received_events_url": "https://api.github.com/users/pavlovcik/received_events",
      "type": "User",
      "site_admin": false
    },
    "event": "connected",
    "commit_id": null,
    "commit_url": null,
    "created_at": "2024-02-02T12:00:52Z",
    "performed_via_github_app": null
  }

We can see that the only thing matching here is the created_at property.

Be sure to invalidate pairing disconnected and un-cross-referenced events (not sure the exact names.)

Glossary

connected refers to when a collaborator selects the issue from the pull request UI (sidebar) cross-referenced is when a contributor who opens the pull request, opens with a "closing" keyword e.g. Resolves #1234

0x4007 commented 5 months ago

@wannacfuture this is yours to take

0x4007 commented 5 months ago

Just did a test. Once not linked, and once linked. https://github.com/pavlovcik/link-pulls/blob/development/static/link-pull.ts

m1:static nv$ yarn tsx static/link-pull.ts
yarn run v1.22.21
$ /Users/nv/repos/pavlovcik/link-pull-request-prototype/node_modules/.bin/tsx static/link-pull.ts
Trace: { isLinked: true }
    at main (/Users/nv/repos/pavlovcik/link-pull-request-prototype/static/link-pull.ts:53:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
✨  Done in 1.47s.
m1:static nv$
gentlementlegen commented 4 months ago

@pavlovcik I already stumbled upon this before, and the problem with cross-referenced is that referencing another issue in a comment also creates that same event. connected does not always happen either, depending on some scenarios. I've seen somewhere that the GraphQl API actually does make it possible to retrieve, but didn't test myself. Second problem is that the timeline is paginated and could eventually get tedious to parse. I can have a look if @wannacfuture has something else on his plate.

ubiquibot[bot] commented 4 months ago

@pavlovcik the deadline is at 2024-02-29T11:24:28.919Z

0x4007 commented 4 months ago

I guess I technically finished implementing this already at https://github.com/ubiquibot/conversation-rewards

Which is a brand new codebase with tests for this.

ubiquibot[bot] commented 4 months ago
+ Evaluating results. Please wait...
ubiquibot[bot] commented 4 months ago

[ 423.4 WXDAI ]

@pavlovcik
Contributions Overview
ViewContributionCountReward
IssueSpecification199
IssueTask1300
IssueComment324.4
IssueComment30
Conversation Incentives
CommentFormattingRelevanceReward
Our old approach involved scraping the DOM from a public issue v...
99
h3:
  count: 3
  score: "3"
  words: 4
code:
  count: 7
  score: "7"
  words: 7
199
@wannacfuture this is yours to take...
1.20.811.2
Just did a test. Once not linked, and once linked. https://git...
18.2
code:
  count: 1
  score: "1"
  words: 0
0.7118.2
I guess I technically finished implementing this already at http...
50.7755
@wannacfuture this is yours to take...
-0.81-
Just did a test. Once not linked, and once linked. https://git...
-
code:
  count: 1
  score: "0"
  words: 0
0.71-
I guess I technically finished implementing this already at http...
-0.775-

[ 10.4 WXDAI ]

@FernandVEYRIER
Contributions Overview
ViewContributionCountReward
IssueComment110.4
Conversation Incentives
CommentFormattingRelevanceReward
@pavlovcik I already stumbled upon this before, and the problem ...
10.4
code:
  count: 2
  score: "2"
  words: 3
0.6210.4