-
Notifications
You must be signed in to change notification settings - Fork 277
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
Specify a prefix for limiting the list of Gerrit Projects #391
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,8 +54,9 @@ public class GerritProjectListUpdater extends Thread implements ConnectionListen | |
/** | ||
* The command for fetching projects. | ||
*/ | ||
public static final String GERRIT_LS_PROJECTS = "gerrit ls-projects"; | ||
public static final String GERRIT_LS_PROJECTS = "gerrit ls-projects --prefix "; | ||
private static final int MAX_WAIT_TIME = 64; | ||
private final String projectPrefix; | ||
|
||
private AtomicBoolean connected = new AtomicBoolean(false); | ||
private boolean shutdown = false; | ||
|
@@ -66,11 +67,13 @@ public class GerritProjectListUpdater extends Thread implements ConnectionListen | |
/** | ||
* Default constructor. | ||
* @param serverName the name of the Gerrit server. | ||
* @param projectPrefix of the projects to list from the Gerrit server. | ||
*/ | ||
public GerritProjectListUpdater(String serverName) { | ||
public GerritProjectListUpdater(String serverName, String projectPrefix) { | ||
this.setName(this.getClass().getName() + " for " + serverName + " Thread"); | ||
this.setDaemon(true); | ||
this.serverName = serverName; | ||
this.projectPrefix = projectPrefix; | ||
addThisAsListener(); | ||
} | ||
|
||
|
@@ -239,7 +242,8 @@ private void tryLoadProjectList() { | |
activeConfig.getGerritProxy(), | ||
activeConfig.getGerritAuthentication() | ||
); | ||
List<String> projects = readProjects(sshConnection.executeCommandReader(GERRIT_LS_PROJECTS)); | ||
List<String> projects = readProjects(sshConnection | ||
.executeCommandReader(GERRIT_LS_PROJECTS + projectPrefix)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we assume that htis works if |
||
if (projects.size() > 0) { | ||
setGerritProjects(projects); | ||
logger.info("Project list from {} contains {} entries", serverName, projects.size()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ public class GerritServer implements Describable<GerritServer>, Action { | |
private static final int RESPONSE_INTERVAL_MS = 1000; | ||
private static final int RESPONSE_TIMEOUT_S = 10; | ||
private String name; | ||
private String projectPrefix; | ||
@Deprecated | ||
private transient boolean pseudoMode; | ||
private boolean noConnectionOnStartup; | ||
|
@@ -251,6 +252,26 @@ public String getName() { | |
return name; | ||
} | ||
|
||
/** | ||
* Get the prefix for fetching all project names. | ||
* | ||
* @return projects prefix. | ||
*/ | ||
@Exported | ||
public String getProjectPrefix() { | ||
return projectPrefix; | ||
} | ||
|
||
/** | ||
* Set the prefix for fetching all project names. | ||
* | ||
* @param projectPrefix prefix of the projects to list from the Gerrit Server. | ||
*/ | ||
@Exported | ||
public void setProjectPrefix(String projectPrefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm missing something, but where does this get called? If it's not called from anywhere, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For backward compatibility, it will work as before. Need to find a place to hook into it, do you have any suggestions? I’m not very familiar with this codebase :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this uses an outdated way of doing Jenkins form submission. See |
||
this.projectPrefix = projectPrefix; | ||
} | ||
|
||
/** | ||
* Get hostname of the server. | ||
* | ||
|
@@ -445,7 +466,7 @@ public void start() { | |
initializeConnectionListener(); | ||
|
||
projectListUpdater = | ||
new GerritProjectListUpdater(name); | ||
new GerritProjectListUpdater(name, projectPrefix); | ||
projectListUpdater.start(); | ||
|
||
missedEventsPlaybackManager.checkIfEventsLogPluginSupported(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The
--prefix
option is not documented on thels-projects
command for 2.14, 2.15 or 2.16.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, this needs to be fixed in Gerrit though.
With regards to the support in Gerrit < 2.13, needs to be documented in this plugin and checked as soon as the version is queried.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've posted the documentation for review https://gerrit-review.googlesource.com/c/gerrit/+/212012