use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class SubmitRuleEvaluator method evaluate.
/**
* Evaluate the submit rules.
*
* @return List of {@link SubmitRecord} objects returned from the evaluated rules, including any
* errors.
* @param cd ChangeData to evaluate
*/
public List<SubmitRecord> evaluate(ChangeData cd) {
logger.atFine().log("Evaluate submit rules for change %d (caller: %s)", cd.change().getId().get(), callerFinder.findCallerLazy());
try (Timer0.Context ignored = submitRuleEvaluationLatency.start()) {
Change change;
ProjectState projectState;
try {
change = cd.change();
if (change == null) {
throw new StorageException("Change not found");
}
Project.NameKey name = cd.project();
Optional<ProjectState> projectStateOptional = projectCache.get(name);
if (!projectStateOptional.isPresent()) {
throw new NoSuchProjectException(name);
}
projectState = projectStateOptional.get();
} catch (NoSuchProjectException e) {
throw new IllegalStateException("Unable to find project while evaluating submit rule", e);
}
if (change.isClosed() && (!opts.recomputeOnClosedChanges() || OnlineReindexMode.isActive())) {
return cd.notes().getSubmitRecords().stream().map(r -> {
SubmitRecord record = r.deepCopy();
if (record.status == SubmitRecord.Status.OK) {
// Submit records that were OK when they got merged are CLOSED now.
record.status = SubmitRecord.Status.CLOSED;
}
return record;
}).collect(toImmutableList());
}
// and then we collect the results in one list.
return Streams.stream(submitRules).filter(projectState.hasPrologRules() ? rule -> !(rule.get() instanceof DefaultSubmitRule) : rule -> true).map(c -> c.call(s -> {
Optional<SubmitRecord> record = s.evaluate(cd);
if (record.isPresent() && record.get().ruleName == null) {
// Only back-fill the ruleName if it was not populated by the "submit
// rule".
record.get().ruleName = c.getPluginName() + "~" + s.getClass().getSimpleName();
}
return record;
})).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class AbstractGitCommand method start.
@Override
public void start(ChannelSession channel, Environment env) {
enableGracefulStop();
String gitProtocol = env.getEnv().get(GIT_PROTOCOL);
if (gitProtocol != null) {
extraParameters = gitProtocol.split(":");
}
Context ctx = context.subContext(newSession(), context.getCommandLine());
final Context old = sshScope.set(ctx);
try {
startThread(new ProjectCommandRunnable() {
@Override
public void executeParseCommand(DynamicOptions pluginOptions) throws Exception {
parseCommandLine(pluginOptions);
}
@Override
public void run() throws Exception {
AbstractGitCommand.this.service();
}
@Override
public Project.NameKey getProjectName() {
Project project = projectState.getProject();
return project.getNameKey();
}
}, AccessPath.GIT);
} finally {
sshScope.set(old);
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class SubmoduleSectionParser method parse.
private SubmoduleSubscription parse(String id) {
final String url = config.getString("submodule", id, "url");
final String path = config.getString("submodule", id, "path");
String branch = config.getString("submodule", id, "branch");
try {
if (url != null && url.length() > 0 && path != null && path.length() > 0 && branch != null && branch.length() > 0) {
// All required fields filled.
String project;
if (branch.equals(".")) {
branch = superProjectBranch.branch();
}
// relative URL
if (url.startsWith("../")) {
// prefix with a slash for easier relative path walks
project = '/' + superProjectBranch.project().get();
String hostPart = url;
while (hostPart.startsWith("../")) {
int lastSlash = project.lastIndexOf('/');
if (lastSlash < 0) {
// too many levels up, ignore for now
return null;
}
project = project.substring(0, lastSlash);
hostPart = hostPart.substring(3);
}
project = project + "/" + hostPart;
// remove leading '/'
project = project.substring(1);
} else {
// It is actually an URI. It could be ssh://localhost/project-a.
URI targetServerURI = new URI(url);
URI thisServerURI = new URI(canonicalWebUrl);
String thisHost = thisServerURI.getHost();
String targetHost = targetServerURI.getHost();
if (thisHost == null || targetHost == null || !targetHost.equalsIgnoreCase(thisHost)) {
return null;
}
String p1 = targetServerURI.getPath();
String p2 = thisServerURI.getPath();
if (!p1.startsWith(p2)) {
// http://server/other-teams-gerrit/
return null;
}
// skip common part
project = p1.substring(p2.length());
}
while (project.startsWith("/")) {
project = project.substring(1);
}
if (project.endsWith(Constants.DOT_GIT_EXT)) {
project = project.substring(//
0, project.length() - Constants.DOT_GIT_EXT.length());
}
Project.NameKey projectKey = Project.nameKey(project);
return new SubmoduleSubscription(superProjectBranch, BranchNameKey.create(projectKey, branch), path);
}
} catch (URISyntaxException e) {
// Error in url syntax (in fact it is uri syntax)
}
return null;
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectIT method maxObjectSizeIsInheritedFromGlobalConfig.
@Test
@GerritConfig(name = "receive.maxObjectSizeLimit", value = "200k")
public void maxObjectSizeIsInheritedFromGlobalConfig() throws Exception {
Project.NameKey child = projectOperations.newProject().parent(project).create();
ConfigInfo info = getConfig();
assertThat(info.maxObjectSizeLimit.value).isEqualTo("204800");
assertThat(info.maxObjectSizeLimit.configuredValue).isNull();
assertThat(info.maxObjectSizeLimit.summary).isEqualTo(INHERITED_FROM_GLOBAL);
info = getConfig(child);
assertThat(info.maxObjectSizeLimit.value).isEqualTo("204800");
assertThat(info.maxObjectSizeLimit.configuredValue).isNull();
assertThat(info.maxObjectSizeLimit.summary).isEqualTo(INHERITED_FROM_GLOBAL);
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectIT method maxObjectSizeDoesNotOverrideParentProjectWhenHigher.
@Test
@GerritConfig(name = "receive.inheritProjectMaxObjectSizeLimit", value = "true")
public void maxObjectSizeDoesNotOverrideParentProjectWhenHigher() throws Exception {
Project.NameKey child = projectOperations.newProject().parent(project).create();
ConfigInfo info = setMaxObjectSize("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("102400");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.summary).isNull();
info = setMaxObjectSize(child, "200k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("102400");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("200k");
assertThat(info.maxObjectSizeLimit.summary).isEqualTo(String.format(OVERRIDDEN_BY_PARENT, project));
}
Aggregations