<commit_before>---
- hosts: localhost
  connection: local

  vars:
    # As name of folder inside of "cmf/".
    cmf: "drupal"
    without_sources: no
    # Every "download_url" will be prefixed with "https://" and ended by "-{{ version }}.tar.gz".
    cmfs:
      drupal:
        download_url: "www.drupal.org/files/projects/drupal"
        default_version: "7.54"
      wordpress:
        download_url: "wordpress.org/wordpress"
        default_version: "4.7"

  vars_files:
    - ../config.yml

  tasks:
    - include: tasks/project-variable.yml

    - name: Set default version of CMF
      set_fact:
        version: "{{ cmfs[cmf].default_version }}"
      when: "{{ version is undefined }}"

    - name: Determine major version of CMF
      set_fact:
        major: "{{ version.split('.') | first }}"

    - name: Check for CMF configuration
      stat:
        path: "../cmf/{{ cmf }}/{{ major | int }}"
      register: cmf_configs

    - name: CMF is not available
      fail:
        msg: "You are not allowed to install {{ cmf | capitalize }} {{ version }} because it isn't pre-configured."
      when: "{{ not cmf_configs.stat.exists }}"

    - name: Prepare directory for project
      file:
        path: "../{{ project }}/docroot"
        state: directory

    - name: Download CMF
      shell: "curl -s https://{{ cmfs[cmf].download_url }}-{{ version }}.tar.gz | tar --strip-components=1 -xzC ./"
      args:
        warn: no
        chdir: "../{{ project }}/docroot"
      when: "{{ not without_sources }}"

    - name: Prepare CIKit-structured repository
      synchronize:
        src: "{{ item.src }}"
        dest: "../{{ project }}/{{ item.dest | default('') }}"
        archive: no
        recursive: yes
        rsync_opts: ["--exclude=*.retry", "--exclude=.git"]
      with_items:
        - src: "../cmf/all/"
        - src: "../cmf/{{ cmf }}/all/"
        - src: "{{ cmf_configs.stat.path }}/"
        - src: "../cikit"
        - src: "../config.yml"
        - src: "../inventory"

        - src: "../scripts/"
          dest: "provisioning"

    - name: Setting permissions for project tree
      file:
        mode: 0755
        path: "../{{ project }}"
        state: directory
        recurse: yes

    - name: Update config.yml
      lineinfile:
        dest: "../{{ project }}/config.yml"
        line: "cmf: {{ cmf }}\ncore: {{ major }}\nproject: {{ project }}\nsite_url: https://{{ project | regex_replace('[^\\w+\\.\\-\\_]', '') | regex_replace('^[\\.\\-|\\_]+|\\.{2,}', '') }}.dev"
        insertafter: "^---$"

    - name: Update config.yml
      replace:
        dest: "../{{ project }}/config.yml"
        regexp: "APPLICATION_CONFIG: ~"
        replace: "{{ lookup('file', '../' + project + '/APPLICATION_CONFIG.yml') }}"

    - include_vars: "../{{ project }}/REPLACEMENTS.yml"

    - name: Seeking the placeholders
      shell: "find ../{{ project }}/scripts/ -type f -exec sed -i {{ \"''\" if ansible_os_family == 'Darwin' else '' }} 's/<{{ item.key }}>/{{ item.value }}/g' {} \\;"
      environment:
        LC_ALL: C
      with_dict: "{{ replacements }}"

    - name: Clear created repository
      file:
        path: "../{{ project }}/{{ item }}"
        state: absent
      with_items:
        - provisioning/repository.yml
        - docroot/.gitignore
        - docroot/.git
        - APPLICATION_CONFIG.yml
        - REPLACEMENTS.yml<commit_msg>[CIKit][Repository] Simplify regex for parsing site URL<commit_after>---
- hosts: localhost
  connection: local

  vars:
    # As name of folder inside of "cmf/".
    cmf: "drupal"
    without_sources: no
    # Every "download_url" will be prefixed with "https://" and ended by "-{{ version }}.tar.gz".
    cmfs:
      drupal:
        download_url: "www.drupal.org/files/projects/drupal"
        default_version: "7.54"
      wordpress:
        download_url: "wordpress.org/wordpress"
        default_version: "4.7"

  vars_files:
    - ../config.yml

  tasks:
    - include: tasks/project-variable.yml

    - name: Set default version of CMF
      set_fact:
        version: "{{ cmfs[cmf].default_version }}"
      when: "{{ version is undefined }}"

    - name: Determine major version of CMF
      set_fact:
        major: "{{ version.split('.') | first }}"

    - name: Check for CMF configuration
      stat:
        path: "../cmf/{{ cmf }}/{{ major | int }}"
      register: cmf_configs

    - name: CMF is not available
      fail:
        msg: "You are not allowed to install {{ cmf | capitalize }} {{ version }} because it isn't pre-configured."
      when: "{{ not cmf_configs.stat.exists }}"

    - name: Prepare directory for project
      file:
        path: "../{{ project }}/docroot"
        state: directory

    - name: Download CMF
      shell: "curl -s https://{{ cmfs[cmf].download_url }}-{{ version }}.tar.gz | tar --strip-components=1 -xzC ./"
      args:
        warn: no
        chdir: "../{{ project }}/docroot"
      when: "{{ not without_sources }}"

    - name: Prepare CIKit-structured repository
      synchronize:
        src: "{{ item.src }}"
        dest: "../{{ project }}/{{ item.dest | default('') }}"
        archive: no
        recursive: yes
        rsync_opts: ["--exclude=*.retry", "--exclude=.git"]
      with_items:
        - src: "../cmf/all/"
        - src: "../cmf/{{ cmf }}/all/"
        - src: "{{ cmf_configs.stat.path }}/"
        - src: "../cikit"
        - src: "../config.yml"
        - src: "../inventory"

        - src: "../scripts/"
          dest: "provisioning"

    - name: Setting permissions for project tree
      file:
        mode: 0755
        path: "../{{ project }}"
        state: directory
        recurse: yes

    - name: Update config.yml
      lineinfile:
        dest: "../{{ project }}/config.yml"
        line: "cmf: {{ cmf }}\ncore: {{ major }}\nproject: {{ project }}\nsite_url: https://{{ project | regex_replace('[^\\w+\\.\\-\\_]', '') | regex_replace('^[\\.\\-\\_]+|\\.{2,}', '') }}.dev"
        insertafter: "^---$"

    - name: Update config.yml
      replace:
        dest: "../{{ project }}/config.yml"
        regexp: "APPLICATION_CONFIG: ~"
        replace: "{{ lookup('file', '../' + project + '/APPLICATION_CONFIG.yml') }}"

    - include_vars: "../{{ project }}/REPLACEMENTS.yml"

    - name: Seeking the placeholders
      shell: "find ../{{ project }}/scripts/ -type f -exec sed -i {{ \"''\" if ansible_os_family == 'Darwin' else '' }} 's/<{{ item.key }}>/{{ item.value }}/g' {} \\;"
      environment:
        LC_ALL: C
      with_dict: "{{ replacements }}"

    - name: Clear created repository
      file:
        path: "../{{ project }}/{{ item }}"
        state: absent
      with_items:
        - provisioning/repository.yml
        - docroot/.gitignore
        - docroot/.git
        - APPLICATION_CONFIG.yml
        - REPLACEMENTS.yml
{'fraction_non_alphanumeric': 0.1814321276907307, 'fraction_numerical': 0.0032215551325230633, 'mean_word_length': 1.9225502781343602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4296011', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2144, 'n_words': 541}