'Show merge commits' option in repository settings

This commit is contained in:
ViacheslavKlimov 2022-12-09 18:29:57 +02:00
parent 3a3771db64
commit 808b1dc0c5
7 changed files with 21 additions and 13 deletions

View File

@ -78,6 +78,10 @@ public class DefaultCacheCleanupService implements CacheCleanupService {
clearCacheByName("assets"); clearCacheByName("assets");
clearCacheByName("repositorySettings"); clearCacheByName("repositorySettings");
break; break;
case "3.4.2":
log.info("Clearing cache to upgrade from version 3.4.2 to 3.4.3 ...");
clearCacheByName("repositorySettings");
break;
default: default:
//Do nothing, since cache cleanup is optional. //Do nothing, since cache cleanup is optional.
} }

View File

@ -32,6 +32,7 @@ public class RepositorySettings implements Serializable {
private String privateKeyPassword; private String privateKeyPassword;
private String defaultBranch; private String defaultBranch;
private boolean readOnly; private boolean readOnly;
private boolean showMergeCommits;
public RepositorySettings() { public RepositorySettings() {
} }
@ -46,5 +47,6 @@ public class RepositorySettings implements Serializable {
this.privateKeyPassword = settings.getPrivateKeyPassword(); this.privateKeyPassword = settings.getPrivateKeyPassword();
this.defaultBranch = settings.getDefaultBranch(); this.defaultBranch = settings.getDefaultBranch();
this.readOnly = settings.isReadOnly(); this.readOnly = settings.isReadOnly();
this.showMergeCommits = settings.isShowMergeCommits();
} }
} }

View File

@ -197,12 +197,7 @@ public class GitRepository {
LogCommand command = git.log() LogCommand command = git.log()
.add(branchId); .add(branchId);
if (StringUtils.isNotEmpty(pageLink.getTextSearch())) { command.setRevFilter(new CommitFilter(pageLink.getTextSearch(), settings.isShowMergeCommits()));
command.setRevFilter(new NoMergesAndCommitMessageFilter(pageLink.getTextSearch()));
} else {
command.setRevFilter(RevFilter.NO_MERGES);
}
if (StringUtils.isNotEmpty(path)) { if (StringUtils.isNotEmpty(path)) {
command.addPath(path); command.addPath(path);
} }
@ -478,17 +473,20 @@ public class GitRepository {
} }
} }
private static class NoMergesAndCommitMessageFilter extends RevFilter { private static class CommitFilter extends RevFilter {
private final String textSearch; private final String textSearch;
private final boolean showMergeCommits;
NoMergesAndCommitMessageFilter(String textSearch) { CommitFilter(String textSearch, boolean showMergeCommits) {
this.textSearch = textSearch.toLowerCase(); this.textSearch = textSearch.toLowerCase();
this.showMergeCommits = showMergeCommits;
} }
@Override @Override
public boolean include(RevWalk walker, RevCommit c) { public boolean include(RevWalk walker, RevCommit c) {
return c.getParentCount() < 2 && c.getFullMessage().toLowerCase().contains(this.textSearch); return (showMergeCommits || c.getParentCount() < 2) && (StringUtils.isEmpty(textSearch)
|| c.getFullMessage().toLowerCase().contains(textSearch));
} }
@Override @Override
@ -501,10 +499,6 @@ public class GitRepository {
return false; return false;
} }
@Override
public String toString() {
return "NO_MERGES_AND_COMMIT_MESSAGE";
}
} }
@Data @Data

View File

@ -44,6 +44,11 @@
<mat-checkbox formControlName="readOnly"> <mat-checkbox formControlName="readOnly">
{{ 'admin.repository-read-only' | translate }} {{ 'admin.repository-read-only' | translate }}
</mat-checkbox> </mat-checkbox>
<div>
<mat-checkbox formControlName="showMergeCommits">
{{ 'admin.show-merge-commits' | translate }}
</mat-checkbox>
</div>
<fieldset [disabled]="isLoading$ | async" class="fields-group"> <fieldset [disabled]="isLoading$ | async" class="fields-group">
<legend class="group-title" translate>admin.authentication-settings</legend> <legend class="group-title" translate>admin.authentication-settings</legend>
<mat-form-field fxFlex class="mat-block"> <mat-form-field fxFlex class="mat-block">

View File

@ -75,6 +75,7 @@ export class RepositorySettingsComponent extends PageComponent implements OnInit
repositoryUri: [null, [Validators.required]], repositoryUri: [null, [Validators.required]],
defaultBranch: ['main', []], defaultBranch: ['main', []],
readOnly: [false, []], readOnly: [false, []],
showMergeCommits: [false, []],
authMethod: [RepositoryAuthMethod.USERNAME_PASSWORD, [Validators.required]], authMethod: [RepositoryAuthMethod.USERNAME_PASSWORD, [Validators.required]],
username: [null, []], username: [null, []],
password: [null, []], password: [null, []],

View File

@ -418,6 +418,7 @@ export const repositoryAuthMethodTranslationMap = new Map<RepositoryAuthMethod,
export interface RepositorySettings { export interface RepositorySettings {
repositoryUri: string; repositoryUri: string;
defaultBranch: string; defaultBranch: string;
showMergeCommits: boolean;
authMethod: RepositoryAuthMethod; authMethod: RepositoryAuthMethod;
username: string; username: string;
password: string; password: string;

View File

@ -329,6 +329,7 @@
"repository-url-required": "Repository URL is required.", "repository-url-required": "Repository URL is required.",
"default-branch": "Default branch name", "default-branch": "Default branch name",
"repository-read-only": "Read-only", "repository-read-only": "Read-only",
"show-merge-commits": "Show merge commits",
"authentication-settings": "Authentication settings", "authentication-settings": "Authentication settings",
"auth-method": "Authentication method", "auth-method": "Authentication method",
"auth-method-username-password": "Password / access token", "auth-method-username-password": "Password / access token",