Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace github-contributors-lists plugin #257

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thinkasany
Copy link

@thinkasany thinkasany commented Nov 27, 2024

文档中贡献者头像无法显示,原因可能是 主分支为 main,antd 的是 master 分支所以不会有问题,虽然当时也 pr 加上了 main分支的设置,但是好像也会有这样子问题。所以当时换了个api 接口开发了个插件,web3.ant.design目前的的贡献者头像就是用这个插件(https://github.com/thinkasany/contributors-list)

before:
image

after:
image

Summary by CodeRabbit

  • 新功能

    • 更新了贡献者头像和贡献者列表组件的导入路径,提升了组件的灵活性和可维护性。
  • Bug 修复

    • 改进了 ContributorAvatar 组件的解构逻辑,确保在未提供 item 时不会抛出错误。
  • 文档

    • 更新了 package.json 中的依赖项,替换为更通用的 github-contributors-lists 包。

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

📝 Walkthrough

Walkthrough

此次变更主要涉及对 ContributorAvatarContributors 组件的导入语句进行修改,将原先从 @qixian.cs/github-contributors-list 的导入更改为更通用的 github-contributors-lists。此外,ContributorAvatar 组件中的 item 属性的解构逻辑进行了小幅改进,以提供默认值,从而增强错误处理能力。package.json 文件中也更新了依赖项,反映了对新包的引入。

Changes

文件路径 变更摘要
.dumi/theme/slots/Content/ContributorAvatar.tsx 更新导入路径,将 AvatarListItem@qixian.cs/github-contributors-list 更改为 github-contributors-lists,并调整了导入顺序。修改了 item 属性的解构逻辑以提供默认值。
.dumi/theme/slots/Content/Contributors.tsx 更新导入路径,将 ContributorsList@qixian.cs/github-contributors-list 更改为 github-contributors-lists
package.json 更新依赖项,将 @qixian.cs/github-contributors-list^2.0.2 更改为 github-contributors-lists

Possibly related PRs

Suggested reviewers

  • YumoImer

Poem

在草地上跳跃,兔子欢快舞,
导入路径更新,代码更流畅。
贡献者头像,闪亮如星光,
让我们一起庆祝,代码更辉煌! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Prepare preview

Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] network 0 47.3 kB thinkerwing

View full report↗︎

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
.dumi/theme/slots/Content/ContributorAvatar.tsx (1)

Line range hint 35-37: 建议考虑提高代码的可配置性

目前 GitHub URL 是硬编码的(https://github.com/${username}),建议考虑将其改为可配置的,以支持其他 Git 托管服务提供商。这样可以提高组件的复用性。

.dumi/theme/slots/Content/Contributors.tsx (2)

Line range hint 47-63: 建议增加错误处理和加载状态提示

当前实现在数据加载失败时缺少用户反馈机制。建议添加错误处理和加载状态提示。

建议按照以下方式优化代码:

 return (
   <div className={classNames({ [styles.listMobile]: isMobile })}>
     <div className={styles.title}>{formatMessage({ id: 'app.content.contributors' })}</div>
     <ContributorsList
       cache
       repo="x"
       owner="ant-design"
       branch="main"
       fileName={filename}
       className={styles.list}
+      onError={(error) => {
+        console.error('Failed to load contributors:', error);
+        // 可以在这里添加错误提示UI
+      }}
       renderItem={(item, loading) => (
         <ContributorAvatar item={item} loading={loading} key={item?.url} />
       )}
     />
   </div>
 );

Line range hint 47-63: 验证分支配置的正确性

根据 PR 描述,原始问题与分支名称(main/master)有关。目前组件中硬编码使用 main 分支,建议改为可配置的方式。

建议将分支名称提取为配置项:

+interface ContributorsConfig {
+  branch: string;
+  owner: string;
+  repo: string;
+}
+
+const defaultConfig: ContributorsConfig = {
+  branch: 'main',
+  owner: 'ant-design',
+  repo: 'x',
+};
+
-const Contributors: React.FC<ContributorsProps> = ({ filename }) => {
+const Contributors: React.FC<ContributorsProps & Partial<ContributorsConfig>> = ({
+  filename,
+  branch = defaultConfig.branch,
+  owner = defaultConfig.owner,
+  repo = defaultConfig.repo,
+}) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1731062 and b474cc0.

📒 Files selected for processing (3)
  • .dumi/theme/slots/Content/ContributorAvatar.tsx (1 hunks)
  • .dumi/theme/slots/Content/Contributors.tsx (1 hunks)
  • package.json (1 hunks)
🔇 Additional comments (2)
.dumi/theme/slots/Content/ContributorAvatar.tsx (2)

2-3: 导入更改看起来没有问题!

@qixian.cs/github-contributors-list 切换到 github-contributors-lists 的类型导入符合 PR 的目标,且保持了类型定义的一致性。


Line range hint 22-26: 解构赋值的改进很好,建议验证默认值处理!

item 属性添加默认空对象是一个很好的防御性编程实践,可以避免解构时的运行时错误。不过建议验证一下这个改动是否会影响头像的正常显示。

运行以下脚本来验证新的 github-contributors-lists 包的使用情况:

import { createStyles } from 'antd-style';
import classNames from 'classnames';
import { useIntl } from 'dumi';
import ContributorsList from 'github-contributors-lists';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

需要添加 github-contributors-lists 包到项目依赖中

package.json 中缺少 github-contributors-lists 依赖,但代码中已经在使用这个包。这可能会导致构建失败或运行时错误。请:

  • 运行 npm install github-contributors-lists --saveyarn add github-contributors-lists 添加依赖
  • 确保添加的版本为 ^1.0.3(根据之前的搜索结果)
🔗 Analysis chain

请验证新包的兼容性和稳定性

新引入的 github-contributors-lists 包替换了原有的 @qixian.cs/github-contributors-list,建议进行以下验证:

  • 确保新包的 API 接口与原包完全兼容
  • 验证新包在生产环境中的稳定性
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查新包的使用情况和依赖关系

# 查找项目中所有使用此包的地方
rg "github-contributors-lists"

# 检查 package.json 中的版本信息
cat package.json | jq '.dependencies["github-contributors-lists"]'

Length of output: 160


Script:

#!/bin/bash
# 检查原包的使用情况
rg "@qixian.cs/github-contributors-list"

# 检查 Contributors 组件的实现细节
cat .dumi/theme/slots/Content/Contributors.tsx

# 检查 package.json 的完整依赖
cat package.json | jq '.dependencies'

Length of output: 2044

@@ -109,7 +109,7 @@
"@microflash/rehype-figure": "^2.1.1",
"@npmcli/run-script": "^9.0.1",
"@octokit/rest": "^21.0.2",
"@qixian.cs/github-contributors-list": "^2.0.2",
"github-contributors-lists": "^1.0.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

不建议使用 github-contributors-lists 依赖包

基于验证结果,发现以下严重问题:

  1. 该包在 npm 仓库中无法获取到任何基本信息(发布时间、下载量、维护者等)
  2. 在代码库中仅在 package.json 中发现引用,没有实际使用代码
  3. 包的可用性和可靠性无法得到验证

建议:

  • 建议回退此更改,继续使用原有的 @qixian.cs/github-contributors-list
  • 或者寻找其他更可靠的替代方案来解决头像显示问题
🔗 Analysis chain

请验证新依赖包的可靠性和兼容性

关于将 @qixian.cs/github-contributors-list 替换为 github-contributors-lists 的变更,需要注意以下几点:

  1. 新包的版本(1.0.3)相对较低,建议验证其稳定性和维护状态
  2. 由于是不同的包,需要确认 API 接口的兼容性
  3. 建议在合并前在测试环境完整验证新包的功能

Let me verify the package usage in the codebase before making the final response.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查新包的发布时间、下载量和最新版本
echo "检查 github-contributors-lists 包的基本信息:"
curl -s https://api.npms.io/v2/package/github-contributors-lists | jq '{
    "最后发布时间": .collected.metadata.date,
    "周下载量": .collected.npm.downloads[0].count,
    "最新版本": .collected.metadata.version,
    "维护者数量": (.collected.metadata.maintainers | length)
}'

# 检查是否存在已知的安全漏洞
echo -e "\n检查安全漏洞:"
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "github-contributors-lists") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

