Skip to content

Commit

Permalink
Merge pull request #434 from spyrkob/accept_unknown_history
Browse files Browse the repository at this point in the history
Prevent an error if history contains event of unknown type
  • Loading branch information
spyrkob authored Aug 15, 2023
2 parents d1f4acb + c9a1c06 commit 4b88aa9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@

public class SavedState {

public enum Type { UPDATE, INSTALL, ROLLBACK, CONFIG_CHANGE;}
public enum Type {
UPDATE, INSTALL, ROLLBACK, CONFIG_CHANGE, UNKNOWN;
public static Type fromText(String text) {
for (Type value : Type.values()) {
if (value.name().equals(text)) {
return value;
}
}
return UNKNOWN;
}
}

private String hash;
private Instant timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<SavedState> getRevisions() throws MetadataException {
final String shortMessage = revCommit.getShortMessage().trim();
final int endOfTypeIndex = shortMessage.indexOf(' ');
final String type;
final String msg;
String msg;
if (endOfTypeIndex < 0) {
type = shortMessage;
msg = "";
Expand All @@ -90,9 +90,13 @@ public List<SavedState> getRevisions() throws MetadataException {
msg = shortMessage.substring(endOfTypeIndex + 1).trim();

}
final SavedState.Type recordType = SavedState.Type.fromText(type.toUpperCase(Locale.ROOT));
if (recordType == SavedState.Type.UNKNOWN) {
msg = shortMessage;
}
history.add(new SavedState(revCommit.getName().substring(0,8),
Instant.ofEpochSecond(revCommit.getCommitTime()),
SavedState.Type.valueOf(type.toUpperCase(Locale.ROOT)), msg));
recordType, msg));
}

return history;
Expand Down

0 comments on commit 4b88aa9

Please sign in to comment.