mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-06 18:00:18 +09:00
Backport #39612 * Fix #39610 * Regression of #39262 Also, the old code is very fragile: `#branch_target` is from translation string, so refactored it together Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -103,7 +103,7 @@
|
||||
{{svg "octicon-arrow-right"}}
|
||||
<div class="ui floating dropdown" data-no-results="{{ctx.Locale.Tr "no_results_found"}}">
|
||||
<div class="ui basic small button">
|
||||
<span id="pull-target-branch" class="gt-ellipsis" data-base-user-name="{{$baseUserName}}" data-text-compare-base="{{ctx.Locale.Tr "repo.pulls.compare_base"}}">
|
||||
<span id="pull-target-branch" class="gt-ellipsis" data-base-user-name="{{$baseUserName}}" data-old-target-branch="{{$baseBranch}}" data-branch="{{$baseBranch}}" data-text-compare-base="{{ctx.Locale.Tr "repo.pulls.compare_base"}}">
|
||||
{{ctx.Locale.Tr "repo.pulls.compare_base"}}: {{$baseUserName}}:{{$baseBranch}}
|
||||
</span>
|
||||
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user