Merge branch 'stable-3.0'
* stable-3.0:
Fix project import rollback
Adapt to Gerrit v3.0.0 API
Bump API version to v2.16.8
Change-Id: I9a0f41ad4fa87392e899fbe348f30c63bea7c27f
diff --git a/github-oauth/pom.xml b/github-oauth/pom.xml
index 8b749ff..cb738b5 100644
--- a/github-oauth/pom.xml
+++ b/github-oauth/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
<artifactId>github-parent</artifactId>
- <version>2.16.7</version>
+ <version>3.0.0</version>
</parent>
<artifactId>github-oauth</artifactId>
<name>Gerrit Code Review - GitHub OAuth login</name>
diff --git a/github-plugin/pom.xml b/github-plugin/pom.xml
index 84dce58..d252daa 100644
--- a/github-plugin/pom.xml
+++ b/github-plugin/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>github-parent</artifactId>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
- <version>2.16.7</version>
+ <version>3.0.0</version>
</parent>
<artifactId>github-plugin</artifactId>
diff --git a/github-plugin/src/main/java/com/google/gerrit/server/account/AccountImporter.java b/github-plugin/src/main/java/com/google/gerrit/server/account/AccountImporter.java
index 549c560..6a8a014 100644
--- a/github-plugin/src/main/java/com/google/gerrit/server/account/AccountImporter.java
+++ b/github-plugin/src/main/java/com/google/gerrit/server/account/AccountImporter.java
@@ -15,10 +15,9 @@
import com.google.common.base.MoreObjects;
import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.server.Sequences;
import com.google.gerrit.server.ServerInitiated;
import com.google.gerrit.server.account.externalids.ExternalId;
-import com.google.gwtorm.server.OrmException;
+import com.google.gerrit.server.notedb.Sequences;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
@@ -38,7 +37,7 @@
}
public Account.Id importAccount(String login, String name, String email)
- throws IOException, OrmException, ConfigInvalidException {
+ throws IOException, ConfigInvalidException {
Account.Id id = new Account.Id(sequences.nextAccountId());
List<ExternalId> extIds = new ArrayList<>();
extIds.add(ExternalId.createEmail(id, email));
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java
index e3006b6..5488838 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java
@@ -48,6 +48,7 @@
private final String organisation;
private final String repository;
+ private final ProjectConfig.Factory projectConfigFactory;
private MetaDataUpdate.User metaDataUpdateFactory;
private String description;
@@ -74,6 +75,7 @@
GitHubRepository.Factory ghRepoFactory,
GitHubConfig gitHubConfig,
OneOffRequestContext context,
+ ProjectConfig.Factory projectConfigFactory,
@Assisted("organisation") String organisation,
@Assisted("name") String repository,
@Assisted("description") String description,
@@ -90,6 +92,7 @@
this.username = username;
this.config = gitHubConfig;
this.context = context;
+ this.projectConfigFactory = projectConfigFactory;
}
private void setProjectPermissions() {
@@ -160,7 +163,7 @@
MetaDataUpdate md = null;
try (ManualRequestContext requestContext = context.openAs(config.importAccountId)) {
md = metaDataUpdateFactory.create(getProjectNameKey());
- projectConfig = ProjectConfig.read(md);
+ projectConfig = projectConfigFactory.read(md);
progress.beginTask("Configure Gerrit project", 2);
setProjectSettings();
progress.update(1);
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
index bcfc117..54ff346 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
@@ -14,11 +14,16 @@
package com.googlesource.gerrit.plugins.github.git;
import com.google.gerrit.extensions.api.GerritApi;
+import com.google.gerrit.extensions.api.changes.NotifyHandling;
+import com.google.gerrit.extensions.events.ProjectDeletedListener;
+import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
+import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.util.ManualRequestContext;
import com.google.gerrit.server.util.OneOffRequestContext;
-import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.googlesource.gerrit.plugins.github.GitHubConfig;
@@ -29,6 +34,8 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,6 +49,9 @@
private final String organisation;
private final String repository;
private final File destinationDirectory;
+ private final DynamicSet<ProjectDeletedListener> deletedListeners;
+ private final ProjectCache projectCache;
+ private final GitRepositoryManager repoManager;
public interface Factory {
GitCloneStep create(
@@ -54,6 +64,9 @@
GitHubRepository.Factory gitHubRepoFactory,
GerritApi gerritApi,
OneOffRequestContext context,
+ DynamicSet<ProjectDeletedListener> deletedListeners,
+ ProjectCache projectCache,
+ GitRepositoryManager repoManager,
@Assisted("organisation") String organisation,
@Assisted("name") String repository)
throws GitException {
@@ -67,6 +80,9 @@
this.organisation = organisation;
this.repository = repository;
this.destinationDirectory = prepareTargetGitDirectory(gitDir, organisation, repository);
+ this.deletedListeners = deletedListeners;
+ this.projectCache = projectCache;
+ this.repoManager = repoManager;
}
private static File prepareTargetGitDirectory(File gitDir, String organisation, String repository)
@@ -87,9 +103,6 @@
throw new GitDestinationAlreadyExistsException(projectName);
} catch (RestApiException e) {
throw new GitException("Unable to create repository " + projectName, e);
- } catch (OrmException e) {
- throw new GitException(
- "Unable to create request context to create a new project " + projectName, e);
}
}
@@ -123,11 +136,44 @@
}
try {
+ String projectName = organisation + "/" + repository;
+ Project.NameKey key = new Project.NameKey(projectName);
+ cleanJGitCache(key);
FileUtils.deleteDirectory(gitDirectory);
+ projectCache.remove(key);
+ sendProjectDeletedEvent(projectName);
return true;
} catch (IOException e) {
LOG.error("Cannot clean-up output Git directory " + gitDirectory);
return false;
}
}
+
+ private void cleanJGitCache(Project.NameKey key) throws IOException {
+ try (Repository repository = repoManager.openRepository(key)) {
+ RepositoryCache.close(repository);
+ }
+ }
+
+ private void sendProjectDeletedEvent(String projectName) {
+ ProjectDeletedListener.Event event =
+ new ProjectDeletedListener.Event() {
+ @Override
+ public String getProjectName() {
+ return projectName;
+ }
+
+ @Override
+ public NotifyHandling getNotify() {
+ return NotifyHandling.NONE;
+ }
+ };
+ for (ProjectDeletedListener l : deletedListeners) {
+ try {
+ l.onProjectDeleted(event);
+ } catch (RuntimeException e) {
+ LOG.warn("Failure in ProjectDeletedListener", e);
+ }
+ }
+ }
}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestCreateChange.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestCreateChange.java
index f2313a0..7ebe8d3 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestCreateChange.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestCreateChange.java
@@ -16,41 +16,31 @@
import static com.google.gerrit.reviewdb.client.RefNames.REFS_HEADS;
-import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.index.query.QueryParseException;
import com.google.gerrit.index.query.QueryResult;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.PatchSet;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.server.ReviewDb;
+import com.google.gerrit.reviewdb.client.*;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.IdentifiedUser.GenericFactory;
import com.google.gerrit.server.change.ChangeInserter;
import com.google.gerrit.server.change.PatchSetInserter;
import com.google.gerrit.server.notedb.ChangeNotes;
+import com.google.gerrit.server.notedb.Sequences;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gerrit.server.query.change.ChangeQueryProcessor;
import com.google.gerrit.server.query.change.InternalChangeQuery;
-import com.google.gerrit.server.submit.IntegrationException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.util.time.TimeUtil;
-import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import org.eclipse.jgit.errors.IncorrectObjectTypeException;
-import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -72,6 +62,7 @@
private final BatchUpdate.Factory updateFactory;
private final Provider<ChangeQueryProcessor> qp;
private final ChangeQueryBuilder changeQuery;
+ private final Sequences sequences;
@Inject
PullRequestCreateChange(
@@ -81,7 +72,8 @@
Provider<InternalChangeQuery> queryProvider,
BatchUpdate.Factory batchUpdateFactory,
Provider<ChangeQueryProcessor> qp,
- ChangeQueryBuilder changeQuery) {
+ ChangeQueryBuilder changeQuery,
+ Sequences sequences) {
this.changeInserterFactory = changeInserterFactory;
this.patchSetInserterFactory = patchSetInserterFactory;
this.userFactory = userFactory;
@@ -89,10 +81,10 @@
this.updateFactory = batchUpdateFactory;
this.qp = qp;
this.changeQuery = changeQuery;
+ this.sequences = sequences;
}
public Change.Id addCommitToChange(
- ReviewDb db,
final Project project,
final Repository repo,
final String destinationBranch,
@@ -100,15 +92,13 @@
final RevCommit pullRequestCommit,
final String pullRequestMessage,
final String topic)
- throws NoSuchChangeException, EmailException, OrmException, MissingObjectException,
- IncorrectObjectTypeException, IOException, InvalidChangeOperationException,
- IntegrationException, NoSuchProjectException, UpdateException, RestApiException {
+ throws NoSuchChangeException, IOException, InvalidChangeOperationException, UpdateException,
+ RestApiException {
try (BatchUpdate bu =
updateFactory.create(
- db, project.getNameKey(), userFactory.create(pullRequestOwner), TimeUtil.nowTs())) {
+ project.getNameKey(), userFactory.create(pullRequestOwner), TimeUtil.nowTs())) {
return internalAddCommitToChange(
- db,
bu,
project,
repo,
@@ -121,7 +111,6 @@
}
public Change.Id internalAddCommitToChange(
- ReviewDb db,
BatchUpdate bu,
final Project project,
final Repository repo,
@@ -130,8 +119,7 @@
final RevCommit pullRequestCommit,
final String pullRequestMesage,
final String topic)
- throws InvalidChangeOperationException, IOException, NoSuchProjectException, OrmException,
- UpdateException, RestApiException {
+ throws InvalidChangeOperationException, IOException, UpdateException, RestApiException {
if (destinationBranch == null || destinationBranch.length() == 0) {
throw new InvalidChangeOperationException("Destination branch cannot be null or empty");
}
@@ -201,7 +189,6 @@
// Change key not found on destination branch. We can create a new
// change.
return createNewChange(
- db,
bu,
changeKey,
project.getNameKey(),
@@ -218,7 +205,7 @@
try {
results = qp.get().query(changeQuery.commit(pullRequestSha1));
return results.entities();
- } catch (OrmException | QueryParseException e) {
+ } catch (QueryParseException e) {
LOG.error(
"Invalid SHA1 " + pullRequestSha1 + ": cannot query changes for this pull request", e);
return Collections.emptyList();
@@ -247,7 +234,6 @@
}
private Change.Id createNewChange(
- ReviewDb db,
BatchUpdate bu,
Change.Key changeKey,
Project.NameKey project,
@@ -257,11 +243,11 @@
String refName,
String pullRequestMessage,
String topic)
- throws OrmException, UpdateException, RestApiException, IOException {
+ throws UpdateException, RestApiException, IOException {
Change change =
new Change(
changeKey,
- new Change.Id(db.nextChangeId()),
+ new Change.Id(sequences.nextChangeId()),
pullRequestOwner,
new Branch.NameKey(project, destRef.getName()),
TimeUtil.nowTs());
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
index e54b2eb..cfc3a7d 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
@@ -23,16 +23,13 @@
import com.google.gerrit.reviewdb.client.Change.Id;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.NameKey;
-import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountImporter;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
-import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
-import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.googlesource.gerrit.plugins.github.git.GitJobStatus.Code;
import com.googlesource.gerrit.plugins.github.oauth.GitHubLogin;
@@ -88,7 +85,6 @@
private Project project;
private GitJobStatus status;
private boolean cancelRequested;
- private Provider<ReviewDb> schema;
private AccountImporter accountImporter;
@Inject
@@ -96,7 +92,6 @@
GitRepositoryManager repoMgr,
PullRequestCreateChange createChange,
ProjectCache projectCache,
- Provider<ReviewDb> schema,
AccountImporter accountImporter,
GitHubRepository.Factory gitHubRepoFactory,
ScopedProvider<GitHubLogin> ghLoginProvider,
@@ -115,7 +110,6 @@
this.project = fetchGerritProject(projectCache, organisation, repoName);
this.ghRepository = gitHubRepoFactory.create(organisation, repoName);
this.status = new GitJobStatus(jobIndex);
- this.schema = schema;
this.accountImporter = accountImporter;
this.externalIds = externalIds;
}
@@ -129,7 +123,7 @@
@Override
public void run() {
- try (ReviewDb db = schema.get()) {
+ try {
status.update(GitJobStatus.Code.SYNC);
exitWhenCancelled();
GHPullRequest pr = fetchGitHubPullRequestInfo();
@@ -141,7 +135,7 @@
fetchGitHubPullRequest(gitRepo, pr);
exitWhenCancelled();
- List<Id> changeIds = addPullRequestToChange(db, pr, gitRepo);
+ List<Id> changeIds = addPullRequestToChange(pr, gitRepo);
status.update(
GitJobStatus.Code.COMPLETE, "Imported", "PullRequest imported as Changes " + changeIds);
}
@@ -161,8 +155,7 @@
}
}
- private List<Id> addPullRequestToChange(ReviewDb db, GHPullRequest pr, Repository gitRepo)
- throws Exception {
+ private List<Id> addPullRequestToChange(GHPullRequest pr, Repository gitRepo) throws Exception {
String destinationBranch = REFS_HEADS + pr.getBase().getRef();
List<Id> prChanges = Lists.newArrayList();
ObjectId baseObjectId = ObjectId.fromString(pr.getBase().getSha());
@@ -185,10 +178,9 @@
GitUser commitAuthor = ghCommitDetail.getCommit().getAuthor();
GitHubUser gitHubUser = GitHubUser.from(prUser, commitAuthor);
- Account.Id pullRequestOwner = getOrRegisterAccount(db, gitHubUser);
+ Account.Id pullRequestOwner = getOrRegisterAccount(gitHubUser);
Id changeId =
createChange.addCommitToChange(
- db,
project,
gitRepo,
destinationBranch,
@@ -205,17 +197,16 @@
}
}
- private com.google.gerrit.reviewdb.client.Account.Id getOrRegisterAccount(
- ReviewDb db, GitHubUser author)
+ private com.google.gerrit.reviewdb.client.Account.Id getOrRegisterAccount(GitHubUser author)
throws BadRequestException, ResourceConflictException, UnprocessableEntityException,
- OrmException, IOException, ConfigInvalidException {
- return getOrRegisterAccount(db, author.getLogin(), author.getName(), author.getEmail());
+ IOException, ConfigInvalidException {
+ return getOrRegisterAccount(author.getLogin(), author.getName(), author.getEmail());
}
private com.google.gerrit.reviewdb.client.Account.Id getOrRegisterAccount(
- ReviewDb db, String login, String name, String email)
- throws OrmException, BadRequestException, ResourceConflictException,
- UnprocessableEntityException, IOException, ConfigInvalidException {
+ String login, String name, String email)
+ throws BadRequestException, ResourceConflictException, UnprocessableEntityException,
+ IOException, ConfigInvalidException {
Optional<ExternalId> gerritId = externalIdByScheme(ExternalId.SCHEME_GERRIT, login);
if (gerritId.isPresent()) {
return gerritId.get().accountId();
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java
index c4334be..250d7e5 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.github.replication;
-import com.google.gerrit.server.OutputFormat;
+import com.google.gerrit.json.OutputFormat;
import com.google.gson.Gson;
import com.google.inject.Provider;
import com.google.inject.Singleton;
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityStaticServlet.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityStaticServlet.java
index 3359065..06a5556 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityStaticServlet.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityStaticServlet.java
@@ -16,7 +16,7 @@
import com.google.common.collect.Maps;
import com.google.gerrit.util.http.CacheHeaders;
-import com.google.gwtjsonrpc.server.RPCServletUtils;
+import com.google.gerrit.util.http.RequestUtil;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -141,7 +141,7 @@
final String type = contentType(p.getName());
final byte[] tosend;
- if (!type.equals("application/x-javascript") && RPCServletUtils.acceptsGzipEncoding(req)) {
+ if (!type.equals("application/x-javascript") && RequestUtil.acceptsGzipEncoding(req)) {
rsp.setHeader("Content-Encoding", "gzip");
tosend = compress(readResource(p));
} else {
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
index e5166cd..e3fbc5a 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/AccountController.java
@@ -37,7 +37,6 @@
import com.google.gerrit.server.restapi.account.GetSshKeys;
import com.google.gerrit.server.restapi.account.PutName;
import com.google.gerrit.server.restapi.account.PutPreferred;
-import com.google.gwtorm.server.OrmDuplicateKeyException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.googlesource.gerrit.plugins.github.oauth.GitHubLogin;
@@ -150,8 +149,6 @@
"Set Username from GitHub",
accountId,
u -> u.addExternalId(ExternalId.create(key, accountId, null, null)));
- } catch (OrmDuplicateKeyException dupeErr) {
- throw new IllegalArgumentException("username " + username + " already in use");
} catch (Exception e) {
throw new IllegalArgumentException(
"Internal error while trying to set username='" + username + "'");
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
index b2998f5..941547d 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/PullRequestListController.java
@@ -19,7 +19,6 @@
import com.google.common.collect.Maps;
import com.google.gerrit.index.query.QueryParseException;
import com.google.gerrit.reviewdb.client.Project.NameKey;
-import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
@@ -28,7 +27,6 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
-import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -61,7 +59,6 @@
private final GitHubConfig config;
private final ProjectCache projectsCache;
private final GitRepositoryManager repoMgr;
- private final Provider<ReviewDb> schema;
private final Provider<ChangeQueryProcessor> qp;
private final ChangeQueryBuilder changeQuery;
@@ -69,13 +66,11 @@
public PullRequestListController(
ProjectCache projectsCache,
GitRepositoryManager repoMgr,
- Provider<ReviewDb> schema,
GitHubConfig config,
Provider<ChangeQueryProcessor> qp,
ChangeQueryBuilder changeQuery) {
this.projectsCache = projectsCache;
this.repoMgr = repoMgr;
- this.schema = schema;
this.config = config;
this.qp = qp;
this.changeQuery = changeQuery;
@@ -135,25 +130,22 @@
GitHubLogin login, Iterable<NameKey> repos) throws IOException {
int numPullRequests = 0;
Map<String, List<GHPullRequest>> allPullRequests = Maps.newHashMap();
- try (ReviewDb db = schema.get()) {
- for (NameKey gerritRepoName : repos) {
- try (Repository gitRepo = repoMgr.openRepository(gerritRepoName)) {
- String ghRepoName = gerritRepoName.get().split("/")[1];
- Optional<GHRepository> githubRepo = getGHRepository(login, gerritRepoName);
- if (githubRepo.isPresent()) {
- numPullRequests =
- collectPullRequestsFromGitHubRepository(
- numPullRequests, db, allPullRequests, gitRepo, ghRepoName, githubRepo);
- }
+ for (NameKey gerritRepoName : repos) {
+ try (Repository gitRepo = repoMgr.openRepository(gerritRepoName)) {
+ String ghRepoName = gerritRepoName.get().split("/")[1];
+ Optional<GHRepository> githubRepo = getGHRepository(login, gerritRepoName);
+ if (githubRepo.isPresent()) {
+ numPullRequests =
+ collectPullRequestsFromGitHubRepository(
+ numPullRequests, allPullRequests, gitRepo, ghRepoName, githubRepo);
}
}
- return allPullRequests;
}
+ return allPullRequests;
}
private int collectPullRequestsFromGitHubRepository(
int numPullRequests,
- ReviewDb db,
Map<String, List<GHPullRequest>> allPullRequests,
Repository gitRepo,
String ghRepoName,
@@ -165,7 +157,7 @@
if (count < config.pullRequestListLimit) {
for (GHPullRequest ghPullRequest : githubRepo.get().listPullRequests(GHIssueState.OPEN)) {
- if (isAnyCommitOfPullRequestToBeImported(db, gitRepo, ghPullRequest)) {
+ if (isAnyCommitOfPullRequestToBeImported(gitRepo, ghPullRequest)) {
repoPullRequests.add(ghPullRequest);
count++;
}
@@ -190,7 +182,7 @@
}
private boolean isAnyCommitOfPullRequestToBeImported(
- ReviewDb db, Repository gitRepo, GHPullRequest ghPullRequest)
+ Repository gitRepo, GHPullRequest ghPullRequest)
throws IncorrectObjectTypeException, IOException {
boolean pullRequestToImport = false;
try {
@@ -199,7 +191,7 @@
qp.get().query(changeQuery.commit(pullRequestCommit.getSha())).entities().isEmpty();
}
return pullRequestToImport;
- } catch (OrmException | QueryParseException e) {
+ } catch (QueryParseException e) {
LOG.error("Unable to query Gerrit changes for pull-request " + ghPullRequest.getNumber(), e);
return false;
}
diff --git a/pom.xml b/pom.xml
index 300219d..cc40c34 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
<artifactId>github-parent</artifactId>
- <version>2.16.7</version>
+ <version>3.0.0</version>
<name>Gerrit Code Review - GitHub integration</name>
<url>http://www.gerritforge.com</url>
<packaging>pom</packaging>