-
Notifications
You must be signed in to change notification settings - Fork 905
kitenite/halved position #2102
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
kitenite/halved position #2102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| buildPullRequestCompareUrl, | ||
| normalizeGitHubRepoUrl, | ||
| parseUpstreamRef, | ||
| } from "./pull-request-url"; | ||
|
|
||
| describe("pull-request-url", () => { | ||
| test("normalizes GitHub remote URLs", () => { | ||
| expect( | ||
| normalizeGitHubRepoUrl("https://github.com/superset-sh/superset.git"), | ||
| ).toBe("https://github.com/superset-sh/superset"); | ||
| expect(normalizeGitHubRepoUrl("git@github.com:Kitenite/superset.git")).toBe( | ||
| "https://github.com/Kitenite/superset", | ||
| ); | ||
| expect( | ||
| normalizeGitHubRepoUrl("ssh://git@github.com/Kitenite/superset.git"), | ||
| ).toBe("https://github.com/Kitenite/superset"); | ||
| }); | ||
|
|
||
| test("parses upstream refs with slashes in branch names", () => { | ||
| expect(parseUpstreamRef("kitenite/kitenite/halved-position")).toEqual({ | ||
| remoteName: "kitenite", | ||
| branchName: "kitenite/halved-position", | ||
| }); | ||
| }); | ||
|
|
||
| test("builds compare URLs for fork branches", () => { | ||
| expect( | ||
| buildPullRequestCompareUrl({ | ||
| baseRepoUrl: "https://github.com/superset-sh/superset.git", | ||
| baseBranch: "main", | ||
| headRepoOwner: "Kitenite", | ||
| headBranch: "kitenite/halved-position", | ||
| }), | ||
| ).toBe( | ||
| "https://github.com/superset-sh/superset/compare/main...Kitenite:kitenite/halved-position?expand=1", | ||
| ); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| export interface ParsedUpstreamRef { | ||
| remoteName: string; | ||
| branchName: string; | ||
| } | ||
|
|
||
| export interface PullRequestCompareUrlInput { | ||
| baseRepoUrl: string; | ||
| baseBranch: string; | ||
| headRepoOwner: string; | ||
| headBranch: string; | ||
| } | ||
|
|
||
| export function normalizeGitHubRepoUrl(remoteUrl: string): string | null { | ||
| const trimmedRemoteUrl = remoteUrl.trim(); | ||
| const match = [ | ||
| /^git@github\.com:(?<owner>[^/]+)\/(?<repo>[^/]+?)(?:\.git)?$/, | ||
| /^ssh:\/\/git@github\.com\/(?<owner>[^/]+)\/(?<repo>[^/]+?)(?:\.git)?$/, | ||
| /^https:\/\/github\.com\/(?<owner>[^/]+)\/(?<repo>[^/]+?)(?:\.git)?\/?$/, | ||
| ] | ||
| .map((pattern) => pattern.exec(trimmedRemoteUrl)) | ||
| .find((result) => result?.groups?.owner && result.groups.repo); | ||
|
|
||
| if (!match?.groups?.owner || !match.groups.repo) { | ||
| return null; | ||
| } | ||
|
|
||
| return `https://github.com/${match.groups.owner}/${match.groups.repo}`; | ||
| } | ||
|
|
||
| export function parseUpstreamRef( | ||
| upstreamRef: string, | ||
| ): ParsedUpstreamRef | null { | ||
| const separatorIndex = upstreamRef.indexOf("/"); | ||
| if (separatorIndex <= 0 || separatorIndex === upstreamRef.length - 1) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| remoteName: upstreamRef.slice(0, separatorIndex), | ||
| branchName: upstreamRef.slice(separatorIndex + 1), | ||
| }; | ||
| } | ||
|
|
||
| export function buildPullRequestCompareUrl({ | ||
| baseRepoUrl, | ||
| baseBranch, | ||
| headRepoOwner, | ||
| headBranch, | ||
| }: PullRequestCompareUrlInput): string { | ||
| const normalizedBaseRepoUrl = | ||
| normalizeGitHubRepoUrl(baseRepoUrl) ?? | ||
| baseRepoUrl.replace(/\.git$/, "").replace(/\/$/, ""); | ||
|
|
||
| return `${normalizedBaseRepoUrl}/compare/${baseBranch}...${headRepoOwner}:${headBranch}?expand=1`; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,7 @@ import { ChangesHeader } from "./components/ChangesHeader"; | |||||
| import { CommitInput } from "./components/CommitInput"; | ||||||
| import { CommitItem } from "./components/CommitItem"; | ||||||
| import { FileList } from "./components/FileList"; | ||||||
| import { getPRActionState } from "./utils"; | ||||||
| import { getPRActionState, shouldAutoCreatePRAfterPublish } from "./utils"; | ||||||
|
|
||||||
| interface ChangesViewProps { | ||||||
| onFileOpen?: ( | ||||||
|
|
@@ -364,8 +364,10 @@ export function ChangesView({ onFileOpen, isExpandedView }: ChangesViewProps) { | |||||
| pullCount: status.pullCount, | ||||||
| isDefaultBranch, | ||||||
| }); | ||||||
| const shouldAutoCreatePRAfterPublish = | ||||||
| hasGitHubRepo && !isDefaultBranch && !hasExistingPR; | ||||||
| const shouldAutoCreatePR = shouldAutoCreatePRAfterPublish({ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Bug: Prompt for AI agents
Suggested change
|
||||||
| hasExistingPR, | ||||||
| isDefaultBranch, | ||||||
| }); | ||||||
|
|
||||||
| return ( | ||||||
| <div className="flex flex-col flex-1 min-h-0"> | ||||||
|
|
@@ -398,7 +400,7 @@ export function ChangesView({ onFileOpen, isExpandedView }: ChangesViewProps) { | |||||
| hasUpstream={status.hasUpstream} | ||||||
| hasExistingPR={hasExistingPR} | ||||||
| canCreatePR={prActionState.canCreatePR} | ||||||
| shouldAutoCreatePRAfterPublish={shouldAutoCreatePRAfterPublish} | ||||||
| shouldAutoCreatePRAfterPublish={shouldAutoCreatePR} | ||||||
| prUrl={prUrl} | ||||||
| onRefresh={handleRefresh} | ||||||
| /> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { shouldAutoCreatePRAfterPublish } from "./auto-create-pr-after-publish"; | ||
|
|
||
| describe("shouldAutoCreatePRAfterPublish", () => { | ||
| test("auto-creates after publishing on a non-default branch without an existing PR", () => { | ||
| expect( | ||
| shouldAutoCreatePRAfterPublish({ | ||
| hasExistingPR: false, | ||
| isDefaultBranch: false, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("does not auto-create on the default branch", () => { | ||
| expect( | ||
| shouldAutoCreatePRAfterPublish({ | ||
| hasExistingPR: false, | ||
| isDefaultBranch: true, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("does not auto-create when a PR already exists", () => { | ||
| expect( | ||
| shouldAutoCreatePRAfterPublish({ | ||
| hasExistingPR: true, | ||
| isDefaultBranch: false, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| interface AutoCreatePRAfterPublishInput { | ||
| hasExistingPR: boolean; | ||
| isDefaultBranch: boolean; | ||
| } | ||
|
|
||
| export function shouldAutoCreatePRAfterPublish({ | ||
| hasExistingPR, | ||
| isDefaultBranch, | ||
| }: AutoCreatePRAfterPublishInput): boolean { | ||
| return !hasExistingPR && !isDefaultBranch; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { shouldAutoCreatePRAfterPublish } from "./auto-create-pr-after-publish"; | ||
| export { formatRelativeDate } from "./date"; | ||
| export { getPRActionState } from "./pr-action-state"; | ||
| export { getStatusColor, getStatusIndicator } from "./status"; |
Uh oh!
There was an error while loading. Please reload this page.
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.
P2: Empty catch block silently swallows errors from multiple git operations (upstream ref resolution and remote URL lookup). At minimum, log a warning with context so fork/upstream debugging is possible.
(Based on your team's feedback about avoiding empty catch blocks that hide failures.)
View Feedback
Prompt for AI agents