http response bitbucket /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint 200 OK
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests 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 --
DELETE /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

PUT /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
reporter: Prometheus rule linter
title: pint unknown
result: PASS
details: |-
  pint is a Prometheus rule linter/validator.
  It will inspect all Prometheus recording and alerting rules for problems that could prevent these from working correctly.
  Checks can be either offline (static checks using only rule definition) or online (validate rule against live Prometheus server).
link: https://cloudflare.github.io/pint/
data:
  - value: 4
    title: Number of rules parsed
    type: NUMBER
  - value: 4
    title: Number of rules checked
    type: NUMBER
  - value: 6
    title: Number of problems found
    type: NUMBER
  - value: 16
    title: Number of offline checks
    type: NUMBER
  - value: 0
    title: Number of online checks
    type: NUMBER
  - value: 0
    title: Checks duration
    type: DURATION
--- END ---

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

DELETE /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

POST /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
annotations:
  - path: rules.yml
    message: "Problem reported on unmodified line 2, annotation moved here: alerts/comparison: always firing alert"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/alerts/comparison.html
    line: 1
  - path: rules.yml
    message: "Problem reported on unmodified line 2, annotation moved here: promql/regexp: redundant regexp"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/promql/regexp.html
    line: 1
  - path: rules.yml
    message: "alerts/for: redundant field with default value"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/alerts/for.html
    line: 3
  - path: rules.yml
    message: "Problem reported on unmodified line 5, annotation moved here: alerts/comparison: always firing alert"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/alerts/comparison.html
    line: 4
  - path: rules.yml
    message: "Problem reported on unmodified line 5, annotation moved here: promql/regexp: redundant regexp"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/promql/regexp.html
    line: 4
  - path: rules.yml
    message: "Problem reported on unmodified line 6, annotation moved here: alerts/for: redundant field with default value"
    severity: LOW
    type: CODE_SMELL
    link: https://cloudflare.github.io/pint/checks/alerts/for.html
    line: 4
--- END ---

