Skip to content

Commit

Permalink
Changed model for Bitbucket Server Payload (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
RMadsenG authored Jan 28, 2025
1 parent 6042b3b commit 16325f4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Check warning on line 48 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerMergeCommit.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 28-48 are not covered by tests
}
Original file line number Diff line number Diff line change
@@ -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;
}

Check warning on line 39 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPRProperties.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 28-39 are not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class BitBucketPPRServerPullRequest implements Serializable {

private BitBucketPPRServerRepositoryRef toRef;

private BitBucketPPRServerPRProperties properties;

public Long getId() {
return id;
}
Expand Down Expand Up @@ -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;
}

Check warning on line 179 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/model/server/BitBucketPPRServerPullRequest.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 174-179 are not covered by tests

@Override
public String toString() {
return "BitBucketPPRServerPullRequest [id=" + id + ", version=" + version + ", title=" + title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 16325f4

Please sign in to comment.