|
1 | 1 | package org.kohsuke.github; |
2 | 2 |
|
3 | | -import com.infradna.tool.bridge_method_injector.WithBridgeMethods; |
4 | 3 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
5 | 4 |
|
6 | 5 | import java.io.IOException; |
@@ -34,94 +33,60 @@ public class GHCommit { |
34 | 33 | value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", |
35 | 34 | "UWF_UNWRITTEN_FIELD" }, |
36 | 35 | justification = "JSON API") |
37 | | - public static class ShortInfo { |
38 | | - private GHAuthor author; |
39 | | - private GHAuthor committer; |
| 36 | + public static class ShortInfo extends GitCommit { |
40 | 37 |
|
41 | | - private String message; |
42 | | - |
43 | | - private int comment_count; |
44 | | - |
45 | | - private GHVerification verification; |
46 | | - |
47 | | - static class Tree { |
48 | | - String sha; |
49 | | - } |
50 | | - |
51 | | - private Tree tree; |
52 | | - |
53 | | - /** |
54 | | - * Gets author. |
55 | | - * |
56 | | - * @return the author |
57 | | - */ |
58 | | - @WithBridgeMethods(value = GHAuthor.class, castRequired = true) |
59 | | - public GitUser getAuthor() { |
60 | | - return author; |
61 | | - } |
| 38 | + private int comment_count = -1; |
62 | 39 |
|
63 | 40 | /** |
64 | | - * Gets authored date. |
| 41 | + * Gets comment count. |
65 | 42 | * |
66 | | - * @return the authored date |
| 43 | + * @return the comment count |
67 | 44 | */ |
68 | | - public Date getAuthoredDate() { |
69 | | - return author.getDate(); |
| 45 | + public int getCommentCount() throws GHException { |
| 46 | + if (comment_count < 0) { |
| 47 | + throw new GHException("Not available on this endpoint."); |
| 48 | + } |
| 49 | + return comment_count; |
70 | 50 | } |
71 | 51 |
|
72 | 52 | /** |
73 | | - * Gets committer. |
74 | | - * |
75 | | - * @return the committer |
| 53 | + * Creates instance of {@link GHCommit.ShortInfo}. |
76 | 54 | */ |
77 | | - @WithBridgeMethods(value = GHAuthor.class, castRequired = true) |
78 | | - public GitUser getCommitter() { |
79 | | - return committer; |
80 | | - } |
| 55 | + public ShortInfo() { |
| 56 | + // Empty constructor required for Jackson binding |
| 57 | + }; |
81 | 58 |
|
82 | | - /** |
83 | | - * Gets commit date. |
84 | | - * |
85 | | - * @return the commit date |
86 | | - */ |
87 | | - public Date getCommitDate() { |
88 | | - return committer.getDate(); |
| 59 | + ShortInfo(GitCommit commit) { |
| 60 | + // Inherited copy constructor, used for bridge method from {@link GitCommit}, |
| 61 | + // which is used in {@link GHContentUpdateResponse}) to {@link GHCommit}. |
| 62 | + super(commit); |
89 | 63 | } |
90 | 64 |
|
91 | | - /** |
92 | | - * Gets message. |
93 | | - * |
94 | | - * @return Commit message. |
95 | | - */ |
96 | | - public String getMessage() { |
97 | | - return message; |
98 | | - } |
99 | | - |
100 | | - /** |
101 | | - * Gets comment count. |
102 | | - * |
103 | | - * @return the comment count |
104 | | - */ |
105 | | - public int getCommentCount() { |
106 | | - return comment_count; |
| 65 | + @Override |
| 66 | + public List<String> getParentSHA1s() { |
| 67 | + List<String> shortInfoParents = super.getParentSHA1s(); |
| 68 | + if (shortInfoParents == null) { |
| 69 | + throw new GHException("Not available on this endpoint. Try calling getParentSHA1s from outer class."); |
| 70 | + } |
| 71 | + return shortInfoParents; |
107 | 72 | } |
108 | 73 |
|
109 | | - /** |
110 | | - * Gets Verification Status. |
111 | | - * |
112 | | - * @return the Verification status |
113 | | - */ |
114 | | - public GHVerification getVerification() { |
115 | | - return verification; |
116 | | - } |
117 | 74 | } |
118 | 75 |
|
119 | 76 | /** |
120 | 77 | * The type GHAuthor. |
121 | 78 | * |
122 | 79 | * @deprecated Use {@link GitUser} instead. |
123 | 80 | */ |
| 81 | + @Deprecated |
124 | 82 | public static class GHAuthor extends GitUser { |
| 83 | + public GHAuthor() { |
| 84 | + super(); |
| 85 | + } |
| 86 | + |
| 87 | + public GHAuthor(GitUser user) { |
| 88 | + super(user); |
| 89 | + } |
125 | 90 | } |
126 | 91 |
|
127 | 92 | /** |
@@ -263,6 +228,27 @@ static class User { |
263 | 228 | List<Parent> parents; |
264 | 229 | User author, committer; |
265 | 230 |
|
| 231 | + /** |
| 232 | + * Creates an instance of {@link GHCommit}. |
| 233 | + */ |
| 234 | + public GHCommit() { |
| 235 | + // empty constructor needed for Jackson binding |
| 236 | + } |
| 237 | + |
| 238 | + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "acceptable") |
| 239 | + GHCommit(ShortInfo shortInfo) { |
| 240 | + // Constructs a (relatively sparse) GHCommit from a GitCommit. Used for |
| 241 | + // bridge method from {@link GitCommit}, which is used in |
| 242 | + // {@link GHContentUpdateResponse}) to {@link GHCommit}. |
| 243 | + commit = shortInfo; |
| 244 | + |
| 245 | + owner = commit.getOwner(); |
| 246 | + html_url = commit.getHtmlUrl(); |
| 247 | + sha = commit.getSha(); |
| 248 | + url = commit.getUrl(); |
| 249 | + parents = commit.getParents(); |
| 250 | + } |
| 251 | + |
266 | 252 | /** |
267 | 253 | * Gets commit short info. |
268 | 254 | * |
@@ -330,7 +316,7 @@ public int getLinesDeleted() throws IOException { |
330 | 316 | * on error |
331 | 317 | */ |
332 | 318 | public GHTree getTree() throws IOException { |
333 | | - return owner.getTree(getCommitShortInfo().tree.sha); |
| 319 | + return owner.getTree(getCommitShortInfo().getTreeSHA1()); |
334 | 320 | } |
335 | 321 |
|
336 | 322 | /** |
@@ -379,7 +365,7 @@ public List<File> getFiles() throws IOException { |
379 | 365 | * @return SHA1 of parent commit objects. |
380 | 366 | */ |
381 | 367 | public List<String> getParentSHA1s() { |
382 | | - if (parents == null) |
| 368 | + if (parents == null || parents.size() == 0) |
383 | 369 | return Collections.emptyList(); |
384 | 370 | return new AbstractList<String>() { |
385 | 371 | @Override |
@@ -596,4 +582,5 @@ GHCommit wrapUp(GHRepository owner) { |
596 | 582 | this.owner = owner; |
597 | 583 | return this; |
598 | 584 | } |
| 585 | + |
599 | 586 | } |
0 commit comments