Merge "Allow optionally submitting a whole topic"
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 5d621f2..a72221f 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt
@@ -2089,8 +2089,23 @@ [[change.submitWholeTopic]]change.submitWholeTopic:: + -Determines if the submit button submits the whole topic instead of -just the current change. +Deprecated in favor of link:#change.enforceWholeTopicSubmit[enforceWholeTopicSubmit]. ++ +Determines if the submit button enforces submitting the whole topic +instead of just the current change. If disabled, the option to submit +the whole topic still exists. ++ +Default is `false`. + +[[change.enforceWholeTopicSubmit]]change.enforceWholeTopicSubmit:: ++ +Determines if the submit button enforces submitting the whole topic +instead of just the current change. If disabled, the option to submit +the whole topic still exists. ++ +Replaces link:#change.submitWholeTopic[submitWholeTopic] to provide +a clear naming. If one of these options is `true`, submitting the +whole topic will be enforced. + Default is `false`.
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 8106363..d9e9618 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt
@@ -2026,9 +2026,11 @@ part of the response. Changes that will also be submitted: -1. All changes of the same topic if -link:config-gerrit.html#change.submitWholeTopic[`change.submitWholeTopic`] -configuration is set to true. +1. All changes of the same topic if one of +link:config-gerrit.html#change.submitWholeTopic[`change.submitWholeTopic`] or +link:config-gerrit.html#change.enforceWholeTopicSubmit[`change.enforceWholeTopicSubmit`] +is set to `true`, or if `submit_whole_topic` is set to `true` in the +request body. 2. All dependent changes. 3. The closure of the above (e.g if a dependent change has a topic, all changes of *that* topic will also be submitted). @@ -5477,9 +5479,11 @@ part of the response. Changes that will also be submitted: -1. All changes of the same topic if -link:config-gerrit.html#change.submitWholeTopic[`change.submitWholeTopic`] -configuration is set to true. +1. All changes of the same topic if one of +link:config-gerrit.html#change.submitWholeTopic[`change.submitWholeTopic`] or +link:config-gerrit.html#change.enforceWholeTopicSubmit[`change.enforceWholeTopicSubmit`] +is set to `true`, or if `submit_whole_topic` is set to `true` in the +request body. 2. All dependent changes. 3. The closure of the above (e.g if a dependent change has a topic, all changes of *that* topic will also be submitted). @@ -5522,6 +5526,97 @@ "revision 674ac754f91e64a0efb8087e59a176484bd534d1 is not current revision" ---- +[[submit-whole-topic-guarantees]] +=== Submit Whole Topic: Guarantees and Limitations + +This section documents what Gerrit guarantees when +the `submit_whole_topic` field in link:#submit-input[SubmitInput] is +set to `true`, and what it explicitly cannot guarantee. + +==== What is guaranteed + +[[submit-whole-topic-guarantee-permission]] +Permissions:: +The caller must have submit permission on every change in the topic +closure before any ref is written. If any permission check fails the +entire operation is rejected with `403 Forbidden` or `409 Conflict` +(depending on which change lacks permission) and no changes are merged. + +[[submit-whole-topic-guarantee-submit-rules]] +Submit rules:: +Every change in the topic closure is checked against its project's +submit rules before any ref is written. If any change is not ready the +entire operation is rejected with `409 Conflict` and no changes are +merged. + +[[submit-whole-topic-guarantee-single-project]] +Atomicity within a single project:: +When all changes in the topic closure belong to the *same* project, +their refs are updated in a single +link:https://git-scm.com/docs/git-push[atomic batch ref update]. Either +all refs are written or none are. + +[[submit-whole-topic-guarantee-retry]] +Retry on concurrent modification:: +If a concurrent submit causes a ref-lock conflict during the operation, +Gerrit retries the whole submission automatically. On retry, changes +that were already merged by the concurrent submit are silently skipped +(`allowMerged=true`), and only the remaining open changes are +completed. This means a temporary race does not cause the operation to +fail permanently. + +[[submit-whole-topic-guarantee-ancestors]] +Unmerged ancestors:: +For each change in the topic whose submit strategy is not +`CHERRY_PICK`, all unmerged ancestor changes targeting the same branch +are also included in the submission, exactly as for a regular submit. + +[[submit-whole-topic-guarantee-open-only]] +Only open changes are submitted:: +The topic closure is computed from open changes only. Changes in the +topic that are already merged at the time the operation starts are +ignored and do not cause the operation to fail. + +==== What cannot be guaranteed + +[[submit-whole-topic-no-guarantee-cross-project]] +No atomicity across projects:: +When the topic closure spans *multiple* projects, each project's refs +are written in a *separate* batch ref update. These per-project updates +are applied sequentially and are not coordinated with each other. +If project A succeeds but project B subsequently fails (for example +after retries are exhausted), the changes in project A remain merged +and the changes in project B remain open. There is no automatic +rollback. ++ +This is an inherent limitation of Git's ref-locking model: a single +atomic transaction cannot span multiple repositories. + +[[submit-whole-topic-no-guarantee-new-changes]] +Changes added to the topic after submission starts:: +The topic closure is computed once when the request is received. Any +change whose topic is set to the same value after that point is not +included in the current operation. There is no mechanism to wait for or +retry with an extended closure. + +[[submit-whole-topic-no-guarantee-concurrent-single-submit]] +Isolation from concurrent single-change submits:: +Nothing prevents another user from submitting individual changes from +the same topic concurrently. Such concurrent submits are not +blocked or rolled back. If the triggering change itself is merged by a +concurrent submit before this operation runs, the operation returns +`409 Conflict`. + +[[submit-whole-topic-no-guarantee-response-change]] +The response change may not be the only one submitted:: +The `200 OK` response body contains the +link:#change-info[ChangeInfo] for the triggering change only. Other +changes in the topic closure are submitted in the same operation but +are not individually enumerated in the response. Use +link:#submitted-together[Changes Submitted Together] (with +`o=TOPIC_CLOSURE`) before calling this endpoint to enumerate the full +set of changes that will be included. + [[get-patch]] === Get Patch -- @@ -10048,6 +10143,9 @@ link:#notify-info[NotifyInfo] entity. |`wait_for_merge`|optional| Deprecated and no longer used. Kept for backwards compatibility. +|`submit_whole_topic`|optional| +If `true`, all open changes that share the topic of the submitted change +are also submitted together in a single operation. Defaults to `false`. |============================= [[submit-record]]
diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt index 5088a8a..36ba175 100644 --- a/Documentation/rest-api-config.txt +++ b/Documentation/rest-api-config.txt
@@ -2320,8 +2320,11 @@ link:config-gerrit.html#change.updateDelay[How often in seconds the web interface should poll for updates to the currently open change]. |`submit_whole_topic` |not set if `false`| -link:config-gerrit.html#change.submitWholeTopic[A configuration if -the whole topic is submitted]. +link:config-gerrit.html#change.submitWholeTopic[Configuration that enforces +the whole topic to be submitted]. Deprecated; use `enforce_whole_topic_submit`. +|`enforce_whole_topic_submit` |not set if `false`| +link:config-gerrit.html#change.enforceWholeTopicSubmit[Configuration that enforces +the whole topic to be submitted]. |`disable_private_changes` |not set if `false`| Returns true if private changes are disabled. |`mergeability_computation_behavior` ||
diff --git a/java/com/google/gerrit/extensions/api/changes/SubmitInput.java b/java/com/google/gerrit/extensions/api/changes/SubmitInput.java index f820318..a88690f 100644 --- a/java/com/google/gerrit/extensions/api/changes/SubmitInput.java +++ b/java/com/google/gerrit/extensions/api/changes/SubmitInput.java
@@ -24,4 +24,5 @@ public NotifyHandling notify = NotifyHandling.ALL; public Map<RecipientType, NotifyInfo> notifyDetails; + public boolean submitWholeTopic; }
diff --git a/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java b/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java index c967946..03fd463 100644 --- a/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java +++ b/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java
@@ -19,7 +19,17 @@ public Boolean allowBlame; public Boolean disablePrivateChanges; public int updateDelay; - public Boolean submitWholeTopic; + + /** + * Backward-compatible boolean + * + * @deprecated Use {@link #enforceWholeTopicSubmit} instead. + */ + @Deprecated public Boolean submitWholeTopic; + + /** Preferred alternative to {@link #submitWholeTopic}. */ + public Boolean enforceWholeTopicSubmit; + public String mergeabilityComputationBehavior; public Boolean conflictsPredicateEnabled; public Boolean allowMarkdownBase64ImagesInComments;
diff --git a/java/com/google/gerrit/server/restapi/change/Submit.java b/java/com/google/gerrit/server/restapi/change/Submit.java index 6056d01..caa765d 100644 --- a/java/com/google/gerrit/server/restapi/change/Submit.java +++ b/java/com/google/gerrit/server/restapi/change/Submit.java
@@ -125,7 +125,7 @@ private final ParameterizedString titlePatternWithAncestors; private final String submitTopicLabel; private final ParameterizedString submitTopicTooltip; - private final boolean submitWholeTopic; + private final boolean enforceWholeTopicSubmit; private final Provider<InternalChangeQuery> queryProvider; private final ChangeJson.Factory json; private final ChangeData.Factory changeDataFactory; @@ -170,7 +170,7 @@ MoreObjects.firstNonNull( cfg.getString("change", null, "submitTooltipAncestors"), DEFAULT_TOOLTIP_ANCESTORS)); - submitWholeTopic = MergeSuperSet.wholeTopicEnabled(cfg); + enforceWholeTopicSubmit = MergeSuperSet.isWholeTopicSubmitEnforced(cfg); this.submitTopicLabel = MoreObjects.firstNonNull( Strings.emptyToNull(cfg.getString("change", null, "submitTopicLabel")), @@ -331,7 +331,8 @@ if (!Strings.isNullOrEmpty(topic)) { topicSize = queryProvider.get().noFields().byTopicOpen(topic).size(); } - boolean treatWithTopic = submitWholeTopic && !Strings.isNullOrEmpty(topic) && topicSize > 1; + boolean treatWithTopic = + enforceWholeTopicSubmit && !Strings.isNullOrEmpty(topic) && topicSize > 1; if (submitProblems != null) { return new UiAction.Description()
diff --git a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java index f8c066d..83cb569 100644 --- a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java +++ b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
@@ -226,7 +226,8 @@ info.allowBlame = toBoolean(config.getBoolean("change", "allowBlame", true)); info.updateDelay = (int) ConfigUtil.getTimeUnit(config, "change", null, "updateDelay", 300, TimeUnit.SECONDS); - info.submitWholeTopic = toBoolean(MergeSuperSet.wholeTopicEnabled(config)); + info.submitWholeTopic = toBoolean(MergeSuperSet.isWholeTopicSubmitEnforced(config)); + info.enforceWholeTopicSubmit = toBoolean(MergeSuperSet.isWholeTopicSubmitEnforced(config)); info.disablePrivateChanges = toBoolean(this.config.getBoolean("change", null, "disablePrivateChanges", false)); info.mergeabilityComputationBehavior =
diff --git a/java/com/google/gerrit/server/submit/MergeOp.java b/java/com/google/gerrit/server/submit/MergeOp.java index 0356d8f..f172ae8 100644 --- a/java/com/google/gerrit/server/submit/MergeOp.java +++ b/java/com/google/gerrit/server/submit/MergeOp.java
@@ -809,7 +809,8 @@ logger.atFine().log("Beginning integration of %s", change); try { - ChangeSet indexBackedChangeSet = completeMergeChangeSetWithRetry(change); + ChangeSet indexBackedChangeSet = + completeMergeChangeSetWithRetry(change, submitInput.submitWholeTopic); if (preMergeChecker.check(indexBackedChangeSet).isPresent()) { return null; @@ -903,7 +904,7 @@ } } - private ChangeSet completeMergeChangeSetWithRetry(Change change) + private ChangeSet completeMergeChangeSetWithRetry(Change change, boolean includingTopicClosure) throws IOException, ResourceConflictException { try { mergeSuperSet.setMergeOpRepoManager(orm); @@ -919,10 +920,7 @@ Change reloadChange = change; ChangeSet indexBackedMergeChangeSet = mergeSuperSet.completeChangeSet( - reloadChange, - caller.getRealUser(), - /* includingTopicClosure= */ false, - backfill); + reloadChange, caller.getRealUser(), includingTopicClosure, backfill); if (!indexBackedMergeChangeSet.ids().contains(reloadChange.getId())) { // indexBackedChangeSet contains only open changes, if the change is missing // in this set it might be that the change was concurrently submitted in the
diff --git a/java/com/google/gerrit/server/submit/MergeSuperSet.java b/java/com/google/gerrit/server/submit/MergeSuperSet.java index fc05e31..3bb2f21 100644 --- a/java/com/google/gerrit/server/submit/MergeSuperSet.java +++ b/java/com/google/gerrit/server/submit/MergeSuperSet.java
@@ -83,8 +83,10 @@ this.projectCache = projectCache; } - public static boolean wholeTopicEnabled(Config config) { - return config.getBoolean("change", null, "submitWholeTopic", false); + /** Returns whether the submission of the whole topic is being enforced. */ + public static boolean isWholeTopicSubmitEnforced(Config config) { + return config.getBoolean("change", "submitWholeTopic", false) // deprecated + || config.getBoolean("change", "enforceWholeTopicSubmit", false); } @CanIgnoreReturnValue @@ -144,7 +146,7 @@ && permissionBackend.user(user).change(cd).test(ChangePermission.READ); ChangeSet changeSet = new ChangeSet(cd, visible); - if (wholeTopicEnabled(cfg) || includingTopicClosure) { + if (isWholeTopicSubmitEnforced(cfg) || includingTopicClosure) { return completeChangeSetIncludingTopics(changeSet, user, backfill); } try (TraceContext traceContext = PluginContext.newTrace(mergeSuperSetComputation);
diff --git a/polygerrit-ui/app/api/rest-api.ts b/polygerrit-ui/app/api/rest-api.ts index ffbf859..0bfdb32 100644 --- a/polygerrit-ui/app/api/rest-api.ts +++ b/polygerrit-ui/app/api/rest-api.ts
@@ -370,6 +370,7 @@ large_change: number; update_delay: number; submit_whole_topic?: boolean; + enforce_whole_topic_submit?: boolean; disable_private_changes?: boolean; mergeability_computation_behavior: MergeabilityComputationBehavior; conflicts_predicate_enabled?: boolean;
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts index 2778fb3..9ca9c6a 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
@@ -1921,15 +1921,17 @@ } // private but used in test - handleSubmitConfirm() { + handleSubmitConfirm(e: CustomEvent<{submitWholeTopic: boolean}>) { if (!this.canSubmitChange()) { return; } + const submitWholeTopic = e.detail?.submitWholeTopic ?? false; this.hideAllDialogs(); this.fireAction( '/submit', assertUIActionInfo(this.revisionActions?.submit), - true + true, + submitWholeTopic ? {submit_whole_topic: true} : undefined ); }
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts index 1f35616..c6743154 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.ts
@@ -748,19 +748,24 @@ test('handleSubmitConfirm', () => { const fireStub = sinon.stub(element, 'fireAction'); sinon.stub(element, 'canSubmitChange').returns(true); - element.handleSubmitConfirm(); + element.handleSubmitConfirm( + new CustomEvent('confirm', {detail: {submitWholeTopic: false}}) + ); assert.isTrue(fireStub.calledOnce); assert.deepEqual(fireStub.lastCall.args, [ '/submit', assertUIActionInfo(element.revisionActions?.submit), true, + undefined, ]); }); test('handleSubmitConfirm when not able to submit', () => { const fireStub = sinon.stub(element, 'fireAction'); sinon.stub(element, 'canSubmitChange').returns(false); - element.handleSubmitConfirm(); + element.handleSubmitConfirm( + new CustomEvent('confirm', {detail: {submitWholeTopic: false}}) + ); assert.isFalse(fireStub.called); });
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.ts b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.ts index 8a1070f..d2ef591 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.ts +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog.ts
@@ -8,12 +8,15 @@ import '../../plugins/gr-endpoint-decorator/gr-endpoint-decorator'; import '../../plugins/gr-endpoint-param/gr-endpoint-param'; import '../gr-thread-list/gr-thread-list'; +import '../../shared/gr-button/gr-button'; import { ActionInfo, ChangeActionDialog, + ChangeInfo, CommentThread, EDIT, RevisionInfo, + ServerInfo, } from '../../../types/common'; import {GrDialog} from '../../shared/gr-dialog/gr-dialog'; import {pluralize} from '../../../utils/string-util'; @@ -26,8 +29,11 @@ import {EditRevisionInfo, ParsedChangeInfo} from '../../../types/types'; import {commentsModelToken} from '../../../models/comments/comments-model'; import {changeModelToken} from '../../../models/change/change-model'; +import {configModelToken} from '../../../models/config/config-model'; +import {relatedChangesModelToken} from '../../../models/change/related-changes-model'; import {resolve} from '../../../models/dependency'; import {fireNoBubbleNoCompose} from '../../../utils/event-util'; +import {createSearchUrl} from '../../../models/views/search'; import {createChangeUrl} from '../../../models/views/change'; import {navigationToken} from '../../core/gr-navigation/gr-navigation'; @@ -64,14 +70,24 @@ initialised = false; @state() + private serverConfig?: ServerInfo; + + @state() + private sameTopicChanges: ChangeInfo[] = []; + + @state() sortedRevisions: (RevisionInfo | EditRevisionInfo)[] = []; private getCommentsModel = resolve(this, commentsModelToken); private getChangeModel = resolve(this, changeModelToken); + private getConfigModel = resolve(this, configModelToken); + private getNavigation = resolve(this, navigationToken); + private getRelatedChangesModel = resolve(this, relatedChangesModelToken); + static override get styles() { return [ sharedStyles, @@ -80,9 +96,42 @@ #dialog { min-width: 40em; } + .topicDashboardLink { + display: block; + margin-top: var(--spacing-m); + } + .warningBox { + display: flex; + align-items: flex-start; + gap: var(--spacing-s); + background-color: var(--warning-background); + color: var(--warning-foreground); + border: 1px solid var(--warning-foreground); + border-radius: var(--border-radius); + padding: var(--spacing-m) var(--spacing-l); + margin-bottom: var(--spacing-l); + } + .warningBox gr-icon { + color: var(--warning-foreground); + flex-shrink: 0; + margin-top: 2px; + } + + .footer-buttons { + display: flex; + align-items: center; + gap: var(--spacing-l); + flex: 1; + } + .footer-space { + flex-grow: 1; + } p { margin-bottom: var(--spacing-l); } + p:last-child { + margin-bottom: 0; + } .warningBeforeSubmit { color: var(--warning-foreground); vertical-align: top; @@ -115,6 +164,69 @@ () => this.getChangeModel().revisions$, x => (this.sortedRevisions = x) ); + subscribe( + this, + () => this.getConfigModel().serverConfig$, + x => (this.serverConfig = x) + ); + subscribe( + this, + () => this.getRelatedChangesModel().sameTopicChanges$, + x => (this.sameTopicChanges = x ?? []) + ); + } + + private isWholeTopicEnforced() { + return ( + this.serverConfig?.change.submit_whole_topic || + this.serverConfig?.change.enforce_whole_topic_submit + ); + } + + private hasSameTopicUnsubmittableChanges() { + return this.sameTopicChanges.some(c => !c.submittable); + } + + private renderTopicWarning() { + if ( + !this.sameTopicChanges.length || + !this.hasSameTopicUnsubmittableChanges() + ) + return ''; + return html` + <div class="warningBox"> + <gr-icon icon="warning" filled></gr-icon> + Some changes in this topic are not ready to submit. + </div> + `; + } + + private renderTopicSection() { + const topic = this.change?.topic; + if (!topic) return ''; + const dashboardUrl = createSearchUrl({topic}); + return html` + <div class="section"> + ${this.renderTopicWarning()} + <a + class="topicDashboardLink" + href=${dashboardUrl} + target="_blank" + rel="noopener noreferrer" + >View all changes with topic <strong>${topic}</strong></a + > + </div> + `; + } + + private renderWarnings() { + const private_ = this.renderPrivate(); + const unresolvedComments = this.renderUnresolvedCommentCount(); + const changeEdit = this.renderChangeEdit(); + if (!private_ && !unresolvedComments && !changeEdit) return ''; + return html` + <div class="section">${private_}${unresolvedComments}${changeEdit}</div> + `; } private renderPrivate() { @@ -175,13 +287,17 @@ private renderInitialised() { if (!this.initialised) return ''; + const hasTopicWithChanges = + !!this.change?.topic && this.sameTopicChanges.length > 0; + const submitWholeTopicDisabled = this.hasSameTopicUnsubmittableChanges(); + const showSubmitButton = + !hasTopicWithChanges || !this.isWholeTopicEnforced(); return html` <div class="header" slot="header">${this.action?.label}</div> <div class="main" slot="main"> <gr-endpoint-decorator name="confirm-submit-change"> <p>Ready to submit "<strong>${this.change?.subject}</strong>"?</p> - ${this.renderPrivate()} ${this.renderUnresolvedCommentCount()} - ${this.renderChangeEdit()} + ${this.renderWarnings()} ${this.renderTopicSection()} <gr-endpoint-param name="change" .value=${this.change} @@ -192,13 +308,31 @@ ></gr-endpoint-param> </gr-endpoint-decorator> </div> + <div class="footer-buttons" slot="footer"> + <div class="footer-space"></div> + <gr-button link @click=${this.handleCancelTap}>Cancel</gr-button> + ${showSubmitButton + ? html`<gr-button primary @click=${this.handleConfirmTap} + >Submit</gr-button + >` + : ''} + ${hasTopicWithChanges + ? html`<gr-button + primary + ?disabled=${submitWholeTopicDisabled} + @click=${this.handleSubmitWholeTopicTap} + >Submit Whole Topic</gr-button + >` + : ''} + </div> `; } override render() { return html` <gr-dialog id="dialog" - confirm-label="Continue" + confirm-label="" + cancel-label="" confirm-on-enter="" @cancel=${this.handleCancelTap} @confirm=${this.handleConfirmTap} @@ -212,7 +346,12 @@ } resetFocus() { - this.dialog?.resetFocus(); + // Buttons are rendered directly in slot="footer", not by gr-dialog, + // so focus the Submit button directly instead of delegating to gr-dialog. + const submitBtn = this.shadowRoot?.querySelector<HTMLElement>( + '.footer-buttons gr-button[primary]' + ); + submitBtn?.focus(); } // Private method, but visible for testing. @@ -232,7 +371,13 @@ private handleConfirmTap(e: Event) { e.preventDefault(); e.stopPropagation(); - fireNoBubbleNoCompose(this, 'confirm', {}); + fireNoBubbleNoCompose(this, 'confirm', {submitWholeTopic: false}); + } + + private handleSubmitWholeTopicTap(e: Event) { + e.preventDefault(); + e.stopPropagation(); + fireNoBubbleNoCompose(this, 'confirm', {submitWholeTopic: true}); } private handleCancelTap(e: Event) {
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_screenshot_test.ts b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_screenshot_test.ts new file mode 100644 index 0000000..749304c --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_screenshot_test.ts
@@ -0,0 +1,199 @@ +/** + * @license + * Copyright (C) 2026 The Android Open Source Project + * SPDX-License-Identifier: Apache-2.0 + */ +import '../../../test/common-test-setup'; +import './gr-confirm-submit-dialog'; +import {fixture, html} from '@open-wc/testing'; +// Until https://github.com/modernweb-dev/web/issues/2804 is fixed +// @ts-ignore +import {visualDiff} from '@web/test-runner-visual-regression'; +import {GrConfirmSubmitDialog} from './gr-confirm-submit-dialog'; +import {visualDiffDarkTheme} from '../../../test/test-utils'; +import {testResolver} from '../../../test/common-test-setup'; +import {relatedChangesModelToken} from '../../../models/change/related-changes-model'; +import {configModelToken} from '../../../models/config/config-model'; +import { + createChange, + createChangeConfig, + createParsedChange, + createServerInfo, +} from '../../../test/test-data-generators'; +import {RepoName, TopicName} from '../../../types/common'; + +suite('gr-confirm-submit-dialog screenshot tests', () => { + let element: GrConfirmSubmitDialog; + + setup(async () => { + element = await fixture<GrConfirmSubmitDialog>( + html`<gr-confirm-submit-dialog></gr-confirm-submit-dialog>` + ); + element.action = {label: 'Submit'}; + element.initialised = true; + }); + + test('no topic', async () => { + element.change = { + ...createParsedChange(), + subject: 'My change subject', + revisions: {}, + }; + await element.updateComplete; + + await visualDiff(element, 'gr-confirm-submit-dialog-no-topic'); + await visualDiffDarkTheme(element, 'gr-confirm-submit-dialog-no-topic'); + }); + + test('with topic, all changes submittable', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + { + ...createChange(), + subject: 'Change B', + project: 'repo/b' as RepoName, + submittable: true, + }, + ], + }); + element.change = { + ...createParsedChange(), + subject: 'My change subject', + topic: 'my-feature-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + await visualDiff(element, 'gr-confirm-submit-dialog-topic-all-submittable'); + await visualDiffDarkTheme( + element, + 'gr-confirm-submit-dialog-topic-all-submittable' + ); + }); + + test('with topic, some changes not submittable', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + { + ...createChange(), + subject: 'Change B - not ready', + project: 'repo/b' as RepoName, + submittable: false, + }, + ], + }); + element.change = { + ...createParsedChange(), + subject: 'My change subject', + topic: 'my-feature-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + await visualDiff(element, 'gr-confirm-submit-dialog-topic-unsubmittable'); + await visualDiffDarkTheme( + element, + 'gr-confirm-submit-dialog-topic-unsubmittable' + ); + }); + + test('whole topic enforced, all changes submittable', async () => { + const configModel = testResolver(configModelToken); + configModel.updateState({ + serverConfig: { + ...createServerInfo(), + change: {...createChangeConfig(), submit_whole_topic: true}, + }, + }); + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + { + ...createChange(), + subject: 'Change B', + project: 'repo/b' as RepoName, + submittable: true, + }, + ], + }); + element.change = { + ...createParsedChange(), + subject: 'My change subject', + topic: 'my-feature-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + await visualDiff( + element, + 'gr-confirm-submit-dialog-topic-enforced-all-submittable' + ); + await visualDiffDarkTheme( + element, + 'gr-confirm-submit-dialog-topic-enforced-all-submittable' + ); + }); + + test('whole topic enforced, some changes not submittable', async () => { + const configModel = testResolver(configModelToken); + configModel.updateState({ + serverConfig: { + ...createServerInfo(), + change: {...createChangeConfig(), submit_whole_topic: true}, + }, + }); + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + { + ...createChange(), + subject: 'Change B - not ready', + project: 'repo/b' as RepoName, + submittable: false, + }, + ], + }); + element.change = { + ...createParsedChange(), + subject: 'My change subject', + topic: 'my-feature-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + await visualDiff( + element, + 'gr-confirm-submit-dialog-topic-enforced-unsubmittable' + ); + await visualDiffDarkTheme( + element, + 'gr-confirm-submit-dialog-topic-enforced-unsubmittable' + ); + }); +});
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.ts b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.ts index d221e16..abcded6 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.ts +++ b/polygerrit-ui/app/elements/change/gr-confirm-submit-dialog/gr-confirm-submit-dialog_test.ts
@@ -5,14 +5,20 @@ */ import '../../../test/common-test-setup'; import { + createChange, + createChangeConfig, createParsedChange, createRevision, + createServerInfo, createThread, } from '../../../test/test-data-generators'; -import {EDIT} from '../../../types/common'; +import {EDIT, RepoName, TopicName} from '../../../types/common'; import {GrConfirmSubmitDialog} from './gr-confirm-submit-dialog'; import './gr-confirm-submit-dialog'; +import {configModelToken} from '../../../models/config/config-model'; import {assert, fixture, html} from '@open-wc/testing'; +import {testResolver} from '../../../test/common-test-setup'; +import {relatedChangesModelToken} from '../../../models/change/related-changes-model'; suite('gr-confirm-submit-dialog tests', () => { let element: GrConfirmSubmitDialog; @@ -37,7 +43,8 @@ element, /* HTML */ ` <gr-dialog - confirm-label="Continue" + cancel-label="" + confirm-label="" confirm-on-enter="" id="dialog" role="dialog" @@ -54,6 +61,20 @@ <gr-endpoint-param name="action"> </gr-endpoint-param> </gr-endpoint-decorator> </div> + <div class="footer-buttons" slot="footer"> + <div class="footer-space"></div> + <gr-button aria-disabled="false" link="" role="button" tabindex="0"> + Cancel + </gr-button> + <gr-button + aria-disabled="false" + primary="" + role="button" + tabindex="0" + > + Submit + </gr-button> + </div> </gr-dialog> ` ); @@ -74,6 +95,210 @@ ); }); + test('renders topic dashboard link when change has a topic', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + const link = element.shadowRoot!.querySelector( + 'a.topicDashboardLink' + ) as HTMLAnchorElement; + assert.isNotNull(link); + assert.include(link.textContent, 'my-topic'); + assert.equal(link.target, '_blank'); + assert.include(link.href, 'my-topic'); + }); + + test('does not render topic section when change has no topic', async () => { + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + revisions: {}, + }; + await element.updateComplete; + + assert.isNull(element.shadowRoot!.querySelector('a.topicDashboardLink')); + }); + + test('warning shown when topic has unsubmittable changes', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: false, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + const warning = element.shadowRoot!.querySelector('.warningBox'); + assert.isNotNull(warning); + assert.include( + warning.textContent, + 'Some changes in this topic are not ready to submit.' + ); + }); + + test('no warning shown when all topic changes are submittable', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + assert.isNull(element.shadowRoot!.querySelector('.warningBox')); + }); + + test('Submit Whole Topic button present when topic has changes', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + const btns = element.shadowRoot!.querySelectorAll( + '.footer-buttons gr-button[primary]' + ); + assert.equal(btns.length, 2); + const wholeTopicBtn = btns[1] as HTMLElement; + assert.include(wholeTopicBtn.textContent, 'Submit Whole Topic'); + assert.isFalse(wholeTopicBtn.hasAttribute('disabled')); + }); + + test('Submit Whole Topic button disabled when topic has unsubmittable changes', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: false, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + const btns = element.shadowRoot!.querySelectorAll( + '.footer-buttons gr-button[primary]' + ); + assert.equal(btns.length, 2); + const wholeTopicBtn = btns[1] as HTMLElement; + assert.isTrue(wholeTopicBtn.hasAttribute('disabled')); + }); + + test('Submit Whole Topic button absent when change has no topic', async () => { + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + revisions: {}, + }; + await element.updateComplete; + + const btns = element.shadowRoot!.querySelectorAll( + '.footer-buttons gr-button[primary]' + ); + assert.equal(btns.length, 1); + assert.include(btns[0].textContent, 'Submit'); + assert.notInclude(btns[0].textContent, 'Whole'); + }); + + test('Submit Whole Topic button fires confirm with submitWholeTopic=true', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + let detail: {submitWholeTopic: boolean} | undefined; + element.addEventListener('confirm', (e: Event) => { + detail = (e as CustomEvent).detail; + }); + + const btns = element.shadowRoot!.querySelectorAll( + '.footer-buttons gr-button[primary]' + ); + (btns[1] as HTMLElement).click(); + + assert.isTrue(detail?.submitWholeTopic); + }); + test('computeHasChangeEdit', () => { element.change = { ...createParsedChange(), @@ -93,4 +318,77 @@ }; assert.isFalse(element.computeHasChangeEdit()); }); + + suite('whole topic enforced by server config', () => { + setup(() => { + const configModel = testResolver(configModelToken); + configModel.updateState({ + serverConfig: { + ...createServerInfo(), + change: {...createChangeConfig(), submit_whole_topic: true}, + }, + }); + }); + + test('only Submit Whole Topic button shown when enforced', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + const btns = element.shadowRoot!.querySelectorAll( + '.footer-buttons gr-button[primary]' + ); + assert.equal(btns.length, 1); + assert.include(btns[0].textContent, 'Submit Whole Topic'); + }); + + test('Submit Whole Topic fires confirm with submitWholeTopic=true when enforced', async () => { + const relatedChangesModel = testResolver(relatedChangesModelToken); + relatedChangesModel.updateState({ + sameTopicChanges: [ + { + ...createChange(), + subject: 'Change A', + project: 'repo/a' as RepoName, + submittable: true, + }, + ], + }); + element.action = {label: 'Submit'}; + element.change = { + ...createParsedChange(), + subject: 'my-subject', + topic: 'my-topic' as TopicName, + revisions: {}, + }; + await element.updateComplete; + + let detail: {submitWholeTopic: boolean} | undefined; + element.addEventListener('confirm', (e: Event) => { + detail = (e as CustomEvent).detail; + }); + const btn = element.shadowRoot!.querySelector<HTMLElement>( + '.footer-buttons gr-button[primary]' + )!; + btn.click(); + + assert.isTrue(detail?.submitWholeTopic); + }); + }); });
diff --git a/polygerrit-ui/app/models/change/related-changes-model.ts b/polygerrit-ui/app/models/change/related-changes-model.ts index 55f0b75..a49c362 100644 --- a/polygerrit-ui/app/models/change/related-changes-model.ts +++ b/polygerrit-ui/app/models/change/related-changes-model.ts
@@ -211,7 +211,6 @@ .pipe( switchMap(([changeNum, topic, config]) => { if (!changeNum || !topic || !config) return of(undefined); - if (config.change.submit_whole_topic) return of(undefined); return from( this.restApiService.getChangesWithSameTopic(topic, { openChangesOnly: true,
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic-dark.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic-dark.png new file mode 100644 index 0000000..9e0d71e --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic-dark.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic.png new file mode 100644 index 0000000..5f42bdf --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-no-topic.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable-dark.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable-dark.png new file mode 100644 index 0000000..2610f73 --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable-dark.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable.png new file mode 100644 index 0000000..38eb583 --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-all-submittable.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable-dark.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable-dark.png new file mode 100644 index 0000000..d30a2eb --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable-dark.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable.png new file mode 100644 index 0000000..8ad489c --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-all-submittable.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable-dark.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable-dark.png new file mode 100644 index 0000000..86b0e6f --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable-dark.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable.png new file mode 100644 index 0000000..beffb74 --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-enforced-unsubmittable.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable-dark.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable-dark.png new file mode 100644 index 0000000..05b0d9f --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable-dark.png Binary files differ
diff --git a/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable.png b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable.png new file mode 100644 index 0000000..1d1029c --- /dev/null +++ b/polygerrit-ui/screenshots/Chromium/baseline/gr-confirm-submit-dialog-topic-unsubmittable.png Binary files differ