Skip to content

Commit eb9bdb9

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

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

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

Lines changed: 29 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,32 @@ 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+
generateChangelog(projectIdOrPath, new ChangelogPayload(version));
765+
}
766+
767+
/**
768+
* Generate changelog data based on commits in a repository.
769+
*
770+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/changelog</code></pre>
771+
*
772+
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
773+
* @param payload the payload to generate the changelog for
774+
* @throws GitLabApiException if any exception occurs
775+
*/
776+
public void generateChangelog(Object projectIdOrPath, ChangelogPayload payload) throws GitLabApiException {
777+
post(Response.Status.OK, payload.getFormData(), "projects",
778+
getProjectIdOrPath(projectIdOrPath), "repository", "changelog");
779+
}
780+
752781
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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(String version) {
22+
this.version = version;
23+
}
24+
25+
@JsonIgnore
26+
public GitLabApiForm getFormData() {
27+
return new GitLabApiForm()
28+
.withParam("version", version, true)
29+
.withParam("from", from)
30+
.withParam("to", to)
31+
.withParam("date", ISO8601.dateOnly(date))
32+
.withParam("branch", branch)
33+
.withParam("trailer", trailer)
34+
.withParam("file", file)
35+
.withParam("message", message);
36+
}
37+
38+
public String getVersion() {
39+
return version;
40+
}
41+
42+
public void setVersion(String version) {
43+
this.version = version;
44+
}
45+
46+
public String getFrom() {
47+
return from;
48+
}
49+
50+
public void setFrom(String from) {
51+
this.from = from;
52+
}
53+
54+
public String getTo() {
55+
return to;
56+
}
57+
58+
public void setTo(String to) {
59+
this.to = to;
60+
}
61+
62+
public Date getDate() {
63+
return date;
64+
}
65+
66+
public void setDate(Date date) {
67+
this.date = date;
68+
}
69+
70+
public String getBranch() {
71+
return branch;
72+
}
73+
74+
public void setBranch(String branch) {
75+
this.branch = branch;
76+
}
77+
78+
public String getTrailer() {
79+
return trailer;
80+
}
81+
82+
public void setTrailer(String trailer) {
83+
this.trailer = trailer;
84+
}
85+
86+
public String getFile() {
87+
return file;
88+
}
89+
90+
public void setFile(String file) {
91+
this.file = file;
92+
}
93+
94+
public String getMessage() {
95+
return message;
96+
}
97+
98+
public void setMessage(String message) {
99+
this.message = message;
100+
}
101+
102+
@Override
103+
public String toString() {
104+
return (JacksonJson.toJsonString(this));
105+
}
106+
}

0 commit comments

Comments
 (0)