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

docs: Relative Issues & Component Update Logs Connected to Each Component #3027

Merged
merged 28 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
13c69c2
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
c72022e
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
b54b51a
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
e3d9b1b
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
ee4b3d1
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
1681023
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
eebfa67
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
6435a61
docs: add issues and component logs to all docs
Alex-huxiyang Feb 26, 2025
bbe6ad1
chore: 文本相关性算法
Alex-huxiyang Feb 27, 2025
6de2117
chore: 文本相关性算法
Alex-huxiyang Feb 27, 2025
a3266f0
fix: issue url map
Alex-huxiyang Feb 27, 2025
f205051
fix: update docs content
Alex-huxiyang Feb 28, 2025
e9fd914
refactor: 自定义mdx,组件化Contribution, 修改脚本生成
Alex-huxiyang Mar 3, 2025
3f12670
Merge branch 'V3.0' into feat_issues_commits
Alex-huxiyang Mar 4, 2025
133c9c1
fix: resolve conflicts
Alex-huxiyang Mar 7, 2025
18b1369
fix: update mdx import config
Alex-huxiyang Mar 7, 2025
629e971
fix: update mdx import config
Alex-huxiyang Mar 7, 2025
afee0b3
fix: update mdx import config
Alex-huxiyang Mar 7, 2025
c47c0c3
fix: update mdx import config
Alex-huxiyang Mar 7, 2025
35a5893
fix: update mdx import config
Alex-huxiyang Mar 7, 2025
01e0d31
fix: remove useless code
Alex-huxiyang Mar 7, 2025
16edb15
fix: update component style
Alex-huxiyang Mar 10, 2025
368c7bd
fix: 移除emoji
Alex-huxiyang Mar 10, 2025
b06e350
Merge branch 'feat_v3.x' into feat_issues_commits
Alex-huxiyang Mar 10, 2025
f47a0a6
fix: add desc for scripts and adjust style
Alex-huxiyang Mar 12, 2025
ed16a05
fix: add desc for scripts and adjust style
Alex-huxiyang Mar 12, 2025
8e445f8
fix: add desc for scripts and adjust style
Alex-huxiyang Mar 12, 2025
a0355fe
fix: add desc for scripts and adjust style
Alex-huxiyang Mar 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
130 changes: 130 additions & 0 deletions scripts/analyze-title-relevance.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* @description 用于分析标题或日志与组件的相关性
*/
import config from '../src/config.json' assert { type: 'json' }

// 分析标题与组件的相关性
export function analyzeTitleRelevance(title, componentName, componentNameCN) {
const lowerTitle = title.toLowerCase()
const lowerComponentName = componentName.toLowerCase()
let relevanceScore = 0

// 1. 作者指定 (权重: 100)
const commitFormatMatch = title.match(/[\w:]+\((\w+)\):?/) // 修改正则表达式,使其更灵活地匹配组件名
if (
commitFormatMatch &&
commitFormatMatch[1].toLowerCase() === lowerComponentName
) {
relevanceScore += 100
}

// 2. 完全匹配 (权重: 20) - 提高权重
if (lowerTitle.includes(lowerComponentName)) {
relevanceScore += 20
}
if (title.includes(componentNameCN)) {
relevanceScore += 20
}

// 3. 检查组件列表 (权重: 15) - 提高权重,支持更多分隔符
const componentList = lowerTitle
.split(/[,;\s\[\]]+/)
.map((s) => s.trim())
.filter(Boolean)
if (componentList.includes(lowerComponentName)) {
relevanceScore += 15
}

// 4. 部分匹配 (权重: 3)
const componentWords = lowerComponentName
.split(/(?=[A-Z])/)
.map((word) => word.toLowerCase())
componentWords.forEach((word) => {
if (word.length > 1 && lowerTitle.includes(word)) {
relevanceScore += 3
}
})

// 5. 检查中文关键词匹配 (权重: 3)
const cnKeywords = componentNameCN.split(/[s,,]/).filter(Boolean)
cnKeywords.forEach((keyword) => {
if (title.includes(keyword)) {
relevanceScore += 3
}
})

// 6. 上下文语义分析 (权重: 30)
// 检查是否是组件的主要功能描述
const isMainFeature =
title.includes(`${componentName}组件`) ||
title.includes(`${componentNameCN}组件`) ||
(title.includes(componentName) && title.includes('组件'))
if (isMainFeature) {
relevanceScore += 30
}

// 相关性阈值
const RELEVANCE_THRESHOLD = 3

return {
score: relevanceScore,
isRelevant: relevanceScore >= RELEVANCE_THRESHOLD, // 只有达到阈值才算相关
details: {
commitFormat: commitFormatMatch ? commitFormatMatch[1] : null,
exactMatchEn: lowerTitle.includes(lowerComponentName),
exactMatchCn: title.includes(componentNameCN),
partialMatches: componentWords.filter(
(word) => word.length > 1 && lowerTitle.includes(word)
),
cnMatches: cnKeywords.filter((keyword) => title.includes(keyword)),
},
}
}