Length of output: 746


Script:

#!/bin/bash
# 检查当前包的使用情况
echo "在代码库中搜索 github-contributors-lists 的使用:"
rg -l "github-contributors-lists" --type js --type ts --type jsx --type tsx

echo -e "\n检查原包 @qixian.cs/github-contributors-list 的使用:"
rg -l "@qixian.cs/github-contributors-list" --type js --type ts --type jsx --type tsx

# 检查 package-lock.json 中的相关信息
echo -e "\n检查 package-lock.json 中的包信息:"
if [ -f "package-lock.json" ]; then
    jq '.dependencies["github-contributors-lists"] // .packages["node_modules/github-contributors-lists"]' package-lock.json
fi

Length of output: 513


Script:

#!/bin/bash
# 修正文件类型并重新搜索
echo "在代码库中搜索 github-contributors-lists 的使用:"
rg -l "github-contributors-lists"

echo -e "\n检查原包 @qixian.cs/github-contributors-list 的使用:"
rg -l "@qixian.cs/github-contributors-list"

# 检查 package.json 中的相关信息
echo -e "\n检查 package.json 中的依赖配置:"
if [ -f "package.json" ]; then
    jq '.dependencies["github-contributors-lists"], .dependencies["@qixian.cs/github-contributors-list"]' package.json
fi

# 检查是否有相关的文档或配置
echo -e "\n搜索相关配置文件:"
fd -g "*contributors*" -t f

Length of output: 565

import { createStyles } from 'antd-style';
import classNames from 'classnames';
import { useIntl } from 'dumi';
import ContributorsList from 'github-contributors-lists';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是直接前端请求 github api,会被限流吧?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

web3 那边用了半年了,暂时没遇到什么大的问题,而且在代码部分基本保持一致,可以临时用一下试试。 照理说这些 api 只跟用户有关吧,跟打开 github 在线链接能看到谁修改差不多的吧。不要刷的太频繁基本没影响,人工网站路由切换的话应该不会封。
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片

刷一会就不够用了。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不如等 @chenshuai2144 修复 @qixian.cs/github-contributors-list

Copy link
Author

@thinkasany thinkasany Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实应该没这么容易刷完,这个组件也是懒加载的,不滑到底部不会请求。然后过一个小时会刷新限制。 感觉可以让期贤大佬评估一下,有没有必要修,如果可以直接用的话,也更省时间,原理应该都差不多,肯定用的是github的api去查更改过的用户,如果是这么做的话其实也一样都会有limit。
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants