Skip to content

Commit 4e4435f

Browse files
committed
feat: add generate changelog api support
1 parent 750213b commit 4e4435f

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

src/main/java/org/gitlab4j/api/RepositoryApi.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.gitlab4j.api.GitLabApi.ApiVersion;
2020
import org.gitlab4j.api.models.Branch;
21+
import org.gitlab4j.api.models.ChangelogPayload;
2122
import org.gitlab4j.api.models.Commit;
2223
import org.gitlab4j.api.models.CompareResults;
2324
import org.gitlab4j.api.models.Contributor;
@@ -749,4 +750,36 @@ public void deleteMergedBranches(Object projectIdOrPath) throws GitLabApiExcepti
749750
delete(Response.Status.NO_CONTENT, null, "projects",
750751
getProjectIdOrPath(projectIdOrPath), "repository", "merged_branches");
751752
}
753+
754+
/**
755+
* Generate changelog data based on commits in a repository.
756+
*
757+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/changelog</code></pre>
758+
*
759+
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
760+
* @param version the version to generate the changelog for
761+
* @throws GitLabApiException if any exception occurs
762+
*/
763+
public void generateChangelog(Object projectIdOrPath, String version) throws GitLabApiException {
764+
ChangelogPayload payload = new ChangelogPayload()
765+
.withVersion(version);
766+
767+
post(Response.Status.OK, payload.getFormData(), "projects",
768+
getProjectIdOrPath(projectIdOrPath), "repository", "changelog");
769+
}
770+
771+
/**
772+
* Generate changelog data based on commits in a repository.
773+
*
774+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/changelog</code></pre>
775+
*
776+
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
777+
* @param payload the payload to generate the changelog for
778+
* @throws GitLabApiException if any exception occurs
779+
*/
780+
public void generateChangelog(Object projectIdOrPath, ChangelogPayload payload) throws GitLabApiException {
781+
post(Response.Status.OK, payload.getFormData(), "projects",
782+
getProjectIdOrPath(projectIdOrPath), "repository", "changelog");
783+
}
784+
752785
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package org.gitlab4j.api.models;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import org.gitlab4j.api.GitLabApiForm;
5+
import org.gitlab4j.api.utils.ISO8601;
6+
import org.gitlab4j.api.utils.JacksonJson;
7+
8+
import java.util.Date;
9+
10+
public class ChangelogPayload {
11+
12+
private String version;
13+
private String from;
14+
private String to;
15+
private Date date;
16+
private String branch;
17+
private String trailer;
18+
private String file;
19+
private String message;
20+
21+
public ChangelogPayload withVersion(String version) {
22+
this.version = version;
23+
24+
return this;
25+
}
26+
27+
@JsonIgnore
28+
public GitLabApiForm getFormData() {
29+
return new GitLabApiForm()
30+
.withParam("version", version, true)
31+
.withParam("from", from)
32+
.withParam("to", to)
33+
.withParam("date", ISO8601.dateOnly(date))
34+
.withParam("branch", branch)
35+
.withParam("trailer", trailer)
36+
.withParam("file", file)
37+
.withParam("message", message);
38+
}
39+
40+
public String getVersion() {
41+
return version;
42+
}
43+
44+
public void setVersion(String version) {
45+
this.version = version;
46+
}
47+
48+
public String getFrom() {
49+
return from;
50+
}
51+
52+
public void setFrom(String from) {
53+
this.from = from;
54+
}
55+
56+
public String getTo() {
57+
return to;
58+
}
59+
60+
public void setTo(String to) {
61+
this.to = to;
62+
}
63+
64+
public Date getDate() {
65+
return date;
66+
}
67+
68+
public void setDate(Date date) {
69+
this.date = date;
70+
}
71+
72+
public String getBranch() {
73+
return branch;
74+
}
75+
76+
public void setBranch(String branch) {
77+
this.branch = branch;
78+
}
79+
80+
public String getTrailer() {
81+
return trailer;
82+
}
83+
84+
public void setTrailer(String trailer) {
85+
this.trailer = trailer;
86+
}
87+
88+
public String getFile() {
89+
return file;
90+
}
91+
92+
public void setFile(String file) {
93+
this.file = file;
94+
}
95+
96+
public String getMessage() {
97+
return message;
98+
}
99+
100+
public void setMessage(String message) {
101+
this.message = message;
102+
}
103+
104+
@Override
105+
public String toString() {
106+
return (JacksonJson.toJsonString(this));
107+
}
108+
}

0 commit comments

Comments
 (0)