<commit_before>{% from "gerrit_ci/gerrit/settings.sls" import gerrit with context %}
include:
  - gerrit_ci.java

# Software
required-software:
  pkg.installed:
    - pkgs:
      - mysql-server
      - python-mysqldb
      - wget
      - apache2
    - require:
      - sls: gerrit_ci.java

# gerrit2 user
gerrit2:
  group:
    - present

  user.present:
    - home: /home/gerrit2
    - shell: /bin/bash
    - groups:
      - gerrit2

# Mysql service
mysql:
  service.running:
    - name: mysql
    - enable: True
    - require:
      - pkg: required-software

# database
gerrit-database:
  mysql_database.present:
    - name: {{ gerrit.dbname }}
    - require:
      - service: mysql

  mysql_user.present:
    - name: {{ gerrit.dbuser }}
    - host: {{ gerrit.dbhost }}
    - password: {{ gerrit.dbpassword }}
    - require:
      - service: mysql

  mysql_grants.present:
    - grant: all privileges
    - database: {{ gerrit.dbname }}.*
    - user: {{ gerrit.dbuser }}
    - require:
      - service: mysql

# Gerrit war
/home/gerrit2/gerrit-{{ gerrit.version }}.war:
  cmd.run:
    - name: wget {{ gerrit.war_url }}
    - cwd: /home/gerrit2
    - user: gerrit2
    - onlyif: test ! -s gerrit-{{ gerrit.version }}.war
    - require:
      - user: gerrit2

/var/log/gerrit:
  file.directory:
    - user: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2
      - group: gerrit2

/home/gerrit2/review_site:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2

/home/gerrit2/.ssh:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - mode: 700
    - require:
      - user: gerrit2

/home/gerrit2/.ssh/id_rsa:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/keys/id_rsa
    - owner: gerrit2
    - group: gerrit2
    - mode: 0600
    - require:
      - file: /home/gerrit2/.ssh

/home/gerrit2/.ssh/id_rsa.pub:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/keys/id_rsa.pub
    - owner: gerrit2
    - group: gerrit2
    - mode: 644
    - require:
      - file: /home/gerrit2/.ssh

/home/gerrit2/review_site/etc:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2
      - file: /home/gerrit2/review_site

/home/gerrit2/review_site/etc/gerrit.config:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/gerrit.config
    - mode: 0644
    - owner: gerrit2
    - group: gerrit2
    - replace: False
    - template: jinja
    - require:
      - file: /home/gerrit2/review_site/etc

# Init gerrit
gerrit-init:
  cmd.run:
    - name: java -jar /home/gerrit2/gerrit-{{ gerrit.version }}.war init --batch -d /home/gerrit2/review_site --no-auto-start {% for plugin in gerrit.plugins %} --install-plugin {{ plugin }} {% endfor %}
    - user: gerrit2
    - watch:
      - cmd: /home/gerrit2/gerrit-{{ gerrit.version }}.war

# Rebuild indexes
gerrit-index:
  cmd.run:
    - name: java -jar /home/gerrit2/review_site/bin/gerrit.war reindex -d /home/gerrit2/review_site
    - user: gerrit2
    - require:
      - cmd: gerrit-init
    - onlyif: test ! -e /home/gerrit2/review_site/index/gerrit_index.config

/home/gerrit2/review_site/bin/gerrit.sh:
  file.uncomment:
    - char: '#'
    - regex: '((chkconfig: 3 99 99)|(description: Gerrit Code Review)|(processname: gerrit))'
    - require:
      - cmd: gerrit-init
      - cmd: gerrit-index

/etc/init.d/gerrit:
  file.symlink:
    - target: /home/gerrit2/review_site/bin/gerrit.sh
    - require:
      - file: /home/gerrit2/review_site/bin/gerrit.sh

/etc/rc3.d/s90gerrit:
  file.symlink:<commit_msg>Removed file.uncomment due to bug<commit_after>{% from "gerrit_ci/gerrit/settings.sls" import gerrit with context %}
include:
  - gerrit_ci.java

# Software
required-software:
  pkg.installed:
    - pkgs:
      - mysql-server
      - python-mysqldb
      - wget
      - apache2
    - require:
      - sls: gerrit_ci.java

# gerrit2 user
gerrit2:
  group:
    - present

  user.present:
    - home: /home/gerrit2
    - shell: /bin/bash
    - groups:
      - gerrit2

# Mysql service
mysql:
  service.running:
    - name: mysql
    - enable: True
    - require:
      - pkg: required-software

