Skip to content

Commit

Permalink
2279: Improve JSONNumber::asInt usage to prevent future break
Browse files Browse the repository at this point in the history
Reviewed-by: erikj
  • Loading branch information
zhaosongzs committed Jun 7, 2024
1 parent 9d884b9 commit 3f7de91
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions forge/src/main/java/org/openjdk/skara/forge/Review.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -34,11 +34,11 @@ public class Review {
private final HostUser reviewer;
private final Verdict verdict;
private final Hash hash;
private final int id;
private final String id;
private final String body;
private final String targetRef;

public Review(ZonedDateTime createdAt, HostUser reviewer, Verdict verdict, Hash hash, int id, String body,
public Review(ZonedDateTime createdAt, HostUser reviewer, Verdict verdict, Hash hash, String id, String body,
String targetRef) {
this.createdAt = createdAt;
this.reviewer = reviewer;
Expand Down Expand Up @@ -73,7 +73,7 @@ public Optional<Hash> hash() {
return Optional.ofNullable(hash);
}

public int id() {
public String id() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -107,7 +107,7 @@ public List<Review> reviews() {
verdict = Review.Verdict.NONE;
break;
}
var id = obj.get("id").asInt();
var id = obj.get("id").toString();
var body = obj.get("body").asString();
var createdAt = ZonedDateTime.parse(obj.get("submitted_at").asString());
return new Review(createdAt, reviewer, verdict, hash, id, body, currentTargetRef);
Expand Down Expand Up @@ -349,7 +349,7 @@ public void setBody(String body) {
}

private Comment parseComment(JSONValue comment) {
var ret = new Comment(Long.toString(comment.get("id").asLong()),
var ret = new Comment(comment.get("id").toString(),
comment.get("body").asString(),
host.parseUserField(comment),
ZonedDateTime.parse(comment.get("created_at").asString()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -137,7 +137,7 @@ class CommitDate {
hash = cd.hash;
}
}
var id = obj.get("id").asInt();
var id = obj.get("id").toString();
return new Review(createdAt, reviewer, verdict, hash, id, "", currentTargetRef);
}).toList();
var targetRefChanges = targetRefChanges(notes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -509,7 +509,7 @@ private CommitComment toCommitComment(Hash hash, JSONValue o) {
return new CommitComment(hash,
path,
line,
String.valueOf(note.get("id").asInt()),
note.get("id").toString(),
note.get("body").asString(),
gitLabHost.parseAuthorField(note),
ZonedDateTime.parse(note.get("created_at").asString()),
Expand Down Expand Up @@ -603,7 +603,7 @@ public List<CommitComment> recentCommitComments(ReadOnlyRepository localRepo, Se

return notes.stream()
.map(o -> findComment(o.get("target_title").asString(),
String.valueOf(o.get("note").get("id").asInt()), commitTitleToCommits))
o.get("note").get("id").toString(), commitTitleToCommits))
.flatMap(Optional::stream)
.toList();
}
Expand Down
22 changes: 11 additions & 11 deletions forge/src/test/java/org/openjdk/skara/forge/PullRequestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PullRequestTests {
@Test
void calculateReviewTargetRefsSimple() {
assertEquals(List.of(), PullRequest.calculateReviewTargetRefs(List.of(), List.of()));
var review1 = newReview(ZonedDateTime.now(), 1, "master");
var review1 = newReview(ZonedDateTime.now(), "1", "master");
assertEquals(List.of(review1), PullRequest.calculateReviewTargetRefs(List.of(review1), List.of()));
}

Expand All @@ -45,9 +45,9 @@ void calculateReviewTargetRefs2Changes() {
var refChange1 = new ReferenceChange("first", "second", now.minus(Duration.ofMinutes(4)));
var refChange2 = new ReferenceChange("second", "third", now.minus(Duration.ofMinutes(2)));

var review1 = newReview(now.minus(Duration.ofMinutes(5)), 1, "third");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), 2, "third");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), 3, "third");
var review1 = newReview(now.minus(Duration.ofMinutes(5)), "1", "third");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), "2", "third");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), "3", "third");

var reviews = PullRequest.calculateReviewTargetRefs(List.of(review1, review2, review3), List.of(refChange2, refChange1));

Expand All @@ -64,9 +64,9 @@ void calculateReviewTargetRefsPreIntegrationBranch() {
var refChange1 = new ReferenceChange("first", "pr/4711", now.minus(Duration.ofMinutes(4)));
var refChange2 = new ReferenceChange("pr/4711", "third", now.minus(Duration.ofMinutes(2)));

var review1 = newReview(now.minus(Duration.ofMinutes(5)), 1, "");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), 2, "");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), 3, "third");
var review1 = newReview(now.minus(Duration.ofMinutes(5)), "1", "");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), "2", "");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), "3", "third");

var reviews = PullRequest.calculateReviewTargetRefs(List.of(review1, review2, review3), List.of(refChange1, refChange2));

Expand All @@ -83,9 +83,9 @@ void calculateReviewTargetRefsPreIntegrationBranchLast() {
var refChange1 = new ReferenceChange("first", "pr/4711", now.minus(Duration.ofMinutes(4)));
var refChange2 = new ReferenceChange("pr/4711", "pr/4712", now.minus(Duration.ofMinutes(2)));

var review1 = newReview(now.minus(Duration.ofMinutes(5)), 1, "");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), 2, "foo");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), 3, "pr/4712");
var review1 = newReview(now.minus(Duration.ofMinutes(5)), "1", "");
var review2 = newReview(now.minus(Duration.ofMinutes(3)), "2", "foo");
var review3 = newReview(now.minus(Duration.ofMinutes(1)), "3", "pr/4712");

var reviews = PullRequest.calculateReviewTargetRefs(List.of(review1, review2, review3), List.of(refChange1, refChange2));

Expand All @@ -98,7 +98,7 @@ void calculateReviewTargetRefsPreIntegrationBranchLast() {
/**
* Creates a new review with just the relevant fields.
*/
private Review newReview(ZonedDateTime createdAt, int id, String targetRef) {
private Review newReview(ZonedDateTime createdAt, String id, String targetRef) {
return new Review(createdAt, null, Review.Verdict.APPROVED, null, id, null, targetRef);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -87,7 +87,7 @@ public void addReview(Review.Verdict verdict, String body) {
try {
var review = new Review(ZonedDateTime.now(), user,
verdict, targetRepository.localRepository().resolve(store().sourceRef()).orElseThrow(),
store().reviews().size(),
String.valueOf(store().reviews().size()),
body, targetRef);

store().reviews().add(review);
Expand Down

0 comments on commit 3f7de91

Please sign in to comment.