Skip to content

Commit d5e8c4c

Browse files
committed
Remove superfluous state reasons and events
Also removed the state reason field from issue data Signed-off-by: Leo Sendelbach <[email protected]>
1 parent 300dff7 commit d5e8c4c

File tree

7 files changed

+42
-138
lines changed

7 files changed

+42
-138
lines changed

src/de/uni_passau/fim/gitwrapper/EventData.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,17 @@ public UserData getAssigner() {
202202
*/
203203
public class StateChangedEventData extends EventData {
204204

205+
@Expose(deserialize = false)
206+
Commit commit;
205207
StateReason state_reason;
206208

209+
/**
210+
* The commit references.
211+
*/
212+
public Commit getCommit() {
213+
return commit;
214+
}
215+
207216
/**
208217
* The reason for the state change.
209218
*/
@@ -215,17 +224,7 @@ public StateReason getStateReason() {
215224
/**
216225
* An Event generated by changing the type of an issue.
217226
*/
218-
public class IssueTypeChangedEventData extends EventData {
219-
220-
@Expose(serialize = false)
221-
IssueTypeChangeEvent change_type;
222-
223-
/**
224-
* The type of change that occurred to the issue type.
225-
*/
226-
public IssueTypeChangeEvent getChangeType() {
227-
return change_type;
228-
}
227+
public class IssueTypeChangedEventData extends EventData {
229228
}
230229

231230
/**

src/de/uni_passau/fim/gitwrapper/EventDataProcessor.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ class EventDataProcessor implements JsonDeserializer<EventData>, JsonSerializer<
4646
map.put("referenced", EventData.ReferencedEventData.class);
4747
map.put("merged", EventData.ReferencedEventData.class);
4848
map.put("closed", EventData.StateChangedEventData.class);
49-
map.put("connected", EventData.ConnectedEventData.class);
5049
map.put("reopened", EventData.StateChangedEventData.class);
50+
map.put("connected", EventData.ConnectedEventData.class);
5151
map.put("issue_type_added", EventData.IssueTypeChangedEventData.class);
5252
map.put("issue_type_changed", EventData.IssueTypeChangedEventData.class);
5353
map.put("issue_type_removed", EventData.IssueTypeChangedEventData.class);
5454
map.put("parent_issue_added", EventData.ParentIssueChangedEventData.class);
5555
map.put("parent_issue_removed", EventData.ParentIssueChangedEventData.class);
56-
map.put("parent_issue_changed", EventData.ParentIssueChangedEventData.class);
5756
map.put("sub_issue_added", EventData.SubIssueChangedEventData.class);
5857
map.put("sub_issue_removed", EventData.SubIssueChangedEventData.class);
59-
map.put("sub_issue_changed", EventData.SubIssueChangedEventData.class);
6058
map.put("review_requested", EventData.RequestedReviewEventData.class);
6159
map.put("review_request_removed", EventData.RequestedReviewEventData.class);
6260
map.put("review_dismissed", EventData.DismissedReviewEventData.class);
@@ -181,13 +179,39 @@ public void postSerialize(JsonElement result, EventData.AssignedEventData src, G
181179
*/
182180
static class StateChangedEventProcessor implements PostProcessor<EventData.StateChangedEventData> {
183181

182+
private GitHubRepository repo;
183+
184+
/**
185+
* Creates a new EventDataProcessor for the given repo.
186+
*
187+
* @param repo
188+
* the repo
189+
*/
190+
StateChangedEventProcessor(GitHubRepository repo) {
191+
this.repo = repo;
192+
}
193+
184194
@Override
185195
public void postDeserialize(EventData.StateChangedEventData result, JsonElement src, Gson gson) {
186196
JsonElement stateReasonElement = src.getAsJsonObject().get("state_reason");
187197
String stateReasonValue = (stateReasonElement != null && !stateReasonElement.isJsonNull())
188198
? stateReasonElement.getAsString()
189199
: null;
190200
result.state_reason = StateReason.getFromString(stateReasonValue);
201+
202+
JsonElement hash = src.getAsJsonObject().get("commit_id");
203+
if (hash.isJsonNull()) {
204+
return;
205+
}
206+
207+
result.commit = repo.getGithubCommit(hash.getAsString()).orElseGet(() -> {
208+
LOG.warning("Found commit unknown to GitHub and local git repo: " + hash + " Retry using url...");
209+
JsonElement url = src.getAsJsonObject().get("commit_url");
210+
return repo.getGithubCommitUrl(hash.getAsString(), url.getAsString()).orElseGet(() -> {
211+
LOG.warning("Could not find commit: " + hash);
212+
return null;
213+
});
214+
});
191215
}
192216

193217
@Override
@@ -208,34 +232,6 @@ public void postSerialize(JsonElement result, EventData.IssueTypeChangedEventDat
208232
}
209233
}
210234

211-
/**
212-
* Processor for parent issue change events.
213-
*/
214-
static class ParentIssueChangedEventProcessor implements PostProcessor<EventData.ParentIssueChangedEventData> {
215-
216-
@Override
217-
public void postDeserialize(EventData.ParentIssueChangedEventData result, JsonElement src, Gson gson) {
218-
}
219-
220-
@Override
221-
public void postSerialize(JsonElement result, EventData.ParentIssueChangedEventData src, Gson gson) {
222-
}
223-
}
224-
225-
/**
226-
* Processor for sub-issue change events.
227-
*/
228-
static class SubIssueChangedEventProcessor implements PostProcessor<EventData.SubIssueChangedEventData> {
229-
230-
@Override
231-
public void postDeserialize(EventData.SubIssueChangedEventData result, JsonElement src, Gson gson) {
232-
}
233-
234-
@Override
235-
public void postSerialize(JsonElement result, EventData.SubIssueChangedEventData src, Gson gson) {
236-
}
237-
}
238-
239235
/**
240236
* Processor for connected events.
241237
*/

src/de/uni_passau/fim/gitwrapper/GitHubRepository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,8 @@ public GitHubRepository(String url, File dir, GitWrapper git, List<String> oauth
243243
gfb.registerPostProcessor(EventData.LabeledEventData.class, new EventDataProcessor.LabeledEventProcessor());
244244
gfb.registerPostProcessor(EventData.DismissedReviewEventData.class, new EventDataProcessor.DismissedReviewEventProcessor());
245245
gfb.registerPostProcessor(EventData.AssignedEventData.class, new EventDataProcessor.AssignedEventProcessor());
246-
gfb.registerPostProcessor(EventData.StateChangedEventData.class, new EventDataProcessor.StateChangedEventProcessor());
246+
gfb.registerPostProcessor(EventData.StateChangedEventData.class, new EventDataProcessor.StateChangedEventProcessor(this));
247247
gfb.registerPostProcessor(EventData.IssueTypeChangedEventData.class, new EventDataProcessor.IssueTypeChangedEventProcessor());
248-
gfb.registerPostProcessor(EventData.ParentIssueChangedEventData.class, new EventDataProcessor.ParentIssueChangedEventProcessor());
249-
gfb.registerPostProcessor(EventData.SubIssueChangedEventData.class, new EventDataProcessor.SubIssueChangedEventProcessor());
250248
gfb.registerPostProcessor(EventData.ConnectedEventData.class, new EventDataProcessor.ConnectedEventProcessor());
251249
gfb.registerPostProcessor(ReviewData.ReviewInitialCommentData.class, new ReviewDataProcessor.ReviewInitialCommentDataProcessor(this));
252250
GsonBuilder gb = gfb.createGsonBuilder();

src/de/uni_passau/fim/gitwrapper/IssueData.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class IssueData implements GitHubRepository.IssueDataCached {
4141
UserData user;
4242

4343
@Expose(deserialize = false) State state;
44-
@Expose(deserialize = false) StateReason state_reason;
4544
@Expose(deserialize = false) TypeData type;
4645
OffsetDateTime created_at;
4746
@Nullable OffsetDateTime closed_at;
@@ -197,15 +196,6 @@ public State getState() {
197196
return state;
198197
}
199198

200-
/**
201-
* Gets the reason for the current state of the issue.
202-
*
203-
* @return the state reason
204-
*/
205-
public StateReason getStateReason() {
206-
return state_reason;
207-
}
208-
209199
/**
210200
* Gets the date and time the issue was created.
211201
*

src/de/uni_passau/fim/gitwrapper/IssueDataProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ public void postDeserialize(IssueData result, JsonElement src, Gson gson) {
428428
String stateReasonValue = (stateReasonElement != null && !stateReasonElement.isJsonNull())
429429
? stateReasonElement.getAsString()
430430
: null;
431-
result.state_reason = StateReason.getFromString(stateReasonValue);
432431

433432
JsonElement typeElement = src.getAsJsonObject().get("type");
434433
if (typeElement != null && !typeElement.isJsonNull()) {

src/de/uni_passau/fim/gitwrapper/IssueTypeChangeEvent.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/de/uni_passau/fim/gitwrapper/StateReason.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,17 @@ public enum StateReason {
4040
/**
4141
* Denotes that the Issue or PullRequest was a duplicate.
4242
*/
43-
DUPLICATE,
44-
45-
/**
46-
* Denotes that the state reason is not known or not specified.
47-
* This can be used when the state reason is not applicable or not provided.
48-
*/
49-
NONE,
50-
51-
/**
52-
* Any state reason is included (can be used for unknown reasons).
53-
*/
54-
ANY;
43+
DUPLICATE;
5544

5645
/**
5746
* Gets the StateReason from a string.
5847
*
5948
* @param string the string to convert
60-
* @return the corresponding StateReason, or ANY if no match is found
49+
* @return the corresponding StateReason, the default case being 'COMPLETED'
6150
*/
6251
public static StateReason getFromString(String string) {
6352
if (string == null) {
64-
return NONE;
53+
return COMPLETED;
6554
}
6655

6756
switch (string.toLowerCase()) {
@@ -74,7 +63,7 @@ public static StateReason getFromString(String string) {
7463
case "duplicate":
7564
return DUPLICATE;
7665
default:
77-
return ANY;
66+
return COMPLETED;
7867
}
7968
}
8069
}

0 commit comments

Comments
 (0)