# database
gerrit-database:
  mysql_database.present:
    - name: {{ gerrit.dbname }}
    - require:
      - service: mysql

  mysql_user.present:
    - name: {{ gerrit.dbuser }}
    - host: {{ gerrit.dbhost }}
    - password: {{ gerrit.dbpassword }}
    - require:
      - service: mysql

  mysql_grants.present:
    - grant: all privileges
    - database: {{ gerrit.dbname }}.*
    - user: {{ gerrit.dbuser }}
    - require:
      - service: mysql

# Gerrit war
/home/gerrit2/gerrit-{{ gerrit.version }}.war:
  cmd.run:
    - name: wget {{ gerrit.war_url }}
    - cwd: /home/gerrit2
    - user: gerrit2
    - onlyif: test ! -s gerrit-{{ gerrit.version }}.war
    - require:
      - user: gerrit2

/var/log/gerrit:
  file.directory:
    - user: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2
      - group: gerrit2

/home/gerrit2/review_site:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2

/home/gerrit2/.ssh:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - mode: 700
    - require:
      - user: gerrit2

/home/gerrit2/.ssh/id_rsa:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/keys/id_rsa
    - owner: gerrit2
    - group: gerrit2
    - mode: 0600
    - require:
      - file: /home/gerrit2/.ssh

/home/gerrit2/.ssh/id_rsa.pub:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/keys/id_rsa.pub
    - owner: gerrit2
    - group: gerrit2
    - mode: 644
    - require:
      - file: /home/gerrit2/.ssh

/home/gerrit2/review_site/etc:
  file.directory:
    - owner: gerrit2
    - group: gerrit2
    - require:
      - user: gerrit2
      - file: /home/gerrit2/review_site

/home/gerrit2/review_site/etc/gerrit.config:
  file.managed:
    - source: salt://gerrit_ci/gerrit/files/gerrit.config
    - mode: 0644
    - owner: gerrit2
    - group: gerrit2
    - replace: False
    - template: jinja
    - require:
      - file: /home/gerrit2/review_site/etc

# Init gerrit
gerrit-init:
  cmd.run:
    - name: java -jar /home/gerrit2/gerrit-{{ gerrit.version }}.war init --batch -d /home/gerrit2/review_site --no-auto-start {% for plugin in gerrit.plugins %} --install-plugin {{ plugin }} {% endfor %}
    - user: gerrit2
    - watch:
      - cmd: /home/gerrit2/gerrit-{{ gerrit.version }}.war

# Rebuild indexes
gerrit-index:
  cmd.run:
    - name: java -jar /home/gerrit2/review_site/bin/gerrit.war reindex -d /home/gerrit2/review_site
    - user: gerrit2
    - require:
      - cmd: gerrit-init
    - onlyif: test ! -e /home/gerrit2/review_site/index/gerrit_index.config

#/home/gerrit2/review_site/bin/gerrit.sh:
#  file.uncomment:
#    - char: '#'
#    - regex: '((chkconfig: 3 99 99)|(description: Gerrit Code Review)|(processname: gerrit))'
#    - require:
#      - cmd: gerrit-init
#      - cmd: gerrit-index

uncomment-chkconfig:
  file.replace:
    - name: /home/gerrit2/review_site/bin/gerrit.sh
    - repl: |
        chkconfig: 3 99 99
    - pattern: |
        # chkconfig: 3 99 99
    - show_changes: True
    - require:
      - cmd: gerrit-init
      - cmd: gerrit-index


uncomment-description:
  file.replace:
    - name: /home/gerrit2/review_site/bin/gerrit.sh
    - repl: |
        description: Gerrit Code Review
    - pattern: |
        # description: Gerrit Code Review
    - show_changes: True
    - require:
      - cmd: gerrit-init
      - cmd: gerrit-index


uncomment-processname:
  file.replace:
    - name: /home/gerrit2/review_site/bin/gerrit.sh
    - repl: |
        processname: gerrit
    - pattern: |
        # processname: gerrit
    - show_changes: True
    - require:
      - cmd: gerrit-init
      - cmd: gerrit-index

      

/etc/init.d/gerrit:
  file.symlink:
    - target: /home/gerrit2/review_site/bin/gerrit.sh
    - require:
      - file: /home/gerrit2/review_site/bin/gerrit.sh

/etc/rc3.d/s90gerrit:
  file.symlink:
{'fraction_non_alphanumeric': 0.13809819763828465, 'fraction_numerical': 0.019266625233064015, 'mean_word_length': 2.1125725338491295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7437613', 'n_tokens_mistral': 3322, 'n_tokens_neox': 3019, 'n_words': 570}