# This file is a configuration file of github bot called mergeables.
# See: https://github.com/apps/mergeable
#
# The bot help us to enforce standards and conventions on our repository.
# See: https://mergeable.readthedocs.io/en/latest/usage.html
#
#
# Please read documentation of mergeable at
# https://mergeable.readthedocs.io/en/latest/configuration.html#basics

version: 2
mergeable:
  # Let's welcome contributors.
  - when: pull_request.opened
    name: "Hola!"
    validate: []
    filter:
      - do: author
        must_exclude:
          regex: 'dependabot'
      # Ignore pull requests with the 'automated' label.
      - do: payload
        pull_request:
          labels:
            must_exclude:
              regex: 'automated'
              key: name
    pass:
      - do: comment
        payload:
          body: >
            Thanks for contributing towards Open Social! A maintainer from the @goalgorilla/maintainers group might not
            review all changes from all teams/contributors. Please don't be discouraged if it takes a while. In the meantime,
            we have some automated checks running and it might be that you will see our comments with some tips or requests
            to speed up the review process. :blush:
        leave_old_comment: true

  # Check for a valid title.
  # See: https://mergeable.readthedocs.io/en/latest/validators/title.html
  - when: pull_request.opened, pull_request.reopened, pull_request.edited
    name: "Valid issue title"
    validate:
      # The pull request should have the title in following formats
      - do: title
        # It must start with following keywords.
        begins_with:
          match: ['Issue #', 'Internal:', 'Updates:', 'Hotfix:']
          message: 'A pull request title should start with either Issue #, Internal:, Updates: or Hotfix:'
    fail:
      - do: labels
        add: 'blocked: mergeable'
      - do: checks
        status: 'failure'
    pass:
      - do: labels
        delete: 'blocked: mergeable'
      - do: checks
        status: 'success'

  # Let's make sure that the proper labels are added.
  # See: https://mergeable.readthedocs.io/en/latest/validators/label.html
  - when: pull_request.opened, pull_request.reopened, pull_request.labeled, pull_request.unlabeled
    name: "Valid labels"
    validate:
      # The pull request must have the following labels.
      - do: label
        and:
          - must_include:
              regex: 'team'
              message: 'Please, add "team" label'
          - must_include:
              regex: 'prio'
              message: 'Please, add "prio" label'
          - must_include:
              regex: 'type'
              message: 'Please, add "type" label'
    fail:
      - do: labels
        add: 'blocked: mergeable'
      - do: checks
        status: 'failure'
    pass:
      - do: labels
        delete: 'blocked: mergeable'
      - do: checks
        status: 'success'
