diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl
index d6df337c28f..d6b2fd9545c 100644
--- a/templates/repo/issue/view_title.tmpl
+++ b/templates/repo/issue/view_title.tmpl
@@ -103,7 +103,7 @@
{{svg "octicon-arrow-right"}}
-
+
{{ctx.Locale.Tr "repo.pulls.compare_base"}}: {{$baseUserName}}:{{$baseBranch}}
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
diff --git a/tests/e2e/pr-create.test.ts b/tests/e2e/pr-create.test.ts
index 662bd42af1c..6e9d29ffec5 100644
--- a/tests/e2e/pr-create.test.ts
+++ b/tests/e2e/pr-create.test.ts
@@ -1,8 +1,8 @@
import {env} from 'node:process';
import {test, expect} from '@playwright/test';
-import {login, apiCreateRepo, apiCreateFiles, randomString} from './utils.ts';
+import {login, apiCreateRepo, apiCreateFiles, apiCreatePR, randomString} from './utils.ts';
-test('create a pull request from the compare page', async ({page, request}) => {
+test('create a pull request from the compare page and edit its title', async ({page, request}) => {
const repoName = `e2e-pr-create-${randomString(8)}`;
const owner = env.GITEA_TEST_E2E_USER;
await apiCreateRepo(request, {name: repoName});
@@ -17,7 +17,33 @@ test('create a pull request from the compare page', async ({page, request}) => {
await page.getByPlaceholder('Title').fill(title);
await page.getByRole('button', {name: 'Create Pull Request'}).click();
- // commit, not full load: the PR title heading is server-rendered, so the assertion can resolve before the heavy diff/timeline finishes
- await page.waitForURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+$`), {waitUntil: 'commit'});
+ await page.waitForURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+$`), {waitUntil: 'domcontentloaded'});
await expect(page.getByRole('heading', {name: title})).toBeVisible();
+
+ const titleEditor = page.locator('#issue-title-editor');
+ await page.locator('#issue-title-display').getByRole('button', {name: 'Edit'}).click();
+ await titleEditor.getByRole('textbox').fill('edited title');
+ await titleEditor.getByRole('button', {name: 'Save'}).click();
+ await expect(page.getByRole('heading', {name: 'edited title'})).toBeVisible();
+});
+
+test('change the target branch of a pull request', async ({page, request}) => {
+ const repoName = `e2e-pr-target-${randomString(8)}`;
+ const owner = env.GITEA_TEST_E2E_USER;
+ const createPR = (async () => {
+ await apiCreateRepo(request, {name: repoName});
+ await Promise.all([
+ apiCreateFiles(request, owner, repoName, [{path: 'feat.txt', content: 'feature content\n'}], {branch: 'main', newBranch: 'feat'}),
+ apiCreateFiles(request, owner, repoName, [{path: 'release.txt', content: 'release content\n'}], {branch: 'main', newBranch: 'release'}),
+ ]);
+ return apiCreatePR(request, owner, repoName, 'feat', 'main', 'title');
+ })();
+ const [index] = await Promise.all([createPR, login(page)]);
+ await page.goto(`/${owner}/${repoName}/pulls/${index}`, {waitUntil: 'domcontentloaded'});
+
+ await page.locator('#issue-title-display').getByRole('button', {name: 'Edit'}).click();
+ await page.locator('#pull-target-branch').click();
+ await page.locator('#branch-select').getByText(`${owner}:release`).click();
+ await page.locator('#issue-title-editor').getByRole('button', {name: 'Save'}).click();
+ await expect(page.locator('#pull-desc-display')).toContainText('into release');
});
diff --git a/web_src/js/features/repo-issue.ts b/web_src/js/features/repo-issue.ts
index f7c445a1118..1fb2a2ce37e 100644
--- a/web_src/js/features/repo-issue.ts
+++ b/web_src/js/features/repo-issue.ts
@@ -397,12 +397,13 @@ export function initRepoIssueTitleEdit() {
});
const pullDescEditor = document.querySelector('#pull-desc-editor'); // it may not exist for a merged PR
+ const pullTargetBranch = document.querySelector('#pull-target-branch');
const prTargetUpdateUrl = pullDescEditor?.getAttribute('data-target-update-url');
pullDescEditor?.querySelector('#branch-select')?.addEventListener('click', (e: Event) => {
const el = (e.target as HTMLElement).closest('.item[data-branch]');
if (!el) return;
- const pullTargetBranch = pullDescEditor.querySelector('#pull-target-branch')!;
+ if (!pullTargetBranch) throw new Error('pullTargetBranch not found');
const textCompareBase = pullTargetBranch.getAttribute('data-text-compare-base')!;
const baseUserName = pullTargetBranch.getAttribute('data-base-user-name')!;
const branchNameNew = el.getAttribute('data-branch')!;
@@ -422,8 +423,9 @@ export function initRepoIssueTitleEdit() {
}
}
if (prTargetUpdateUrl) {
- const newTargetBranch = document.querySelector('#pull-target-branch')!.getAttribute('data-branch');
- const oldTargetBranch = document.querySelector('#branch_target')!.textContent;
+ if (!pullTargetBranch) throw new Error('pullTargetBranch not found');
+ const newTargetBranch = pullTargetBranch.getAttribute('data-branch');
+ const oldTargetBranch = pullTargetBranch.getAttribute('data-old-target-branch');
if (newTargetBranch !== oldTargetBranch) {
const resp = await POST(prTargetUpdateUrl, {data: new URLSearchParams({target_branch: String(newTargetBranch)})});
if (!resp.ok) {