bot: "webpack-bot"
rules:

# Add ci-ok, ci-not-ok labels depending on travis status
# comment to point the user to the results
# comment in case of success
- filters:
    open: true
    pull_request:
      mergeable: true
    status_1:
      context: "continuous-integration/travis-ci/pr"
    ensure_1:
      value: "{{status_1.state}}"
      equals: "success"
  actions:
    label:
      add: "PR: CI-ok"
      remove: "PR: CI-not-ok"
    comment:
      identifier: "ci-result"
      message: |-
        Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.
- filters:
    open: true
    pull_request:
      mergeable: true
    status_1:
      context: "continuous-integration/travis-ci/pr"
    any:
      ensure_1:
        value: "{{status_1.state}}"
        equals: "failure"
  actions:
    label:
      add: "PR: CI-not-ok"
      remove: "PR: CI-ok"



# add conflict label to pull requests with conflict
# on conflict all result labels are removed
- filters:
    open: true
    pull_request:
      mergeable: false
  actions:
    label:
      add: "PR: conflict"
      remove:
        - "PR: tests-needed"
        - "PR: CI-ok"
        - "PR: CI-not-ok"
- filters:
    open: true
    pull_request:
      mergeable: true
  actions:
    label:
      remove: "PR: conflict"



# add unreviewed, reviewed, review-outdated labels
# comment to ping reviewer
# comment on new PR
- filters:
    open: true
    in_order:
      commit: true
      review:
        state: APPROVED|CHANGES_REQUESTED
    ensure:
      value: "{{review.state}}"
      equals: APPROVED
  actions:
    label:
      add: "PR: reviewed-approved"
      remove:
      - "PR: review-outdated"
      - "PR: unreviewed"
      - "PR: reviewed"
- filters:
    open: true
    in_order:
      commit: true
      review:
        state: APPROVED|CHANGES_REQUESTED
    ensure:
      value: "{{review.state}}"
      equals: CHANGES_REQUESTED
  actions:
    label:
      add: "PR: reviewed-changes-requested"
      remove:
      - "PR: review-outdated"
      - "PR: unreviewed"
      - "PR: reviewed"
- filters:
    open: true
    in_order:
      review:
        state: APPROVED|CHANGES_REQUESTED
      commit: true
    not:
      label: "review-outdated"
    ensure:
      value: "{{commit.author.login}}"
      notEquals: "{{review.user.login}}"
  actions:
    label:
      add: "PR: review-outdated"
      remove:
      - "PR: reviewed-approved"
      - "PR: reviewed-changes-requested"
      - "PR: unreviewed"
      - "PR: reviewed"
    comment:
      identifier: "review-outdated"
      message: |-
        @{{commit.author.login}} Thanks for your update.

        I labeled the Pull Request so reviewers will review it again.

        @{{review.user.login}} Please review the new changes.
- filters:
    open: true
    commit: true
    not:
      review:
        state: APPROVED|CHANGES_REQUESTED
  actions:
    label: "PR: unreviewed"



# add non-main label to pull request to other branch
- filters:
    pull_request:
      base_ref: "^(?!main)"
  actions:
    label: "PR: non-main"



# add small label to small pull requests
- filters:
    open: true
    pull_request:
      additions: "<= 10"
      deletions: "<= 10"
      changed_files: "<= 2"
  actions:
    label: "PR: small"



# Move issue task
- filters:
    open: true
    comment: "\\s*@webpack-bot\\s+move\\s+(?:to\\s+)?([a-z0-9_\\-\\.]+/[a-z0-9_\\-\\.]+)\\s*([\\s\\S]*)$"
    not:
      comment_1:
        matching: "moved\\-by\\-bot"
        author: "."
    permission:
      user: "{{comment.actor.login}}"
  actions:
    new_issue:
      target: "{{{comment_match.[1]}}}"
      body: |-
        {{{issue.body}}}

        ---

        This issue was moved from {{owner}}/{{repo}}#{{issue.number}} by @{{comment.actor.login}}. Original issue was by @{{issue.user.login}}.

        {{{comment_match.[2]}}}
    comment:
      identifier: moved-by-bot
      message: |-
        I've moved it to {{comment_match.[1]}}.
    close: true
