-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: 优化获取基准分支的算法。 #82
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
Optimize the algorithm for determining base branches by parsing the output of git show-branch and refactoring getBaseBranches to use the new parser.
- Introduces parseBaseBranchName(showBranch) to extract base branch names from git show-branch output.
- Refactors getBaseBranches to delegate to parseBaseBranchName.
- Adds unit tests covering multiple parse scenarios.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/gitremote.js | Adds parseBaseBranchName and updates getBaseBranches to use it. |
| test/gitopen.test.js | Adds tests for parseBaseBranchName with multiple scenarios. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const m = RE_CURRENT_BRANCH.exec(info[0]); | ||
| // 输入异常,没有找到当前分支。 | ||
| if (!m) { | ||
| return ''; |
Copilot
AI
Oct 17, 2025
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.
This returns a string when no current branch match is found, but the function’s JSDoc declares an Array and callers (e.g., getBaseBranches) will then receive a string. Return an empty array instead: return [];.
| return ''; | |
| return []; |
| return brs | ||
| .map(br => { | ||
| var RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" |
Copilot
AI
Oct 17, 2025
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.
The regular expression is recompiled for every line inside map, which is unnecessary. Hoist it outside the loop and use const, e.g., const RE_BASE_BRANCH_NAME = /^[ +-]\[([^\\]\^~]+)/; then reuse it inside map.
| return brs | |
| .map(br => { | |
| var RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" | |
| const RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" | |
| return brs | |
| .map(br => { |
| * @return {Array} base branch name | ||
| */ | ||
| exports.parseBaseBranchName = function(showBranch) { | ||
| // 上下上个部分使用 -- 分隔。 |
Copilot
AI
Oct 17, 2025
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.
Correct the grammar and clarify the separator to match the actual code which splits on lines of hyphens.
| // 上下上个部分使用 -- 分隔。 | |
| // 上下部分使用只包含连字符的行(如 --、--- 等)分隔。 |
| /** | ||
| * 解析 `git show-branch` 的输出,得到当前分支的基准分支。 | ||
| * @param {String} showBranch 当前分支 `git show-branch` 的输出。 | ||
| * @return {Array} base branch name |
Copilot
AI
Oct 17, 2025
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.
The return description should be plural to reflect that an array of names is returned. Suggest: @return {Array} base branch names.
| * @return {Array} base branch name | |
| * @return {Array<string>} base branch names |
No description provided.