automerger plugin configuration

180 views
Skip to first unread message

jiri...@gmail.com

unread,
Mar 3, 2021, 5:24:28 AM3/3/21
to Repo and Gerrit Discussion

Hi,

I would like to use the automerger plugin but I have some questions about the config and installation.

or do I have to build it from branch 3.1 source myself?

2) where is the automerger.config file located? The documentaion in https://gerrit.googlesource.com/plugins/automerger/+/refs/heads/master/src/main/resources/Documentation/config.md isn't clear for me in this.

3) do I understand it correctly the config has to be for each repository separately? Or is it possible to have just one config file with a list of repositories?

Thanks for clarifying my answers.

Best regards
Jiri Tomek

David Ostrovsky

unread,
Mar 3, 2021, 2:30:31 PM3/3/21
to Repo and Gerrit Discussion
jiri...@gmail.com schrieb am Mittwoch, 3. März 2021 um 11:24:28 UTC+1:

Hi,

I would like to use the automerger plugin but I have some questions about the config and installation.


I've uploaded this change to build automerger plugin against stable-3.1
branch on gerrit CI, two months ago, but the change wasn't reviewed yet [1].

 
or do I have to build it from branch 3.1 source myself?

2) where is the automerger.config file located? The documentaion in https://gerrit.googlesource.com/plugins/automerger/+/refs/heads/master/src/main/resources/Documentation/config.md isn't clear for me in this.


I think it's on refs/meta/config branch of All-Projects repository, see this
plugin development documentation: [2].

 
3) do I understand it correctly the config has to be for each repository separately? Or is it possible to have just one config file with a list of repositories?


As the plugin configuration is on All-Projects repository, multiple projects
could be configured in config file. See this example config file in plugin
tree: [3], where multiple projects are configured.
 

Luca Milanesio

unread,
Mar 3, 2021, 4:21:03 PM3/3/21
to David Ostrovsky, Luca Milanesio, Repo and Gerrit Discussion

On 3 Mar 2021, at 19:30, David Ostrovsky <david.o...@gmail.com> wrote:



jiri...@gmail.com schrieb am Mittwoch, 3. März 2021 um 11:24:28 UTC+1:

Hi,

I would like to use the automerger plugin but I have some questions about the config and installation.


I've uploaded this change to build automerger plugin against stable-3.1
branch on gerrit CI, two months ago, but the change wasn't reviewed yet [1].


Let me verify and merge it.

Luca.

 
or do I have to build it from branch 3.1 source myself?

2) where is the automerger.config file located? The documentaion in https://gerrit.googlesource.com/plugins/automerger/+/refs/heads/master/src/main/resources/Documentation/config.md isn't clear for me in this.


I think it's on refs/meta/config branch of All-Projects repository, see this
plugin development documentation: [2].

 
3) do I understand it correctly the config has to be for each repository separately? Or is it possible to have just one config file with a list of repositories?


As the plugin configuration is on All-Projects repository, multiple projects
could be configured in config file. See this example config file in plugin
tree: [3], where multiple projects are configured.
 

Thanks for clarifying my answers.

Best regards
Jiri Tomek

-- 
-- 
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/86bcaef0-0e23-4514-a1c3-d7b0c57be46fn%40googlegroups.com.

jiri...@gmail.com

unread,
Mar 5, 2021, 6:05:58 AM3/5/21
to Repo and Gerrit Discussion
Thanks @Luca for providing the jar file and thanks @David for clarification.

I have now automerger.config file in All-Projects repository on refs/meta/config branch with following content:

[global]
  manifestFile = default.xml
  manifestProject = sandbox/version
[automerger "v3r4:v3r5"]
  mergeAll = true


If I do a change on v3r4 branch, commit that, I push it for a review and finally review is submitted I see no merge coming to v3r5 branch.

Then when I added   setProjects option to automerger section automerging started to work.

[global]
  manifestFile = default.xml
  manifestProject = sandbox/version
[automerger "v3r4:v3r5"]
  setProjects = sandbox/version
  mergeAll = true


I thought the automerger plugin will read the list of projects from manifest file and run the merge over all of them unless ignoreProjects option is set up for some of them.
The manifest file default.xml content:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>

        <remote name="gitserver"
                fetch="https://git.domain.net"
                review="http://review.domain.net" />
        <default revision="refs/heads/v3r4"
                remote="gitserver"
                sync-j="4" />

        <project path="version"
                name="sandbox/version.git"
                remote="gitserver" />

</manifest>


I don't want to get in situation I'll need to maintain a list of projects on two places.

Best regards
Jiri Tomek

David Ostrovsky

unread,
Mar 5, 2021, 3:04:56 PM3/5/21
to Repo and Gerrit Discussion
jiri...@gmail.com schrieb am Freitag, 5. März 2021 um 12:05:58 UTC+1:
Thanks @Luca for providing the jar file and thanks @David for clarification.

I have now automerger.config file in All-Projects repository on refs/meta/config branch with following content:

[global]
  manifestFile = default.xml
  manifestProject = sandbox/version
[automerger "v3r4:v3r5"]
  mergeAll = true


If I do a change on v3r4 branch, commit that, I push it for a review and finally review is submitted I see no merge coming to v3r5 branch.

I see the code, that is handling exactly that use case in automerger plugin.

src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java

  // Returns contents of manifest file for the given branch pair
  // If manifest does not exist, return empty set.
  private Set<String> getManifestProjects(String fromBranch, String toBranch)
      throws RestApiException, IOException, ConfigInvalidException {
    boolean ignoreSourceManifest =
        getConfig()
            .getBoolean(
                "automerger",
                fromBranch + BRANCH_DELIMITER + toBranch,
                "ignoreSourceManifest",
                false);

    Set<String> toProjects =
        getProjectsInManifest(getManifestProject(), getManifestFile(), toBranch);
    if (ignoreSourceManifest) {
      return toProjects;
    }

    Set<String> fromProjects =
        getProjectsInManifest(getManifestProject(), getManifestFile(), fromBranch);
    fromProjects.retainAll(toProjects);
    return fromProjects;
  }

Where getProjectsInManifest() is defined as:

 private Set<String> getProjectsInManifest(
      String manifestProject, String manifestFile, String branch)
      throws RestApiException, IOException {
    try (BinaryResult manifestConfig =
        gApi.projects().name(manifestProject).branch(branch).file(manifestFile)) {
      ManifestReader manifestReader = new ManifestReader(branch, manifestConfig.asString());
      return manifestReader.getProjects();
    } catch (ResourceNotFoundException e) {
      log.debug("Manifest for {} not found", branch);
      return new HashSet<>();
    }
  }

As you can see ManifestReader is supposed to return the projects:

ManifestReader manifestReader = new ManifestReader(branch, manifestConfig.asString());
      return manifestReader.getProjects();

And looking at ManifestReader implementation:

public Set<String> getProjects() {
    Set<String> projectSet = new HashSet<>();

    try {
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      Document document = documentBuilder.parse(new InputSource(new StringReader(manifestString)));

      Element defaultElement = (Element) document.getElementsByTagName("default").item(0);
      String defaultRevision = defaultElement.getAttribute("revision");

      NodeList projectNodes = document.getElementsByTagName("project");
      for (int i = 0; i < projectNodes.getLength(); i++) {
        Node projectNode = projectNodes.item(i);
        if (projectNode.getNodeType() == Node.ELEMENT_NODE) {
          Element projectElement = (Element) projectNode;
          String name = projectElement.getAttribute("name");

          String revision = projectElement.getAttribute("revision");
          if ("".equals(revision)) {
            revision = defaultRevision;
          }

          // Only add to list of projects in scope if revision is same as
          // manifest branch
          if (revision.equals(branch)) {
            projectSet.add(name);
          }

^^^ It has this revision/from-branch comparison. 

However, in your example they differ:

[automerger "v3r4:v3r5"]
  mergeAll = true


FromBranch: "v3r4"

In the project reference:

<project path="version"
                name="sandbox/version.git"
                remote="gitserver" />


you haven't defined the revision attribute, so the default revision is used:

<default revision="refs/heads/v3r4"
                remote="gitserver"
                sync-j="4" />


but: "v3r4" != "refs/heads/v3r4"

and that's why the project "sandbox/version" is not added.

Disclaimer: I know nothing about this plugin, just reading the code,
and looking at the unit tests and example configurations...
Reply all
Reply to author
Forward
0 new messages