Search in sources :

Example 1 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class Schema_135 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    try (Repository git = repoManager.openRepository(allProjectsName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git)) {
        ProjectConfig config = ProjectConfig.read(md);
        AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
        Permission createRefsMetaConfigPermission = meta.getPermission(Permission.CREATE, true);
        Set<GroupReference> groups = Stream.concat(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true).getPermission(GlobalCapability.ADMINISTRATE_SERVER, true).getRules().stream().map(PermissionRule::getGroup), Stream.of(systemGroupBackend.getGroup(PROJECT_OWNERS))).filter(g -> createRefsMetaConfigPermission.getRule(g) == null).collect(toSet());
        for (GroupReference group : groups) {
            createRefsMetaConfigPermission.add(new PermissionRule(config.resolve(group)));
        }
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);
        md.setMessage(COMMIT_MSG);
        config.commit(md);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : PermissionRule(com.google.gerrit.common.data.PermissionRule) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) Inject(com.google.inject.Inject) AccessSection(com.google.gerrit.common.data.AccessSection) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) PROJECT_OWNERS(com.google.gerrit.server.group.SystemGroupBackend.PROJECT_OWNERS) Collectors.toSet(java.util.stream.Collectors.toSet) Permission(com.google.gerrit.common.data.Permission) Set(java.util.Set) IOException(java.io.IOException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) Stream(java.util.stream.Stream) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) RefNames(com.google.gerrit.reviewdb.client.RefNames) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) GroupReference(com.google.gerrit.common.data.GroupReference) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PermissionRule(com.google.gerrit.common.data.PermissionRule) IOException(java.io.IOException) AccessSection(com.google.gerrit.common.data.AccessSection) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) Permission(com.google.gerrit.common.data.Permission) GroupReference(com.google.gerrit.common.data.GroupReference) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 2 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class Schema_125 method getLabelTypes.

private Collection<LabelType> getLabelTypes(ProjectConfig config) throws IOException, ConfigInvalidException {
    Map<String, LabelType> labelTypes = new HashMap<>(config.getLabelSections());
    Project.NameKey parent = config.getProject().getParent(allProjectsName);
    while (parent != null) {
        try (Repository git = repoManager.openRepository(parent);
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, parent, git)) {
            ProjectConfig parentConfig = ProjectConfig.read(md);
            for (LabelType lt : parentConfig.getLabelSections().values()) {
                if (!labelTypes.containsKey(lt.getName())) {
                    labelTypes.put(lt.getName(), lt);
                }
            }
            parent = parentConfig.getProject().getParent(allProjectsName);
        }
    }
    return labelTypes.values();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) HashMap(java.util.HashMap) LabelType(com.google.gerrit.common.data.LabelType) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 3 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class AbstractPushForReview method testPushWithInvalidChangeIdFromEgit.

private void testPushWithInvalidChangeIdFromEgit() throws Exception {
    createCommit(testRepo, "Message with invalid Change-Id\n" + "\n" + "Change-Id: I0000000000000000000000000000000000000000\n");
    pushForReviewRejected(testRepo, "invalid Change-Id line format in commit message footer");
    ProjectConfig config = projectCache.checkedGet(project).getConfig();
    config.getProject().setRequireChangeID(InheritableBoolean.FALSE);
    saveProjectConfig(project, config);
    pushForReviewRejected(testRepo, "invalid Change-Id line format in commit message footer");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig)

Example 4 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method allowRunAs.

private void allowRunAs() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(allProjects).getConfig();
    Util.allow(cfg, GlobalCapability.RUN_AS, systemGroupBackend.getGroup(REGISTERED_USERS).getUUID());
    saveProjectConfig(allProjects, cfg);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig)

Example 5 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class ProjectWatchIT method noNotificationForDraftPatchSetsForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftPatchSetsForWatchersInNotifyConfig() throws Exception {
    Address addr = new Address("Watcher", "watcher@example.com");
    NotifyConfig nc = new NotifyConfig();
    nc.addEmail(addr);
    nc.setName("team");
    nc.setHeader(NotifyConfig.Header.TO);
    nc.setTypes(EnumSet.of(NotifyType.NEW_PATCHSETS, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    sender.clear();
    r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a2", r.getChangeId()).to("refs/for/master%draft");
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Address(com.google.gerrit.server.mail.Address) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ProjectConfig (com.google.gerrit.server.git.ProjectConfig)64 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)23 AccessSection (com.google.gerrit.common.data.AccessSection)15 Project (com.google.gerrit.reviewdb.client.Project)14 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)12 Permission (com.google.gerrit.common.data.Permission)10 PermissionRule (com.google.gerrit.common.data.PermissionRule)10 IOException (java.io.IOException)10 Repository (org.eclipse.jgit.lib.Repository)9 LabelType (com.google.gerrit.common.data.LabelType)8 Test (org.junit.Test)8 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 Before (org.junit.Before)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 GroupReference (com.google.gerrit.common.data.GroupReference)6 OrmException (com.google.gwtorm.server.OrmException)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 AuthException (com.google.gerrit.extensions.restapi.AuthException)4