diff --git a/.changeset/wicked-radios-tease.md b/.changeset/wicked-radios-tease.md new file mode 100644 index 000000000..b2a64e386 --- /dev/null +++ b/.changeset/wicked-radios-tease.md @@ -0,0 +1,5 @@ +--- +'@keystatic/core': patch +--- + +Link to specific open pull request instead of search page of open pull requests diff --git a/packages/keystatic/src/app/dashboard/BranchSection.tsx b/packages/keystatic/src/app/dashboard/BranchSection.tsx index 584826d55..82632af32 100644 --- a/packages/keystatic/src/app/dashboard/BranchSection.tsx +++ b/packages/keystatic/src/app/dashboard/BranchSection.tsx @@ -64,7 +64,7 @@ export function BranchSection(props: { config: Config }) { )} - {!isDefaultBranch && ( + {!isDefaultBranch && branchInfo.pullRequestNumber === undefined ? ( {localizedString.format('createPullRequest')} + ) : ( + + + Pull request #{branchInfo.pullRequestNumber} + )} diff --git a/packages/keystatic/src/app/shell/data.tsx b/packages/keystatic/src/app/shell/data.tsx index 5b8822344..af0b982c8 100644 --- a/packages/keystatic/src/app/shell/data.tsx +++ b/packages/keystatic/src/app/shell/data.tsx @@ -323,6 +323,8 @@ export function GitHubAppShellProvider(props: { }), [baseCommit, repo?.id] ); + const pullRequestNumber = + currentBranchRef?.associatedPullRequests.nodes?.[0]?.number; const branchInfo = useMemo( () => ({ defaultBranch: repo?.defaultBranchRef?.name ?? '', @@ -330,7 +332,7 @@ export function GitHubAppShellProvider(props: { baseCommit: baseCommit || '', repositoryId: repo?.id ?? '', allBranches: repo?.refs?.nodes?.map(x => x?.name).filter(isDefined) ?? [], - hasPullRequests: !!currentBranchRef?.associatedPullRequests.totalCount, + pullRequestNumber, branchNameToId: new Map( repo?.refs?.nodes?.filter(isDefined).map(x => [x.name, x.id]) ), @@ -348,7 +350,7 @@ export function GitHubAppShellProvider(props: { repo?.refs?.nodes, props.currentBranch, baseCommit, - currentBranchRef?.associatedPullRequests.totalCount, + pullRequestNumber, data?.repository?.owner.login, data?.repository?.name, ] @@ -462,8 +464,11 @@ export const Ref_base = gql` } } } - associatedPullRequests(states: [OPEN]) { - totalCount + associatedPullRequests(states: [OPEN], first: 1) { + nodes { + id + number + } } } ` as import('../../../__generated__/ts-gql/Ref_base').type; @@ -605,7 +610,7 @@ export const BranchInfoContext = createContext<{ allBranches: string[]; branchNameToId: Map; defaultBranch: string; - hasPullRequests: boolean; + pullRequestNumber: number | undefined; branchNameToBaseCommit: Map; mainOwner: string; mainRepo: string; @@ -613,7 +618,7 @@ export const BranchInfoContext = createContext<{ currentBranch: '', allBranches: [], defaultBranch: '', - hasPullRequests: false, + pullRequestNumber: undefined, branchNameToId: new Map(), branchNameToBaseCommit: new Map(), mainOwner: '', diff --git a/packages/keystatic/src/app/shell/topbar.tsx b/packages/keystatic/src/app/shell/topbar.tsx index 1b73d3aea..dfc32b94e 100644 --- a/packages/keystatic/src/app/shell/topbar.tsx +++ b/packages/keystatic/src/app/shell/topbar.tsx @@ -15,7 +15,6 @@ import { Avatar } from '@keystar/ui/avatar'; import { ActionButton, Button } from '@keystar/ui/button'; import { AlertDialog, DialogContainer } from '@keystar/ui/dialog'; import { Icon } from '@keystar/ui/icon'; -import { listTodoIcon } from '@keystar/ui/icon/icons/listTodoIcon'; import { logOutIcon } from '@keystar/ui/icon/icons/logOutIcon'; import { gitPullRequestIcon } from '@keystar/ui/icon/icons/gitPullRequestIcon'; import { gitBranchPlusIcon } from '@keystar/ui/icon/icons/gitBranchPlusIcon'; @@ -471,12 +470,20 @@ function GitMenu() { ]; if (!isDefaultBranch) { - prSection.push({ - key: 'create-pull-request', - icon: gitPullRequestIcon, - label: stringFormatter.format('createPullRequest'), - }); - if (!data.hasPullRequests) { + if (data.pullRequestNumber === undefined) { + prSection.push({ + key: 'create-pull-request', + icon: gitPullRequestIcon, + label: stringFormatter.format('createPullRequest'), + }); + } else { + prSection.push({ + key: 'view-pull-request', + icon: gitPullRequestIcon, + label: `Pull Request #${data.pullRequestNumber}`, + }); + } + if (data.pullRequestNumber === undefined) { branchSection.push({ key: 'delete-branch', icon: trash2Icon, @@ -484,14 +491,6 @@ function GitMenu() { }); } } - - if (data.hasPullRequests) { - prSection.push({ - key: 'related-pull-requests', - icon: listTodoIcon, - label: stringFormatter.format('viewPullRequests'), - }); - } if (fork) { repoSection.push({ key: 'fork', @@ -527,7 +526,7 @@ function GitMenu() { fork, data.currentBranch, data.defaultBranch, - data.hasPullRequests, + data.pullRequestNumber, stringFormatter, ]); const router = useRouter(); @@ -547,16 +546,10 @@ function GitMenu() { toggleDeleteBranchDialog(); break; } - case 'related-pull-requests': - let query = [ - ['is', 'pr'], - ['is', 'open'], - ['head', data.currentBranch], - ] - .map(([key, value]) => encodeURIComponent(`${key}:${value}`)) - .join('+'); - - openBlankTargetSafely(`${repoURL}/pulls?q=${query}`); + case 'view-pull-request': + openBlankTargetSafely( + `${repoURL}/pull/${data.pullRequestNumber}` + ); break; case 'create-pull-request': openBlankTargetSafely(