admin管理员组

文章数量:1290134

I am working on a commit tree visualization in React using the GitGraph.js library. My goal is to fetch commits, branches, and merge history from the GitHub API and use this data to render a commit tree.

However, I am facing two main problems:

  • Disconnected data from GitHub API:

    When fetching commits (/repos/{owner}/{repo}/commits), branches (/repos/{owner}/{repo}/branches), and merges (/repos/{owner}/{repo}/pulls), the API does not provide a clear connection between these elements. It's difficult to determine which commit belongs to which branch and how merges should be represented.

  • Merges automatically push all commits to main/master:

    When a branch is merged, all previous commits from that branch seem to be included in the main/master branch, making it look like they were always part of it. This affects the visualization, making it hard to distinguish the actual branch history.

My goal is something like on the image but universal repository and commits.

I fetch commits using GET /{owner}/{repo}/commits

I fetch branches using GET /{owner}/{repo}/branches

I fetch pull requests (merges) using GET /{owner}/{repo}/pulls?state=closed

I tried mapping commits to branches by checking the parents field in commit data but ran into issues with merge commits.

Questions:

  • How can I properly map commits to branches to ensure an accurate representation of branch history?
  • How do I correctly handle merge commits in GitGraph.js to avoid them overriding the commit tree?
  • Is there a better way to fetch structured commit history from GitHub API?

本文标签: