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

Store target hash before potentially fetching the ref #742

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
@@ -45,6 +45,7 @@ public class GitHubPullRequest implements PullRequest {
private final Logger log = Logger.getLogger("org.openjdk.skara.host");

private List<String> labels = null;
private Hash targetHash = null;

GitHubPullRequest(GitHubRepository repository, JSONValue jsonValue, RestRequest request) {
this.host = (GitHubHost)repository.forge();
@@ -257,12 +258,19 @@ public Optional<HostedRepository> sourceRepository() {

@Override
public String targetRef() {
return json.get("base").get("ref").asString();
var targetRef = json.get("base").get("ref").asString();
if (targetHash == null) {
// Read this value before returning, to ensure that future fetches of this ref contains the hash
targetHash = repository.branchHash(targetRef);
}
return targetRef;
}

@Override
public Hash targetHash() {
return repository.branchHash(targetRef());
// Ensure that the field is populated
targetRef();
return targetHash;
}

@Override
@@ -43,6 +43,8 @@ public class GitLabMergeRequest implements PullRequest {
private final Logger log = Logger.getLogger("org.openjdk.skara.host");;
private final GitLabRepository repository;

private Hash targetHash = null;

GitLabMergeRequest(GitLabRepository repository, JSONValue jsonValue, RestRequest request) {
this.repository = repository;
this.json = jsonValue;
@@ -278,12 +280,19 @@ public Optional<HostedRepository> sourceRepository() {

@Override
public String targetRef() {
return json.get("target_branch").asString();
var targetRef = json.get("target_branch").asString();
if (targetHash == null) {
// Read this value before returning, to ensure that future fetches of this ref contains the hash
targetHash = repository.branchHash(targetRef);
}
return targetRef;
}

@Override
public Hash targetHash() {
return repository.branchHash(targetRef());
// Ensure that the field is populated
targetRef();
return targetHash;
}

@Override