// 分析标题与所有组件的相关性,返回相关性最高的组件们

export function findMostRelevantComponents(title) {
let maxScore = -1
let mostRelevantComponents = []
let relevanceDetails = null

config.nav.forEach((nav) => {
nav.packages.forEach((pkg) => {
const result = analyzeTitleRelevance(title, pkg.name, pkg.cName)
if (result.score > maxScore) {
maxScore = result.score
mostRelevantComponents = [pkg]
relevanceDetails = result
} else if (result.score === maxScore && maxScore > 0) {
mostRelevantComponents.push(pkg)
}
})
})
const result = {
components: maxScore >= 15 ? mostRelevantComponents : [],
score: maxScore,
details: relevanceDetails,
}

if (result.components && result.components.length > 0) {
return result.components.map((pkg) => pkg.name)
}
return []
}

const testTitles = [
'fix: usecallback to fix render too many times, button,animatingnumbers,avatar,audio; and fix avatargroup when length > maxsize (#2628) ',
'fix(dialog): 关闭按钮默认在底部,24px白色图标 (#2118) @irisSong',
'feat(calendar): support renderBottomButton props (#2645) ',
'希望Dialog组件内置的确认以及取消按钮对异步自带loading或者可以手动设置loading #1202',
'[FR]: getSystemInfoSync 微信小程序从基础库 2.20.1 开始,本接口停止维护,需要兼容新老接口',
]

// console.log('\n相关性分析结果:')
// testTitles.forEach((title) => {
// console.log('\n标题:', title)
// const result = findMostRelevantComponents(title)
// console.log(`相关组件: ${result})}`)
// console.log(`相关性得分: ${result.score}`)
// console.log('详细信息:', result.details)
// })
17 changes: 10 additions & 7 deletions scripts/generate-changelog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const fs = require('fs-extra');
const path = require('path');
const changelog = fs.readFileSync(path.join(__dirname, '../CHANGELOG.md'), 'utf8');
const fs = require('fs-extra')
const path = require('path')
const changelog = fs.readFileSync(
path.join(__dirname, '../CHANGELOG.md'),
'utf8'
)

