-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthrough此次变更主要涉及对 Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
There was a problem hiding this 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
📒 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'; |
There was a problem hiding this comment.
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 --save
或yarn 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", |
There was a problem hiding this comment.
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 依赖包
基于验证结果,发现以下严重问题:
- 该包在 npm 仓库中无法获取到任何基本信息(发布时间、下载量、维护者等)
- 在代码库中仅在 package.json 中发现引用,没有实际使用代码
- 包的可用性和可靠性无法得到验证
建议:
- 建议回退此更改,继续使用原有的
@qixian.cs/github-contributors-list
包 - 或者寻找其他更可靠的替代方案来解决头像显示问题
🔗 Analysis chain
请验证新依赖包的可靠性和兼容性
关于将 @qixian.cs/github-contributors-list
替换为 github-contributors-lists
的变更,需要注意以下几点:
- 新包的版本(1.0.3)相对较低,建议验证其稳定性和维护状态
- 由于是不同的包,需要确认 API 接口的兼容性
- 建议在合并前在测试环境完整验证新包的功能
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是直接前端请求 github api,会被限流吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档中贡献者头像无法显示,原因可能是 主分支为 main,antd 的是 master 分支所以不会有问题,虽然当时也 pr 加上了 main分支的设置,但是好像也会有这样子问题。所以当时换了个api 接口开发了个插件,web3.ant.design目前的的贡献者头像就是用这个插件(https://github.com/thinkasany/contributors-list)
before:
after:
Summary by CodeRabbit
新功能
Bug 修复
ContributorAvatar
组件的解构逻辑,确保在未提供item
时不会抛出错误。文档
package.json
中的依赖项,替换为更通用的github-contributors-lists
包。