Search in sources :

Example 26 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class CreateProjectIT method createProjectWithGitSuffix.

@Test
public void createProjectWithGitSuffix() throws Exception {
    String newProjectName = name("newProject");
    ProjectInfo p = gApi.projects().create(newProjectName + ".git").get();
    assertThat(p.name).isEqualTo(newProjectName);
    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
    assertThat(projectState).isPresent();
    assertProjectInfo(projectState.get().getProject(), p);
    assertHead(newProjectName, "refs/heads/master");
}
Also used : ProjectAssert.assertProjectInfo(com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class CreateProjectIT method createProjectWithOwner.

@Test
public void createProjectWithOwner() throws Exception {
    String newProjectName = name("newProject");
    ProjectInput in = new ProjectInput();
    in.name = newProjectName;
    in.owners = Lists.newArrayListWithCapacity(3);
    // by name
    in.owners.add("Anonymous Users");
    // by UUID
    in.owners.add(SystemGroupBackend.REGISTERED_USERS.get());
    in.owners.add(Integer.toString(groupCache.get(AccountGroup.nameKey("Administrators")).orElse(null).getId().get()));
    gApi.projects().create(in);
    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
    Set<AccountGroup.UUID> expectedOwnerIds = Sets.newHashSetWithExpectedSize(3);
    expectedOwnerIds.add(SystemGroupBackend.ANONYMOUS_USERS);
    expectedOwnerIds.add(SystemGroupBackend.REGISTERED_USERS);
    expectedOwnerIds.add(groupUuid("Administrators"));
    assertThat(projectState).isPresent();
    assertProjectOwners(expectedOwnerIds, projectState.get());
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class CreateProjectIT method createProject.

@Test
public void createProject() throws Exception {
    String newProjectName = name("newProject");
    ProjectInfo p = gApi.projects().create(newProjectName).get();
    assertThat(p.name).isEqualTo(newProjectName);
    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
    assertThat(projectState).isPresent();
    assertProjectInfo(projectState.get().getProject(), p);
    assertHead(newProjectName, "refs/heads/master");
    assertThat(readProjectConfig(newProjectName)).hasValue("[access]\n\tinheritFrom = All-Projects\n[submit]\n\taction = inherit\n");
}
Also used : ProjectAssert.assertProjectInfo(com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ProjectWatch method getWatchers.

/**
 * Returns all watchers that are relevant
 */
public final Watchers getWatchers(NotifyConfig.NotifyType type, boolean includeWatchersFromNotifyConfig) {
    Watchers matching = new Watchers();
    Set<Account.Id> projectWatchers = new HashSet<>();
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
        Account.Id accountId = a.account().id();
        for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyConfig.NotifyType>> e : a.projectWatches().entrySet()) {
            if (project.equals(e.getKey().project()) && add(matching, accountId, e.getKey(), e.getValue(), type)) {
                // We only want to prevent matching All-Projects if this filter hits
                projectWatchers.add(accountId);
            }
        }
    }
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(args.allProjectsName)) {
        for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyConfig.NotifyType>> e : a.projectWatches().entrySet()) {
            if (args.allProjectsName.equals(e.getKey().project())) {
                Account.Id accountId = a.account().id();
                if (!projectWatchers.contains(accountId)) {
                    add(matching, accountId, e.getKey(), e.getValue(), type);
                }
            }
        }
    }
    if (!includeWatchersFromNotifyConfig) {
        return matching;
    }
    for (ProjectState state : projectState.tree()) {
        for (NotifyConfig nc : state.getConfig().getNotifySections().values()) {
            if (nc.isNotify(type)) {
                try {
                    add(matching, state.getNameKey(), nc);
                } catch (QueryParseException e) {
                    logger.atInfo().log("Project %s has invalid notify %s filter \"%s\": %s", state.getName(), nc.getName(), nc.getFilter(), e.getMessage());
                }
            }
        }
    }
    return matching;
}
Also used : Account(com.google.gerrit.entities.Account) ProjectWatchKey(com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey) AccountState(com.google.gerrit.server.account.AccountState) QueryParseException(com.google.gerrit.index.query.QueryParseException) ImmutableSet(com.google.common.collect.ImmutableSet) NotifyConfig(com.google.gerrit.entities.NotifyConfig) ProjectState(com.google.gerrit.server.project.ProjectState) Map(java.util.Map) HashSet(java.util.HashSet)

Example 30 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ReviewCommand method parseCommandLine.

@Override
protected void parseCommandLine(DynamicOptions pluginOptions) throws UnloggedFailure {
    optionMap = new LinkedHashMap<>();
    customLabels = new HashMap<>();
    ProjectState allProjectsState;
    try {
        allProjectsState = projectCache.getAllProjects();
    } catch (Exception e) {
        throw die("missing " + allProjects.get(), e);
    }
    for (LabelType type : allProjectsState.getLabelTypes().getLabelTypes()) {
        StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
        for (LabelValue v : type.getValues()) {
            usage.append(v.format()).append("\n");
        }
        optionMap.put(newApproveOption(type, usage.toString()), new LabelSetter(type));
    }
    super.parseCommandLine(pluginOptions);
}
Also used : LabelValue(com.google.gerrit.entities.LabelValue) LabelType(com.google.gerrit.entities.LabelType) ProjectState(com.google.gerrit.server.project.ProjectState) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) CmdLineException(org.kohsuke.args4j.CmdLineException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) JsonSyntaxException(com.google.gson.JsonSyntaxException) StorageException(com.google.gerrit.exceptions.StorageException) IOException(java.io.IOException)

Aggregations

ProjectState (com.google.gerrit.server.project.ProjectState)86 Project (com.google.gerrit.entities.Project)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 IOException (java.io.IOException)18 Repository (org.eclipse.jgit.lib.Repository)18 AuthException (com.google.gerrit.extensions.restapi.AuthException)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Change (com.google.gerrit.entities.Change)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 Test (org.junit.Test)13 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)12 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 Inject (com.google.inject.Inject)10 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)10 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)10 StorageException (com.google.gerrit.exceptions.StorageException)9 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)9 ProjectResource (com.google.gerrit.server.project.ProjectResource)9