Merge branch 'stable-3.8' into stable-3.9
* stable-3.8:
Verify high-availability formatting using GJF 1.7
Check for existence of change's target SHA1 for reindexing
Remove `@NoHttpd` from IT tests that interact with Gerrit Rest API
Change-Id: Ie1c0db0578d460a7a31da3ab49468cf7627f89bc
diff --git a/Jenkinsfile b/Jenkinsfile
index 98183a5..503cf93 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,3 +1,4 @@
pluginPipeline(formatCheckId: 'gerritforge:plugins-high-availability-code-style',
buildCheckId: 'gerritforge:plugins-high-availability-build-test',
+ gjfVersion: '1.7',
extraModules: ['global-refdb'])
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
index 9236399..af730b7 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/index/ChangeCheckerImpl.java
@@ -31,6 +31,7 @@
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Optional;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -107,9 +108,9 @@
return (computedChangeTs.get() > indexEvent.eventCreatedOn)
|| (computedChangeTs.get() == indexEvent.eventCreatedOn)
&& (Objects.isNull(indexEvent.targetSha)
- || Objects.equals(getBranchTargetSha(), indexEvent.targetSha))
- && (Objects.isNull(indexEvent.metaSha)
- || Objects.equals(getMetaSha(repo), indexEvent.metaSha));
+ || repositoryHas(repo, indexEvent.targetSha))
+ && (Objects.isNull(indexEvent.targetSha)
+ || repositoryHas(repo, indexEvent.metaSha));
}
}
return true;
@@ -161,6 +162,16 @@
}
}
+ private boolean repositoryHas(Repository repo, String sha1ToCheck) {
+ try {
+ return repo.parseCommit(ObjectId.fromString(sha1ToCheck)) != null;
+ } catch (IOException e) {
+ log.atWarning().withCause(e).log(
+ "Unable to find SHA1 %s for change %s", sha1ToCheck, changeId);
+ return false;
+ }
+ }
+
private Optional<Long> computeLastChangeTs() {
return getChangeNotes().map(this::getTsFromChangeAndDraftComments);
}