From 906e79ad555acdbe86a81d450145c417f828c8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bresson?= Date: Sat, 18 Nov 2023 07:10:36 +0100 Subject: [PATCH] Add 'pipelineId' to CommitStatus (#1064) Fixes https://github.com/gitlab4j/gitlab4j-api/issues/1058 --- .../java/org/gitlab4j/api/CommitsApi.java | 9 +++- .../org/gitlab4j/api/models/CommitStatus.java | 14 +++++++ .../org/gitlab4j/api/commit-status.json | 42 ++++++++++--------- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/CommitsApi.java b/src/main/java/org/gitlab4j/api/CommitsApi.java index c6cffde7d..ece23acbf 100644 --- a/src/main/java/org/gitlab4j/api/CommitsApi.java +++ b/src/main/java/org/gitlab4j/api/CommitsApi.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; @@ -590,7 +591,9 @@ public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBu * @param status the CommitSatus instance hoilding the optional parms: ref, name, target_url, description, and coverage * @return a CommitStatus instance with the updated info * @throws GitLabApiException GitLabApiException if any exception occurs during execution + * @deprecated use {@link #addCommitStatus(Object, String, org.gitlab4j.api.Constants.CommitBuildState, CommitStatus)} and set the pipelineId value in the {@link CommitStatus} parameter */ + @Deprecated public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBuildState state, Long pipelineId, CommitStatus status) throws GitLabApiException { if (projectIdOrPath == null) { @@ -607,7 +610,11 @@ public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBu .withParam("name", status.getName()) .withParam("target_url", status.getTargetUrl()) .withParam("description", status.getDescription()) - .withParam("coverage", status.getCoverage()); + .withParam("coverage", status.getCoverage()) + .withParam("pipeline_id", status.getPipelineId()); + if (pipelineId != null && status.getPipelineId() != null && !Objects.equals(status.getPipelineId(), pipelineId)) { + throw new IllegalArgumentException("The parameter 'pipelineId' and the pipelineId value the 'status' parameter are different. Set the two values to be the same or one of the two values to null."); + } } if (pipelineId != null) { diff --git a/src/main/java/org/gitlab4j/api/models/CommitStatus.java b/src/main/java/org/gitlab4j/api/models/CommitStatus.java index e4ab26ea2..cff7a5770 100644 --- a/src/main/java/org/gitlab4j/api/models/CommitStatus.java +++ b/src/main/java/org/gitlab4j/api/models/CommitStatus.java @@ -15,6 +15,7 @@ public class CommitStatus { private Date finishedAt; private Long id; private String name; + private Long pipelineId; private String ref; private String sha; private Date startedAt; @@ -85,6 +86,14 @@ public void setName(String name) { this.name = name; } + public Long getPipelineId() { + return pipelineId; + } + + public void setPipelineId(Long pipelineId) { + this.pipelineId = pipelineId; + } + public String getRef() { return ref; } @@ -140,6 +149,11 @@ public CommitStatus withName(String name) { return this; } + public CommitStatus withPipelineId(Long pipelineId) { + this.pipelineId = pipelineId; + return this; + } + public CommitStatus withRef(String ref) { this.ref = ref; return this; diff --git a/src/test/resources/org/gitlab4j/api/commit-status.json b/src/test/resources/org/gitlab4j/api/commit-status.json index f4eba8ab4..47ba8cb73 100644 --- a/src/test/resources/org/gitlab4j/api/commit-status.json +++ b/src/test/resources/org/gitlab4j/api/commit-status.json @@ -1,21 +1,23 @@ { - "status" : "pending", - "created_at" : "2016-01-19T08:40:25.934Z", - "started_at" : "2016-01-19T08:40:25.934Z", - "name" : "bundler:audit", - "allow_failure" : true, - "author" : { - "username" : "thedude", - "state" : "active", - "web_url" : "https://gitlab.example.com/thedude", - "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", - "id" : 28, - "name" : "Jeff Lebowski" - }, - "description" : "this is a description", - "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", - "target_url" : "https://gitlab.example.com/thedude/gitlab-ce/builds/91", - "finished_at" : "2016-01-19T08:40:25.934Z", - "id" : 2148826854, - "ref" : "master" - } \ No newline at end of file + "id": 78919, + "sha": "6b9fec60e107f1f323dfa6674b317facd996cb0a", + "ref": "cccct", + "status": "failed", + "name": "extci", + "target_url": "https://example.com/ext/6b9fec60e107f1f323dfa6674b317facd996cb0a/", + "description": "External check", + "created_at": "2023-04-03T11:05:27.792Z", + "started_at": "2023-04-03T11:05:29.205Z", + "finished_at": "2023-04-03T11:16:05.803Z", + "allow_failure": false, + "coverage": 10.8, + "pipeline_id": 15641, + "author": { + "id": 7, + "name": "Pamella Huel", + "username": "arnita", + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/a2f5c6fcef64c9c69cb8779cb292be1b?s=80&d=identicon", + "web_url": "http://gitlab.example.com/arnita" + } +} \ No newline at end of file