Skip to content

Commit

Permalink
Merge pull request #99 from scm-manager/feature/rebase
Browse files Browse the repository at this point in the history
Feature/rebase
  • Loading branch information
pfeuffer authored Sep 23, 2020
2 parents 341ecb2 + 50f2e1c commit c7a1ffe
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Add support for pr merge with prior rebase ([#99](https://github.com/scm-manager/scm-review-plugin/pull/99))

## 2.3.0 - 2020-08-14
### Added
- Sort mechanism for rules in "Add Rule" dropdown ([#88](https://github.com/scm-manager/scm-review-plugin/pull/88))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<artifactId>scm-plugins</artifactId>
<groupId>sonia.scm.plugins</groupId>
<version>2.4.0</version>
<version>2.6.0-SNAPSHOT</version>
</parent>

<artifactId>scm-review-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PullRequestMediaType {
public static final String MERGE_COMMAND = VndMediaType.PREFIX + "mergeCommand" + VndMediaType.SUFFIX;
public static final String MERGE_CHECK_RESULT = VndMediaType.PREFIX + "mergeCheckResult" + VndMediaType.SUFFIX;
public static final String MERGE_CONFLICT_RESULT = VndMediaType.PREFIX + "mergeConflictsResult" + VndMediaType.SUFFIX;
public static final String MERGE_STRATEGY_INFO = VndMediaType.PREFIX + "mergeStrategyInfo" + VndMediaType.SUFFIX;

private PullRequestMediaType() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,16 @@ public String emergencyMerge(String namespace, String name, String pullRequestId
public String conflicts(String namespace, String name, String pullRequestId) {
return mergeLinkBuilder.method("conflicts").parameters(namespace, name, pullRequestId).href();
}

public String createDefaultCommitMessage(String namespace, String name, String pullRequestId) {
return mergeLinkBuilder
.method("createDefaultCommitMessage").parameters(namespace, name, pullRequestId).href();
}

public String getMergeStrategyInfo(String namespace, String name, String pullRequestId) {
return mergeLinkBuilder
.method("getMergeStrategyInfo").parameters(namespace, name, pullRequestId).href();
}
}

public WorkflowEngineLinks workflowEngineLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
*/
package com.cloudogu.scm.review.pullrequest.api;

import com.cloudogu.scm.review.PermissionCheck;
import com.cloudogu.scm.review.PullRequestMediaType;
import com.cloudogu.scm.review.PullRequestResourceLinks;
import com.cloudogu.scm.review.pullrequest.dto.MergeCheckResultDto;
import com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto;
import com.cloudogu.scm.review.pullrequest.dto.MergeConflictResultDto;
import com.cloudogu.scm.review.pullrequest.dto.MergeStrategyInfoDto;
import com.cloudogu.scm.review.pullrequest.service.MergeCheckResult;
import com.cloudogu.scm.review.pullrequest.service.MergeService;
import de.otto.edison.hal.Links;
Expand Down Expand Up @@ -197,6 +197,7 @@ public MergeConflictResultDto conflicts(
);
}

@Deprecated
@GET
@Path("{namespace}/{name}/{pullRequestId}/commit-message")
@Produces("text/plain")
Expand Down Expand Up @@ -229,4 +230,41 @@ public String createDefaultCommitMessage(
) {
return service.createDefaultCommitMessage(new NamespaceAndName(namespace, name), pullRequestId, strategy);
}

@GET
@Path("{namespace}/{name}/{pullRequestId}/merge-strategy-info")
@Produces(PullRequestMediaType.MERGE_STRATEGY_INFO)
@Operation(
summary = "Get commit message information",
description = "Returns commit message information for the given merge strategy",
tags = "Pull Request"
)
@ApiResponse(
responseCode = "200",
description = "commit message was created",
content = @Content(
schema = @Schema(implementation = MergeStrategyInfoDto.class)
)
)
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(
responseCode = "500",
description = "internal server error",
content = @Content(
mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class)
)
)
public MergeStrategyInfoDto getMergeStrategyInfo(
@PathParam("namespace") String namespace,
@PathParam("name") String name,
@PathParam("pullRequestId") String pullRequestId,
@QueryParam("strategy") MergeStrategy strategy
) {
return new MergeStrategyInfoDto(
service.isCommitMessageDisabled(strategy),
service.createDefaultCommitMessage(new NamespaceAndName(namespace, name), pullRequestId, strategy),
service.createMergeCommitMessageHint(strategy)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.cloudogu.scm.review.pullrequest.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class MergeStrategyInfoDto {
private boolean commitMessageDisabled;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String defaultCommitMessage;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String commitMessageHint;
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ PullRequestDto createDto(PullRequest pullRequest, @Context Repository repository
.conflicts(namespace, name, pullRequest.getId())));
linksBuilder.single(link("defaultCommitMessage", pullRequestResourceLinks.mergeLinks()
.createDefaultCommitMessage(namespace, name, pullRequest.getId())));
linksBuilder.single(link("mergeStrategyInfo", pullRequestResourceLinks.mergeLinks().getMergeStrategyInfo(namespace, name, pullRequestId)));
appendMergeStrategyLinks(linksBuilder, repository, pullRequest);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.cloudogu.scm.review.pullrequest.service;

import org.slf4j.MDC;
import sonia.scm.ContextEntry;
import sonia.scm.web.VndMediaType;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.List;

@Provider
public class MergeConflictExceptionMapper implements ExceptionMapper<MergeConflictException> {

@Override
public Response toResponse(MergeConflictException exception) {
return Response.status(409).entity(new Object() {
public String getTransactionId() {
return MDC.get("transaction_id");
}

public String getErrorCode() {
return exception.getCode();
}

public List<ContextEntry> getContext() {
return exception.getContext();
}

public String getMessage() {
return exception.getMessage();
}
}).type(VndMediaType.ERROR_TYPE).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.cloudogu.scm.review.PermissionCheck;
import com.cloudogu.scm.review.pullrequest.dto.MergeCommitDto;
import org.apache.shiro.SecurityUtils;
import sonia.scm.i18n.I18nMessages;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.NamespaceAndName;
Expand Down Expand Up @@ -193,6 +194,17 @@ public String createDefaultCommitMessage(NamespaceAndName namespaceAndName, Stri
}
}

public boolean isCommitMessageDisabled(MergeStrategy strategy) {
return !strategy.isCommitMessageAllowed();
}

public String createMergeCommitMessageHint(MergeStrategy strategy) {
if (strategy == MergeStrategy.FAST_FORWARD_IF_POSSIBLE) {
return strategy.name();
}
return null;
}

private String createDefaultMergeCommitMessage(PullRequest pullRequest) {
return MessageFormat.format(MERGE_COMMIT_MESSAGE_TEMPLATE, pullRequest.getSource(), pullRequest.getTarget());
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/js/MergeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Props = WithTranslation & {
mergeCheck?: MergeCheck;
loading: boolean;
pullRequest: PullRequest;
onMergeModalClose?: () => void;
};

type State = {
Expand Down Expand Up @@ -74,6 +75,9 @@ class MergeButton extends React.Component<Props, State> {
};

toggleMergeModal = () => {
if (this.state.showMergeModal) {
this.props.onMergeModalClose && this.props.onMergeModalClose();
}
this.setState(prevState => ({
showMergeModal: !prevState.showMergeModal
}));
Expand Down Expand Up @@ -196,6 +200,7 @@ class MergeButton extends React.Component<Props, State> {
close={this.toggleMergeModal}
pullRequest={pullRequest}
emergencyMerge={this.existsObstacles() && !this.existsNotOverrideableObstacles()}
mergeCheck={mergeCheck}
/>
);
}
Expand Down
33 changes: 23 additions & 10 deletions src/main/js/MergeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { Link } from "@scm-manager/ui-types";
import MergeStrategies from "./MergeStrategies";
import { Checkbox, Textarea, Button } from "@scm-manager/ui-components";
import { Button, Checkbox, Textarea } from "@scm-manager/ui-components";
import styled from "styled-components";

type Props = WithTranslation & {
strategyLinks: Link[];
selectStrategy: (strategy: string) => void;
selectedStrategy: string;
commitMessage: string;
commitMessageDisabled?: boolean;
commitMessageHint?: string;
onChangeCommitMessage: (message: string) => void;
onResetCommitMessage: () => void;
shouldDeleteSourceBranch: boolean;
Expand All @@ -49,8 +51,12 @@ class MergeForm extends React.Component<Props> {
return this.props.loading;
};

isCommitMessageVisible = () => {
return !this.props.commitMessageDisabled;
};

isShowMessageHint = () => {
return this.props.selectedStrategy === "FAST_FORWARD_IF_POSSIBLE";
return !!this.props.commitMessageHint;
};

render() {
Expand All @@ -63,17 +69,12 @@ class MergeForm extends React.Component<Props> {
shouldDeleteSourceBranch,
onChangeDeleteSourceBranch,
onResetCommitMessage,
commitMessageHint,
t
} = this.props;

return (
const commitMessageElement = this.isCommitMessageVisible() && (
<>
<MergeStrategies
strategyLinks={strategyLinks}
selectedStrategy={selectedStrategy}
selectStrategy={selectStrategy}
/>
<hr />
<Textarea
placeholder={t("scm-review-plugin.showPullRequest.mergeModal.commitMessage")}
disabled={this.isCommitMessageDisabled()}
Expand All @@ -85,11 +86,23 @@ class MergeForm extends React.Component<Props> {
<span className="icon is-small has-text-info">
<i className="fas fa-info-circle" />
</span>{" "}
<span>{t("scm-review-plugin.showPullRequest.mergeModal.fallbackMessageInfo")}</span>
<span>{t("scm-review-plugin.showPullRequest.mergeModal.commitMessageHint." + commitMessageHint)}</span>
</CommitMessageInfo>
)}
<Button label={t("scm-review-plugin.showPullRequest.mergeModal.resetMessage")} action={onResetCommitMessage} />
<hr />
</>
);

return (
<>
<MergeStrategies
strategyLinks={strategyLinks}
selectedStrategy={selectedStrategy}
selectStrategy={selectStrategy}
/>
<hr />
{commitMessageElement}
<Checkbox
label={t("scm-review-plugin.showPullRequest.mergeModal.deleteSourceBranch.flag")}
checked={shouldDeleteSourceBranch}
Expand Down
Loading

0 comments on commit c7a1ffe

Please sign in to comment.