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:6123

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 --require-owner
! stdout .
cd ..
cmp stderr stderr.txt
cmp testrepo/bitbucket.got bitbucket.expected

-- stderr.txt --
Bug: missing owner (rule/owner)
  ---> rules.yml:4-5 -> `No Owner`
5 |     expr: up > 0
              ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Bug: invalid owner (rule/owner)
  ---> rules.yml:7-8 -> `Invalid`
8 |     expr: up == 0
              ^^^ This rule is set as owned by `bob` but `bob` doesn't match any of the allowed owner values.

level=ERROR msg="Execution completed with error(s)" err="problems found"
-- src/v1.yml --
groups:
- name: foo
  rules:
  - alert: Foo
    expr: up > 0
  - alert: Foo
    expr: up == 0
  - alert: Foo
    expr: up > 0

-- src/v2.yml --
groups:
- name: foo
  rules:
  - alert: No Owner
    expr: up > 0
  # pint rule/owner bob
  - alert: Invalid
    expr: up == 0
  # pint rule/owner alice
  - alert: Owner Alice
    expr: up > 0

-- src/.pint.hcl --
owners {
  allowed = ["alice", "max", "not-bob"]
}
ci {
  baseBranch = "main"
}
parser {
  include    = [".+.yml"]
}
repository {
  bitbucket {
    uri        = "http://127.0.0.1:6123"
    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: FAIL
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: 6
    title: Number of rules parsed
    type: NUMBER
  - value: 6
    title: Number of rules checked
    type: NUMBER
  - value: 2
    title: Number of problems found
    type: NUMBER
  - value: 24
    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: "rule/owner: missing owner"
    severity: MEDIUM
    type: BUG
    link: https://cloudflare.github.io/pint/checks/rule/owner.html
    line: 4
  - path: rules.yml
    message: "rule/owner: invalid owner"
    severity: MEDIUM
    type: BUG
    link: https://cloudflare.github.io/pint/checks/rule/owner.html
    line: 7
--- END ---

