Skip to content

Commit dff8509

Browse files
vimsuckszhuyangjmini
authored
Better support for DiffNote type (line_range in Position, suggestions, ...) (#1286)
--------- Co-authored-by: zhuyang <[email protected]> Co-authored-by: Jeremie Bresson <[email protected]>
1 parent fbefbe4 commit dff8509

File tree

5 files changed

+317
-0
lines changed

5 files changed

+317
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.models.utils.JacksonJson;
6+
import org.gitlab4j.models.utils.JacksonJsonEnumHelper;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonValue;
10+
11+
public class LineRange implements Serializable {
12+
private static final long serialVersionUID = 1L;
13+
14+
public static class Position implements Serializable {
15+
private static final long serialVersionUID = 1L;
16+
17+
public static enum PositionType {
18+
OLD,
19+
NEW;
20+
private static JacksonJsonEnumHelper<PositionType> enumHelper =
21+
new JacksonJsonEnumHelper<>(PositionType.class, false, false);
22+
23+
@JsonCreator
24+
public static PositionType forValue(String value) {
25+
return enumHelper.forValue(value);
26+
}
27+
28+
@JsonValue
29+
public String toValue() {
30+
return (enumHelper.toString(this));
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return (enumHelper.toString(this));
36+
}
37+
}
38+
39+
private String lineCode;
40+
private PositionType type;
41+
private Integer oldLine;
42+
private Integer newLine;
43+
44+
public String getLineCode() {
45+
return lineCode;
46+
}
47+
48+
public void setLineCode(String lineCode) {
49+
this.lineCode = lineCode;
50+
}
51+
52+
public Position withLineCode(String lineCode) {
53+
this.lineCode = lineCode;
54+
return this;
55+
}
56+
57+
public PositionType getType() {
58+
return type;
59+
}
60+
61+
public void setType(PositionType type) {
62+
this.type = type;
63+
}
64+
65+
public Position withType(PositionType type) {
66+
this.type = type;
67+
return this;
68+
}
69+
70+
public Integer getOldLine() {
71+
return oldLine;
72+
}
73+
74+
public void setOldLine(Integer oldLine) {
75+
this.oldLine = oldLine;
76+
}
77+
78+
public Position withOldLine(Integer oldLine) {
79+
this.oldLine = oldLine;
80+
return this;
81+
}
82+
83+
public Integer getNewLine() {
84+
return newLine;
85+
}
86+
87+
public void setNewLine(Integer newLine) {
88+
this.newLine = newLine;
89+
}
90+
91+
public Position withNewLine(Integer newLine) {
92+
this.newLine = newLine;
93+
return this;
94+
}
95+
96+
@Override
97+
public String toString() {
98+
return (JacksonJson.toJsonString(this));
99+
}
100+
}
101+
102+
private Position start;
103+
private Position end;
104+
105+
public Position getStart() {
106+
return start;
107+
}
108+
109+
public void setStart(Position start) {
110+
this.start = start;
111+
}
112+
113+
public LineRange withStart(Position start) {
114+
this.start = start;
115+
return this;
116+
}
117+
118+
public Position getEnd() {
119+
return end;
120+
}
121+
122+
public void setEnd(Position end) {
123+
this.end = end;
124+
}
125+
126+
public LineRange withEnd(Position end) {
127+
this.end = end;
128+
return this;
129+
}
130+
131+
@Override
132+
public String toString() {
133+
return (JacksonJson.toJsonString(this));
134+
}
135+
}

gitlab4j-models/src/main/java/org/gitlab4j/api/models/Note.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Serializable;
44
import java.util.Date;
5+
import java.util.List;
56

67
import org.gitlab4j.models.utils.JacksonJson;
78
import org.gitlab4j.models.utils.JacksonJsonEnumHelper;
@@ -96,7 +97,9 @@ public String toString() {
9697
// Use String for noteableType until the constant is fixed in the GitLab API
9798
private String noteableType;
9899

100+
private Long projectId;
99101
private Long noteableIid;
102+
private String commitId;
100103
private Boolean system;
101104
private String title;
102105
private Date updatedAt;
@@ -109,6 +112,7 @@ public String toString() {
109112
private Type type;
110113

111114
private Position position;
115+
private List<Suggestion> suggestions;
112116

113117
public String getAttachment() {
114118
return attachment;
@@ -190,6 +194,14 @@ public void setNoteableType(String noteableType) {
190194
this.noteableType = noteableType;
191195
}
192196

197+
public Long getProjectId() {
198+
return projectId;
199+
}
200+
201+
public void setProjectId(Long projectId) {
202+
this.projectId = projectId;
203+
}
204+
193205
public Long getNoteableIid() {
194206
return noteableIid;
195207
}
@@ -198,6 +210,14 @@ public void setNoteableIid(Long noteableIid) {
198210
this.noteableIid = noteableIid;
199211
}
200212

213+
public String getCommitId() {
214+
return commitId;
215+
}
216+
217+
public void setCommitId(String commitId) {
218+
this.commitId = commitId;
219+
}
220+
201221
public Boolean getSystem() {
202222
return system;
203223
}
@@ -286,6 +306,14 @@ public void setInternal(Boolean internal) {
286306
this.internal = internal;
287307
}
288308

309+
public List<Suggestion> getSuggestions() {
310+
return suggestions;
311+
}
312+
313+
public void setSuggestions(List<Suggestion> suggestions) {
314+
this.suggestions = suggestions;
315+
}
316+
289317
@Override
290318
public String toString() {
291319
return (JacksonJson.toJsonString(this));

gitlab4j-models/src/main/java/org/gitlab4j/api/models/Position.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public String toString() {
4848
private Integer height;
4949
private Double x;
5050
private Double y;
51+
private LineRange lineRange;
5152

5253
public String getBaseSha() {
5354
return baseSha;
@@ -205,6 +206,19 @@ public Position withY(Double y) {
205206
return (this);
206207
}
207208

209+
public LineRange getLineRange() {
210+
return lineRange;
211+
}
212+
213+
public void setLineRange(LineRange lineRange) {
214+
this.lineRange = lineRange;
215+
}
216+
217+
public Position withLineRange(LineRange lineRange) {
218+
this.lineRange = lineRange;
219+
return (this);
220+
}
221+
208222
@Override
209223
public String toString() {
210224
return (JacksonJson.toJsonString(this));
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.models.utils.JacksonJson;
6+
7+
public class Suggestion implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
private Long id;
11+
private Long fromLine;
12+
private Long toLine;
13+
private Boolean appliable;
14+
private Boolean applied;
15+
private String fromContent;
16+
private String toContent;
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public Long getFromLine() {
27+
return fromLine;
28+
}
29+
30+
public void setFromLine(Long fromLine) {
31+
this.fromLine = fromLine;
32+
}
33+
34+
public Long getToLine() {
35+
return toLine;
36+
}
37+
38+
public void setToLine(Long toLine) {
39+
this.toLine = toLine;
40+
}
41+
42+
public Boolean getAppliable() {
43+
return appliable;
44+
}
45+
46+
public void setAppliable(Boolean appliable) {
47+
this.appliable = appliable;
48+
}
49+
50+
public Boolean getApplied() {
51+
return applied;
52+
}
53+
54+
public void setApplied(Boolean applied) {
55+
this.applied = applied;
56+
}
57+
58+
public String getFromContent() {
59+
return fromContent;
60+
}
61+
62+
public void setFromContent(String fromContent) {
63+
this.fromContent = fromContent;
64+
}
65+
66+
public String getToContent() {
67+
return toContent;
68+
}
69+
70+
public void setToContent(String toContent) {
71+
this.toContent = toContent;
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return (JacksonJson.toJsonString(this));
77+
}
78+
}

gitlab4j-models/src/test/resources/org/gitlab4j/models/merge-request-discussions.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,67 @@
6868
"resolvable": true
6969
}
7070
]
71+
},
72+
{
73+
"id": "87805b7c09016a7058e91bdbe7b29d1f284a39e6",
74+
"individual_note": false,
75+
"notes": [
76+
{
77+
"id": 1128,
78+
"type": "DiffNote",
79+
"body": "diff comment",
80+
"author": {
81+
"id": 1,
82+
"name": "root",
83+
"username": "root",
84+
"state": "active",
85+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
86+
"web_url": "http://localhost:3000/root"
87+
},
88+
"created_at": "2018-03-04T09:17:22.520Z",
89+
"updated_at": "2018-03-04T09:17:22.520Z",
90+
"system": false,
91+
"noteable_id": 3,
92+
"noteable_type": "MergeRequest",
93+
"project_id": 5,
94+
"commit_id": "4803c71e6b1833ca72b8b26ef2ecd5adc8a38031",
95+
"position": {
96+
"base_sha": "b5d6e7b1613fca24d250fa8e5bc7bcc3dd6002ef",
97+
"start_sha": "7c9c2ead8a320fb7ba0b4e234bd9529a2614e306",
98+
"head_sha": "4803c71e6b1833ca72b8b26ef2ecd5adc8a38031",
99+
"old_path": "package.json",
100+
"new_path": "package.json",
101+
"position_type": "text",
102+
"old_line": 27,
103+
"new_line": 27,
104+
"line_range": {
105+
"start": {
106+
"line_code": "588440f66559714280628a4f9799f0c4eb880a4a_10_10",
107+
"type": "new",
108+
"new_line": 10
109+
},
110+
"end": {
111+
"line_code": "588440f66559714280628a4f9799f0c4eb880a4a_11_11",
112+
"type": "old",
113+
"old_line": 11,
114+
"new_line": 11
115+
}
116+
}
117+
},
118+
"resolved": false,
119+
"resolvable": true,
120+
"suggestions": [
121+
{
122+
"id": 1,
123+
"from_line": 27,
124+
"to_line": 27,
125+
"appliable": true,
126+
"applied": false,
127+
"from_content": "x",
128+
"to_content": "b"
129+
}
130+
]
131+
}
132+
]
71133
}
72134
]

0 commit comments

Comments
 (0)