Skip to content

Conversation

@hotoo
Copy link
Owner

@hotoo hotoo commented Nov 1, 2020

No description provided.

@hotoo hotoo requested a review from Copilot October 17, 2025 01:04
Copy link

Copilot AI left a 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 '';
Copy link

Copilot AI Oct 17, 2025

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 [];.

Suggested change
return '';
return [];

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +120
return brs
.map(br => {
var RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint"
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change
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 => {

Copilot uses AI. Check for mistakes.
* @return {Array} base branch name
*/
exports.parseBaseBranchName = function(showBranch) {
// 上下上个部分使用 -- 分隔。
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change
// 上下上个部分使用 -- 分隔。
// 上下部分使用只包含连字符的行(如 --、--- 等)分隔。

Copilot uses AI. Check for mistakes.
/**
* 解析 `git show-branch` 的输出,得到当前分支的基准分支。
* @param {String} showBranch 当前分支 `git show-branch` 的输出。
* @return {Array} base branch name
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change
* @return {Array} base branch name
* @return {Array<string>} base branch names

Copilot uses AI. Check for mistakes.
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