-
Notifications
You must be signed in to change notification settings - Fork 0
[#42] baseBranch를 포함한 branch 비교 조합을 구성한다 #56
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { | ||
| BranchComparisonPair, | ||
| BranchContext | ||
| } from "./types.js" | ||
|
|
||
| // base branch와 활성 branch에서 중복 없는 비교 조합을 이름순으로 구성 | ||
| export function build( | ||
| baseBranch: string, | ||
| branches: BranchContext[] | ||
| ): BranchComparisonPair[] { | ||
| const branchNames = [...new Set([ | ||
| baseBranch, | ||
| ...branches.map(branch => branch.name) | ||
| ])].sort(compareBranchNames) | ||
| const pairs: BranchComparisonPair[] = [] | ||
|
|
||
| for (let leftIndex = 0; leftIndex < branchNames.length; leftIndex += 1) { | ||
| const leftBranchName = branchNames[leftIndex]! | ||
|
|
||
| for ( | ||
| let rightIndex = leftIndex + 1; | ||
| rightIndex < branchNames.length; | ||
| rightIndex += 1 | ||
| ) { | ||
| pairs.push({ | ||
| leftBranchName, | ||
| rightBranchName: branchNames[rightIndex]! | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return pairs | ||
| } | ||
|
|
||
| // 실행 환경에 무관한 문자열 비교로 branch 이름 순서를 결정 | ||
| function compareBranchNames(branchName: string, otherBranchName: string): number { | ||
| if (branchName < otherBranchName) { | ||
| return -1 | ||
| } | ||
|
|
||
| if (otherBranchName < branchName) { | ||
| return 1 | ||
| } | ||
|
|
||
| return 0 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import test from "node:test" | ||
| import assert from "node:assert/strict" | ||
| import { build } from "../../src/branches/branchPairBuilder.js" | ||
| import type { BranchContext } from "../../src/branches/types.js" | ||
|
|
||
| // 활성 branch가 없으면 비교 조합을 만들지 않는지 확인 | ||
| test("returns no pairs without active branches", () => { | ||
| assert.deepEqual(build("main", []), []) | ||
| }) | ||
|
|
||
| // base branch와 활성 branch 하나를 한 번만 조합하는지 확인 | ||
| test("pairs the base branch with one active branch", () => { | ||
| assert.deepEqual(build("develop", [branch("feature/watch", "develop")]), [{ | ||
| leftBranchName: "develop", | ||
| rightBranchName: "feature/watch" | ||
| }]) | ||
| }) | ||
|
|
||
| // 중복 이름과 자기 자신 조합을 제외하고 방향 없는 조합만 만드는지 확인 | ||
| test("excludes duplicate, self, and reversed pairs", () => { | ||
| const pairs = build("main", [ | ||
| branch("feature/b"), | ||
| branch("feature/a"), | ||
| branch("feature/a"), | ||
| branch("main") | ||
| ]) | ||
|
|
||
| assert.deepEqual(pairs, [{ | ||
| leftBranchName: "feature/a", | ||
| rightBranchName: "feature/b" | ||
| }, { | ||
| leftBranchName: "feature/a", | ||
| rightBranchName: "main" | ||
| }, { | ||
| leftBranchName: "feature/b", | ||
| rightBranchName: "main" | ||
| }]) | ||
| }) | ||
|
|
||
| // 입력 순서와 무관하게 branch 이름 기준의 같은 조합 순서를 만드는지 확인 | ||
| test("builds pairs in deterministic branch name order", () => { | ||
| const pairs = build("main", [ | ||
| branch("feature/z"), | ||
| branch("feature/a"), | ||
| branch("feature/m") | ||
| ]) | ||
| const reorderedPairs = build("main", [ | ||
| branch("feature/m"), | ||
| branch("feature/z"), | ||
| branch("feature/a") | ||
| ]) | ||
|
|
||
| assert.deepEqual(reorderedPairs, pairs) | ||
| assert.deepEqual(pairs[0], { | ||
| leftBranchName: "feature/a", | ||
| rightBranchName: "feature/m" | ||
| }) | ||
| assert.deepEqual(pairs.at(-1), { | ||
| leftBranchName: "feature/z", | ||
| rightBranchName: "main" | ||
| }) | ||
| }) | ||
|
|
||
| // 지역화 규칙이 아닌 문자열 비교로 대소문자 branch 순서를 고정하는지 확인 | ||
| test("uses non-localized string comparison", () => { | ||
| const pairs = build("main", [ | ||
| branch("feature/a"), | ||
| branch("feature/Z") | ||
| ]) | ||
|
|
||
| assert.deepEqual(pairs, [{ | ||
| leftBranchName: "feature/Z", | ||
| rightBranchName: "feature/a" | ||
| }, { | ||
| leftBranchName: "feature/Z", | ||
| rightBranchName: "main" | ||
| }, { | ||
| leftBranchName: "feature/a", | ||
| rightBranchName: "main" | ||
| }]) | ||
| }) | ||
|
|
||
| // 활성 branch 30개와 base branch에서 최대 465개 조합을 만드는지 확인 | ||
| test("builds 465 pairs for 30 active branches", () => { | ||
| const branches = Array.from({ length: 30 }, (_, index) => | ||
| branch(`feature/${String(index).padStart(2, "0")}`) | ||
| ) | ||
|
|
||
| const pairs = build("main", branches) | ||
|
|
||
| assert.equal(pairs.length, 465) | ||
| assert.equal(new Set(pairs.map(pair => | ||
| `${pair.leftBranchName}\u0000${pair.rightBranchName}` | ||
| )).size, 465) | ||
| }) | ||
|
|
||
| function branch(name: string, baseBranch = "main"): BranchContext { | ||
| return { | ||
| baseBranch, | ||
| name, | ||
| headSha: `${name}-sha`, | ||
| checks: [] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.