Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forge: more precise status for GitHub diff #917

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -383,11 +383,28 @@ private CommitMetadata toCommitMetadata(JSONValue o) {
return new CommitMetadata(hash, parents, author, authored, committer, committed, message);
}

private Status toStatus(String status) {
switch (status) {
case "modified":
return Status.from('M');
case "removed":
return Status.from('D');
case "added":
return Status.from('A');
case "renamed":
return Status.from('R');
case "copied":
return Status.from('C');
default:
throw new IllegalArgumentException("Unexpected status: " + status);
}
}

Diff toDiff(Hash from, Hash to, JSONValue files) {
var patches = new ArrayList<Patch>();

for (var file : files.asArray()) {
var status = Status.from(file.get("status").asString().toUpperCase().charAt(0));
var status = toStatus(file.get("status").asString());
var targetPath = Path.of(file.get("filename").asString());
var sourcePath = status.isRenamed() || status.isCopied() ?
Path.of(file.get("previous_filename").asString()) :