const a = changelog.split('# v')
console.log(a[1])
const getLatestRelease = (cl) => {
const a = changelog.split('# v')
if(a.length === 0) return ''
if (a.length === 0) return ''
return `# v${a[1]}`

// const tag1 = cl.indexOf('#')
Expand All @@ -18,8 +21,8 @@ const getLatestRelease = (cl) => {
// }
// return ''
}
let res = getLatestRelease(changelog);
let res = getLatestRelease(changelog)
if (res) {
res += `\n> [CHANGELOG](https://github.com/jdf2e/nutui-react/blob/next/CHANGELOG.md)\n`
fs.writeFileSync('.github/changelog.md', res);
}
fs.writeFileSync('.github/changelog.md', res)
}
166 changes: 166 additions & 0 deletions scripts/generate-contribution.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* description: 生成Contribution数据
*/
import axios from 'axios'
import * as fs from 'fs'
import * as path from 'path'
import { findMostRelevantComponents } from './analyze-title-relevance.mjs'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import config from '../src/config.json' assert { type: 'json' }
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const GITHUB_API = {
BASE_URL: 'https://api.github.com/repos/jdf2e/nutui-react',
REPO_URL: 'https://github.com/jdf2e/nutui-react/',
HEADERS: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${TOKEN}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个 token 怎么弄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/settings/tokens. 在这里生成Generate new token(classic)复制进去

},
}

const headers = GITHUB_API.HEADERS
const coms = config.nav
.map((i) => i.packages)
.flat(Infinity)
.filter((i) => i.show)

