http response bitbucket /plugins/servlet/applinks/whoami 200 pint
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests 200 {"size":1,"isLastPage":true,"values":[{"id":1,"open":true,"fromRef":{"id":"refs/heads/v2","latestCommit":"fake-commit-id"},"toRef":{"id":"refs/heads/main","latestCommit":"fake-commit-id"}}]}
http response bitbucket /rest/api/latest/projects/prometheus/repos/rules/pull-requests/1/activities 200 {"size":0,"isLastPage":true,"values":[]}
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/1/comments 200 {}
http start bitbucket 127.0.0.1:6069

mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env GIT_AUTHOR_EMAIL=pint@example.com
env GIT_COMMITTER_NAME=pint
env GIT_COMMITTER_EMAIL=pint@example.com
exec git add .
exec git commit -am 'import rules and config'

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'v2'

env BITBUCKET_AUTH_TOKEN="12345"
exec pint -l error --no-color ci
! stdout .
cmp stderr ../stderr.txt
cmp bitbucket.got ../bitbucket.expected

-- stderr.txt --
Warning: always firing alert (alerts/comparison)
  ---> rules.yml:2 -> `rule1b` [+1 duplicates]
2 |   expr: sum(foo{job=~"xxx"}) by(job)
                ^^^^^^^^^^^^^^^
                This query doesn't have any condition and so this alert will always fire if it matches
                anything.

Warning: redundant regexp (promql/regexp)
  ---> rules.yml:2 -> `rule1b` [+1 duplicates]
2 |   expr: sum(foo{job=~"xxx"}) by(job)
                    ^^^^^^^^^^
                    Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead.

Information: redundant field with default value (alerts/for)
  ---> rules.yml:3 -> `rule1b` [+1 duplicates]
3 |   for: 0s
           ^^ `0s` is the default value of `for`, this line is unnecessary.

-- src/v1.yml --
- alert: rule1a
  expr: sum(foo{job=~"xxx"}) by(job)
- alert: rule2a
  expr: sum(foo{job=~"xxx"}) by(job)
  for: 0s

-- src/v2.yml --
- alert: rule1b
  expr: sum(foo{job=~"xxx"}) by(job)
  for: 0s
- alert: rule2b
  expr: sum(foo{job=~"xxx"}) by(job)
  for: 0s

-- src/.pint.hcl --
parser {
  relaxed = [".*"]
}
ci {
  baseBranch = "main"
}
repository {
  bitbucket {
    uri        = "http://127.0.0.1:6069"
    timeout    = "10s"
    project    = "prometheus"
    repository = "rules"
  }
}

-- bitbucket.expected --
GET /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

GET /plugins/servlet/applinks/whoami
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

GET /rest/api/latest/projects/prometheus/repos/rules/pull-requests/1/activities
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

POST /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/1/comments
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
text: |
  :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **alerts/comparison** check.

  <details>
  <summary>always firing alert</summary>

  ```yaml
  2 |   expr: sum(foo{job=~"xxx"}) by(job)
                  ^^^^^^^^^^^^^^^
  ```

  This query doesn't have any condition and so this alert will always fire if it matches anything.

  Prometheus alerting rules will trigger an alert for each query that returns *any* result.
  Unless you do want an alert to always fire you should write your query in a way that returns results only when some condition is met.
  In most cases this can be achieved by having some condition in the query expression.
  For example `up == 0` or `rate(error_total[2m]) > 0`.
  Be careful as some PromQL operations will cause the query to always return the results, for example using the [bool modifier](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators).

  </details>

  ------

  The same issue was reported 1 more time(s), duplicates where suppressed.

  <details>
  <summary>Show affected rules</summary>

  - `rule2b` at `rules.yml:5`

  </details>

  ------

  :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
severity: NORMAL
anchor:
  path: rules.yml
  lineType: ADDED
  fileType: TO
  diffType: EFFECTIVE
  line: 1
--- END ---

POST /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/1/comments
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
text: |
  :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **promql/regexp** check.

  <details>
  <summary>redundant regexp</summary>

  ```yaml
  2 |   expr: sum(foo{job=~"xxx"}) by(job)
                      ^^^^^^^^^^
  ```

  Unnecessary regexp match on static string `job=~"xxx"`, use `job="xxx"` instead.

  See [Prometheus documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/#time-series-selectors) for details on how vector selectors work.

  </details>

  ------

  The same issue was reported 1 more time(s), duplicates where suppressed.

  <details>
  <summary>Show affected rules</summary>

  - `rule2b` at `rules.yml:5`

  </details>

  ------

  :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/promql/regexp.html).
severity: NORMAL
anchor:
  path: rules.yml
  lineType: ADDED
  fileType: TO
  diffType: EFFECTIVE
  line: 1
--- END ---

POST /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/1/comments
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
text: |
  :information_source: **Information** reported by [pint](https://cloudflare.github.io/pint/) **alerts/for** check.

  <details>
  <summary>redundant field with default value</summary>

  ```yaml
  3 |   for: 0s
             ^^
  ```

  `0s` is the default value of `for`, this line is unnecessary.

  </details>

  ------

  The same issue was reported 1 more time(s), duplicates where suppressed.

  <details>
  <summary>Show affected rules</summary>

  - `rule2b` at `rules.yml:6`

  </details>

  ------

  :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/for.html).
severity: NORMAL
anchor:
  path: rules.yml
  lineType: ADDED
  fileType: TO
  diffType: EFFECTIVE
  line: 3
--- END ---

