- name: Install required dependencies (apt)
  apt:
    state: present
    name:
     - sudo
     - git
     - make
     - python3-aiohttp
     - python3-aiodns
     - python3-configobj
     - python3-debian
     - python3-protobuf
     - python3-iso8601
     - protobuf-compiler
     - python3-gpg
     - gnupg2
     - python3-pip
     - python3-yaml
     - python3-tqdm
     - python3-launchpadlib
     - python3-keyrings.alt
     - python3-distro-info
     - python3-patiencediff
     - java-propose-classpath
     - cython3
     - python3-all-dev
     - python3-asyncpg
     - python3-marshmallow
     - rustc
     - cargo
- name: Install required dependencies (pip)
  pip:
    name:
     - mypy-protobuf
     - aiohttp-openmetrics
     - git+https://github.com/maximdanilchenko/aiohttp-apispec
     - git+https://salsa.debian.org/python-debian-team/python-debian
     - aiozipkin
     - setuptools-rust
     - fastbencode
- name: Create janitor user
  user:
    name: "{{ janitor_user }}"
    generate_ssh_key: yes
    create_home: yes
    system: yes
    home: "{{ janitor_home }}"
- name: Update janitor git repository
  git:
    repo: https://github.com/jelmer/janitor
    dest: "{{ janitor_code_path }}"
    force: yes
  become: yes
  become_user: "{{ janitor_static_owner }}"
- name: Build protobuf
  make:
    chdir: "{{ janitor_code_path }}"
  become: yes
  become_user: "{{ janitor_static_owner }}"
- name: Build C extensions for Breezy
  make:
    chdir: "{{ janitor_code_path }}/breezy"
    params:
      # libgit2 has an unstable API, and that leads to segfaults.
      CARGO_NET_GIT_FETCH_WITH_CLI: "true"
  become: yes
  become_user: "{{ janitor_static_owner }}"
- name: Build C extensions for Dulwich
  make:
    chdir: "{{ janitor_code_path }}/dulwich"
  become: yes
  become_user: "{{ janitor_static_owner }}"
- name: janitor.conf configuration
  template:
    src: janitor.conf
    dest: "{{ janitor_conf_path }}"
    owner: "{{ janitor_static_owner }}"
- name: janitor proposal templates
  copy:
    src: "{{ janitor_local_proposal_template_path }}"
    dest: "{{ janitor_home }}/proposal-templates"
- name: env file
  template:
    src: env
    dest: "{{ janitor_home }}/env"
    owner: "{{ janitor_static_owner }}"
- name: postgresql credentials
  template:
    src: pgpass
    dest: "{{ janitor_home }}/.pgpass"
    mode: '0600'
    owner: "{{ janitor_user }}"
- name: configuration directory for Breezy
  file:
    state: directory
    path: "{{ janitor_home }}/{{ item }}"
    owner: "{{ janitor_user }}"
  with_items:
    - .config
    - .config/breezy
    - .config/breezy/plugins
- name: Breezy Debian installation
  file:
    src: "{{ janitor_code_path }}/breezy-debian"
    dest: "{{ janitor_home }}/.config/breezy/plugins/debian"
    owner: "{{ janitor_user }}"
    state: link
- name: Breezy Identity
  command: "{{ janitor_code_path }}/breezy/brz whoami '{{ janitor_fullname }} <{{ janitor_email }}>'"
  become: yes
  become_user: "{{ janitor_user }}"
  environment:
    PYTHONPATH: "{{ janitor_code_path }}/breezy"