async function generateContribution(componentName) {
try {
const issuesResponse = await axios.get(
'https://api.github.com/repos/jdf2e/nutui-react/issues',
{
params: {
state: 'closed',
sort: 'updated',
direction: 'desc',
per_page: 1000,
is: 'issue',
},
headers,
}
)

const issues = issuesResponse.data
.filter(
(issue) =>
!issue.pull_request &&
findMostRelevantComponents(issue.title).includes(componentName)
)
.slice(0, 5)
.map((issue) => ({
title: issue.title,
url: issue.html_url,
number: issue.number,
}))

const releasesResponse = await axios.get(
'https://api.github.com/repos/jdf2e/nutui-react/releases',
{
params: {
per_page: 100,
},
headers,
}
)

const releases = releasesResponse.data
.reduce((acc, release) => {
const buttonUpdates = release.body
.split('\n')
.filter((line) => {
return findMostRelevantComponents(line).includes(componentName)
})
.map((line) => {
let processedLine = line.replace(/^[*\s-]*/, '').replace(':art')
let type = 'others'
if (processedLine.includes(':bug:')) {
type = 'fix'
processedLine = processedLine.replace(':bug:', '')
}
if (processedLine.includes(':sparkles:')) {
type = 'feat'
processedLine = processedLine.replace(':sparkles:', '')
}

const symbols = {
feat: '✨ ',
fix: '🐛 ',
docs: '📖 ',
style: '🎨 ',
perf: '⚡️ ',
others: '💡 ',
}

let processedContent = processedLine
.trim()
.replace(/^(feat|fix|docs|style|perf):\s*/, '')

const prMatch = processedContent.match(/#(\d+)/)
if (prMatch) {
const prNumber = prMatch[1]
processedContent = processedContent.replace(
`#${prNumber}`,
`[#${prNumber}](https://github.com/jdf2e/nutui-react/pull/${prNumber})`
)
}

// 检查是否已经包含表情符号
const hasEmoji = /[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test(processedContent)

return {
version: release.tag_name,
type,
content: hasEmoji ? processedContent : `${symbols[type]}${processedContent}`,
rawContent: processedContent,
tagName: release.tag_name,
}
})
return [...acc, ...buttonUpdates]
}, [])
.slice(0, 5)

// 生成结构化数据
const contributionData = {
issues: {
[componentName]: issues,
},
logs: {
[componentName]: releases,
},
}

return contributionData
} catch (error) {
console.error(error.message)
}
}

Promise.all(coms.map((i) => generateContribution(i.name)))
.then((results) => {
const allContributions = results.reduce(
(acc, curr, index) => {
if (curr) {
const componentName = coms[index].name
acc.issues[componentName] = curr.issues[componentName]
acc.logs[componentName] = curr.logs[componentName]
}
return acc
},
{ issues: {}, logs: {} }
)

// 将数据写入到 JSON 文件
const outputPath = path.resolve(
__dirname,
'../src/sites/doc/components/contribution/contribution.json'
)
fs.writeFileSync(
outputPath,
JSON.stringify(allContributions, null, 2),
'utf8'
)
console.log('已成功写入到:', outputPath)
})
.catch((error) => console.error('获取贡献数据失败:', error))
2 changes: 2 additions & 0 deletions src/packages/actionsheet/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ The component provides the following CSS variables, which can be used to customi
| \--nutui-actionsheet-item-line-height | item line height | `24px` |
| \--nutui-actionsheet-item-color | item color | `$color-title` |
| \--nutui-actionsheet-item-danger | item danger color | `$color-primary` |

<Contribution name="ActionSheet" />
2 changes: 2 additions & 0 deletions src/packages/actionsheet/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ import { ActionSheet } from '@nutui/nutui-react'
| \--nutui-actionsheet-item-line-height | 列表项行高 | `24px` |
| \--nutui-actionsheet-item-color | 列表项字色 | `$color-title` |
| \--nutui-actionsheet-item-danger | 列表项danger字色 | `$color-primary` |

<Contribution name="ActionSheet" />
2 changes: 2 additions & 0 deletions src/packages/actionsheet/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ import { ActionSheet } from '@nutui/nutui-react-taro'
| \--nutui-actionsheet-item-line-height | 列表项行高 | `24px` |
| \--nutui-actionsheet-item-color | 列表项字色 | `$color-title` |
| \--nutui-actionsheet-item-danger | 列表项danger字色 | `$color-primary` |

<Contribution name="ActionSheet" />
2 changes: 2 additions & 0 deletions src/packages/actionsheet/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ import { ActionSheet } from '@nutui/nutui-react'
| \--nutui-actionsheet-item-line-height | 列錶項行高 | `24px` |
| \--nutui-actionsheet-item-color | 列錶項字色 | `$color-title` |
| \--nutui-actionsheet-item-danger | 列錶項danger字色 | `$color-primary` |

<Contribution name="ActionSheet" />
2 changes: 2 additions & 0 deletions src/packages/address/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ You can get the Address instance and call instance methods through ref.
| close | Close address selection | `-` |

More properties in Cascader.

<Contribution name="Address" />
2 changes: 2 additions & 0 deletions src/packages/address/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ import { Address } from '@nutui/nutui-react'
| close | 关闭地址选择 | `-` |

更多参数可参考 `Cascader` 组件。

<Contribution name="Address" />
2 changes: 2 additions & 0 deletions src/packages/address/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ import { Address } from '@nutui/nutui-react-taro'
| close | 关闭地址选择 | `-` |

更多参数可参考 `Cascader` 组件。

<Contribution name="Address" />
2 changes: 2 additions & 0 deletions src/packages/address/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ import { Address } from '@nutui/nutui-react'
| close | 關閉地址選擇 | `-` |

更多參數可參考 `Cascader` 組件。

<Contribution name="Address" />
2 changes: 2 additions & 0 deletions src/packages/animate/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ import { Animate } from '@nutui/nutui-react'
| 9 | jump | jump,It is recommended that loop be true |
| 10 | twinkle | twinkle,It is recommended that loop be true |
| 11 | flicker | Polish button,It is recommended that loop be true |

<Contribution name="Animate" />
2 changes: 2 additions & 0 deletions src/packages/animate/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ import { Animate } from '@nutui/nutui-react'
| 9 | jump | 跳跃,建议loop为true |
| 10 | twinkle | 水波,建议loop为true |
| 11 | flicker | 擦亮按钮,建议loop为true |

<Contribution name="Animate" />
2 changes: 2 additions & 0 deletions src/packages/animate/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ import { Animate } from '@nutui/nutui-react-taro'
| 9 | jump | 跳跃,建议loop为true |
| 10 | twinkle | 水波,建议loop为true |
| 11 | flicker | 擦亮按钮,建议loop为true |

<Contribution name="Animate" />
Loading
Loading