Skip to content

Commit 781e013

Browse files
JENKINS-49202: Add getComment() to ChangeLogSet.Entry with tests
1 parent 9dd8712 commit 781e013

File tree

2 files changed

+119
-21
lines changed

2 files changed

+119
-21
lines changed

core/src/main/java/hudson/scm/ChangeLogSet.java

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
* For the change list at project level, see {@link SCM}.
4848
*
4949
* <p>
50-
* {@link Iterator} is expected to return newer changes first then older changes
51-
* later.
50+
* {@link Iterator} is expected to return newer changes first then older changes later.
5251
*
5352
* @author Kohsuke Kawaguchi
5453
*/
@@ -117,7 +116,6 @@ public final Object[] getItems() {
117116

118117
/**
119118
* Optional identification of the kind of SCM being used.
120-
*
121119
* @return a short token, such as the SCM's main CLI executable name
122120
* @since 1.284
123121
*/
@@ -128,7 +126,6 @@ public String getKind() {
128126

129127
/**
130128
* Constant instance that represents no changes.
131-
*
132129
* @since 1.568
133130
*/
134131
public static ChangeLogSet<? extends ChangeLogSet.Entry> createEmpty(Run build) {
@@ -156,8 +153,16 @@ protected void setParent(ChangeLogSet parent) {
156153
}
157154

158155
/**
159-
* Returns a human readable display name of the commit number, revision number,
160-
* etc.
156+
* Returns a human readable display name of the commit number, revision number, and such thing
157+
* that identifies this entry.
158+
*
159+
* <p>
160+
* This method is primarily intended for visualization of the data.
161+
*
162+
* @return
163+
* null if such a concept doesn't make sense for the implementation. For example,
164+
* in CVS there's no single identifier for commits. Each file gets a different revision number.
165+
* @since 1.405
161166
*/
162167
@Exported
163168
public String getCommitId() {
@@ -166,26 +171,38 @@ public String getCommitId() {
166171

167172
/**
168173
* Returns the timestamp of this commit in the {@link Date#getTime()} format.
174+
*
175+
* <p>
176+
* This method is primarily intended for visualization of the data.
177+
*
178+
* @return
179+
* -1 if the implementation doesn't support it (for example, in CVS a commit
180+
* spreads over time between multiple changes on multiple files, so there's no single timestamp.)
181+
* @since 1.405
169182
*/
170183
@Exported
171184
public long getTimestamp() {
172185
return -1;
173186
}
174187

175188
/**
176-
* Gets the first line commit message (short message).
189+
* Gets the "commit message".
190+
*
191+
* <p>
192+
* The exact definition depends on the individual SCM implementation.
193+
*
194+
* @return
195+
* Can be empty but never null.
177196
*/
178197
@Exported
179198
public abstract String getMsg();
180199

181-
/**
182-
* Returns the full commit message.
200+
/** Returns the full commit message.
183201
*
184-
* Default implementation returns the same value as getMsg().
185-
* SCM implementations can override this if they support full message
186-
* separately.
202+
* Default implementation returns the same value as {@link #getMsg()}.
203+
* SCM implementations may override if they provide a separate full message.
187204
*
188-
* @since TODO
205+
* @since 2.552
189206
*/
190207
@Exported
191208
public String getComment() {
@@ -194,26 +211,46 @@ public String getComment() {
194211

195212
/**
196213
* The user who made this change.
214+
*
215+
* @return
216+
* never null.
197217
*/
198218
@Exported
199219
public abstract User getAuthor();
200220

201221
/**
202-
* Returns affected paths.
222+
* Returns a set of paths in the workspace that was
223+
* affected by this change.
224+
*
225+
* <p>
226+
* Contains string like 'foo/bar/zot'. No leading/trailing '/',
227+
* and separator must be normalized to '/'.
228+
*
229+
* @return never null.
203230
*/
204231
@Exported
205232
public abstract Collection<String> getAffectedPaths();
206233

207234
/**
208-
* Returns affected files.
235+
* Returns a set of paths in the workspace that was
236+
* affected by this change.
237+
* <p>
238+
* Noted: since this is a new interface, some of the SCMs may not have
239+
* implemented this interface. The default implementation for this
240+
* interface is throw UnsupportedOperationException
241+
* <p>
242+
* It doesn't throw NoSuchMethodException because I rather to throw a
243+
* runtime exception
244+
*
245+
* @return AffectedFile never null.
246+
* @since 1.309
209247
*/
210248
public Collection<? extends AffectedFile> getAffectedFiles() {
211249
String scm = "this SCM";
212250
ChangeLogSet parent = getParent();
213251
if (null != parent) {
214252
String kind = parent.getKind();
215-
if (null != kind && !kind.trim().isEmpty())
216-
scm = kind;
253+
if (null != kind && !kind.trim().isEmpty()) scm = kind;
217254
}
218255
throw new UnsupportedOperationException("getAffectedFiles() is not implemented by " + scm);
219256
}
@@ -227,11 +264,9 @@ public String getMsgAnnotated() {
227264
try {
228265
a.annotate(parent.run, this, markup);
229266
} catch (RuntimeException e) {
230-
LOGGER.info("ChangeLogAnnotator " + a.toString() + " failed to annotate message '" + getMsg()
231-
+ "'; " + e.getMessage());
267+
LOGGER.info("ChangeLogAnnotator " + a.toString() + " failed to annotate message '" + getMsg() + "'; " + e.getMessage());
232268
} catch (Error e) {
233-
LOGGER.severe("ChangeLogAnnotator " + a + " failed to annotate message '" + getMsg() + "'; "
234-
+ e.getMessage());
269+
LOGGER.severe("ChangeLogAnnotator " + a + " failed to annotate message '" + getMsg() + "'; " + e.getMessage());
235270
}
236271

237272
return markup.toString(false);
@@ -266,6 +301,7 @@ public interface AffectedFile {
266301
*/
267302
String getPath();
268303

304+
269305
/**
270306
* Return whether the file is new/modified/deleted
271307
*/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package hudson.scm;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import hudson.model.User;
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class ChangeLogSetEntryTest {
11+
12+
@Test
13+
public void getCommentDefaultsToMsg() {
14+
ChangeLogSet.Entry entry = new ChangeLogSet.Entry() {
15+
16+
@Override
17+
public String getMsg() {
18+
return "short message";
19+
}
20+
21+
@Override
22+
public User getAuthor() {
23+
return null;
24+
}
25+
26+
@Override
27+
public Collection<String> getAffectedPaths() {
28+
return Collections.emptyList();
29+
}
30+
};
31+
32+
assertEquals("short message", entry.getComment());
33+
}
34+
35+
@Test
36+
public void getCommentCanBeOverridden() {
37+
ChangeLogSet.Entry entry = new ChangeLogSet.Entry() {
38+
39+
@Override
40+
public String getMsg() {
41+
return "short";
42+
}
43+
44+
@Override
45+
public String getComment() {
46+
return "full commit message";
47+
}
48+
49+
@Override
50+
public User getAuthor() {
51+
return null;
52+
}
53+
54+
@Override
55+
public Collection<String> getAffectedPaths() {
56+
return Collections.emptyList();
57+
}
58+
};
59+
60+
assertEquals("full commit message", entry.getComment());
61+
}
62+
}

0 commit comments

Comments
 (0)