From 16325f4e84e2f508ec05cb3cf788a5269c187206 Mon Sep 17 00:00:00 2001 From: RMadsenG <70653994+RMadsenG@users.noreply.github.com> Date: Tue, 28 Jan 2025 04:13:05 -0500 Subject: [PATCH] Changed model for Bitbucket Server Payload (#359) --- .../BitBucketPPRPullRequestServerAction.java | 2 +- .../server/BitBucketPPRServerMergeCommit.java | 49 +++++++++++++++++++ .../BitBucketPPRServerPRProperties.java | 40 +++++++++++++++ .../server/BitBucketPPRServerPullRequest.java | 10 ++++ ...tBucketPPRPullRequestServerActionTest.java | 2 +- 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerMergeCommit.java create mode 100644 src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPRProperties.java diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java index e791937b..f967635d 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerAction.java @@ -221,7 +221,7 @@ public String getLinkDecline() throws MalformedURLException { @Override public String getLatestCommit() { if (PULL_REQUEST_SERVER_MERGED.equalsIgnoreCase(this.bitbucketEvent.getAction())) { - return payload.getPullRequest().getMergeCommit().getHash(); + return payload.getServerPullRequest().getProperties().getMergeCommit().getId(); } return payload.getServerPullRequest().getFromRef().getLatestCommit(); } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerMergeCommit.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerMergeCommit.java new file mode 100644 index 00000000..9e5f58f9 --- /dev/null +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerMergeCommit.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * The MIT License + * + * Copyright (C) 2018, CloudBees, Inc. + * + * 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 io.jenkins.plugins.bitbucketpushandpullrequest.model.server; + +import java.io.Serializable; + + +public class BitBucketPPRServerMergeCommit implements Serializable { + private static final long serialVersionUID = -5347870725110898308L; + + private String id; + private String displayId; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getDisplayId() { + return displayId; + } + + public void setDisplayId(final String displayId) { + this.displayId = displayId; + } +} diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPRProperties.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPRProperties.java new file mode 100644 index 00000000..ca529243 --- /dev/null +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPRProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * The MIT License + * + * Copyright (C) 2018, CloudBees, Inc. + * + * 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 io.jenkins.plugins.bitbucketpushandpullrequest.model.server; + +import java.io.Serializable; + + +public class BitBucketPPRServerPRProperties implements Serializable { + private static final long serialVersionUID = -4327337466069004128L; + + private BitBucketPPRServerMergeCommit mergeCommit; + + public BitBucketPPRServerMergeCommit getMergeCommit() { + return mergeCommit; + } + + public void setMergeCommit(final BitBucketPPRServerMergeCommit mergeCommit) { + this.mergeCommit = mergeCommit; + } +} diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPullRequest.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPullRequest.java index 4e92f85f..bb2ecc6c 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPullRequest.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPullRequest.java @@ -48,6 +48,8 @@ public class BitBucketPPRServerPullRequest implements Serializable { private BitBucketPPRServerRepositoryRef toRef; + private BitBucketPPRServerPRProperties properties; + public Long getId() { return id; } @@ -168,6 +170,14 @@ public void setToRef(final BitBucketPPRServerRepositoryRef toRef) { this.toRef = toRef; } + public BitBucketPPRServerPRProperties getProperties() { + return properties; + } + + public void setToRef(final BitBucketPPRServerPRProperties properties) { + this.properties = properties; + } + @Override public String toString() { return "BitBucketPPRServerPullRequest [id=" + id + ", version=" + version + ", title=" + title diff --git a/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerActionTest.java b/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerActionTest.java index 624a3913..414dcad9 100644 --- a/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerActionTest.java +++ b/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/action/BitBucketPPRPullRequestServerActionTest.java @@ -58,7 +58,7 @@ public void testGetMergeCommit() throws BitBucketPPRPayloadPropertyNotFoundExcep BitBucketPPRPluginConfig c = mock(BitBucketPPRPluginConfig.class); config.when(BitBucketPPRPluginConfig::getInstance).thenReturn(c); BitBucketPPRPayload payloadMock = mock(BitBucketPPRPayload.class, RETURNS_DEEP_STUBS); - when(payloadMock.getPullRequest().getMergeCommit().getHash()).thenReturn("123456"); + when(payloadMock.getServerPullRequest().getProperties().getMergeCommit().getId()).thenReturn("123456"); BitBucketPPRHookEvent event = mock(BitBucketPPRHookEvent.class); when(event.getAction()).thenReturn("merged"); BitBucketPPRPullRequestServerAction action =