http response bitbucket /plugins/servlet/applinks/whoami 200 pint
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 {"size":1,"isLastPage":true,"values":[{"id":123,"open":true,"fromRef":{"id":"refs/heads/modify","latestCommit":"fake-commit-id"},"toRef":{"id":"refs/heads/main","latestCommit":"fake-commit-id"}}]}
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/123/changes 200 {"values":[{"path":{"toString":"rules.yml"}}],"size":1,"isLastPage":true}
http response bitbucket /rest/api/latest/projects/prometheus/repos/rules/commits/fake-commit-id/diff/rules.yml 200 {"diffs":[{"hunks":[{"segments":[{"type":"ADDED", "lines":[{"source":5,"destination":5}]}]}]}]}
http response bitbucket /rest/api/latest/projects/prometheus/repos/rules/pull-requests/123/activities 200 {"size":1,"isLastPage":true,"values":[{"action":"COMMENTED","commentAction":"ADDED","commentAnchor":{"diffType":"EFFECTIVE","lineType":"ADDED","path":"rules.yml","line":5},"comment":{"id":1,"state":"OPEN","severity":"NORMAL","author":{"name":"pint"},"comments":[{"id":2}]}}]}
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/123/comments 200 {}
http start bitbucket 127.0.0.1:7164

env BITBUCKET_AUTH_TOKEN="12345"

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

cp ../src/v0.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 modify
cp ../src/v1.yml rules.yml
exec git commit -am 'v1'
! exec pint --no-color ci
stderr 'msg="Problems found" Fatal=1'
stderr 'msg="Found open pull request, reporting problems using comments" id=123 srcBranch=modify srcCommit=fake-commit-id dstBranch=main dstCommit=fake-commit-id'
stderr 'msg="Got existing pull request comments from BitBucket" count=1'
stderr 'msg="Generated comments to add to BitBucket" count=1'
stderr 'msg="Added pull request comments to BitBucket" count=1'
cmp bitbucket.got ../bitbucket.expected

cp ../src/v2.yml rules.yml
exec git commit -am 'v2'
exec pint --no-color ci
! stdout .
! stderr 'msg="Problems found"'
stderr 'msg="Found open pull request, reporting problems using comments" id=123 srcBranch=modify srcCommit=fake-commit-id dstBranch=main dstCommit=fake-commit-id'
stderr 'msg="Getting pull request changes from BitBucket"'
stderr 'msg="Got existing pull request comments from BitBucket" count=1'
stderr 'msg="Generated comments to add to BitBucket" count=0'
stderr 'msg="Added pull request comments to BitBucket" count=0'

-- src/v0.yml --
groups:
- name: g1
  rules:
  - record: up:count
    expr: count(up == 1)
-- src/v1.yml --
groups:
- name: g1
  rules:
  - record: up:count
    expr: count(up == 1) bie(job)
-- src/v2.yml --
groups:
- name: g1
  rules:
  - record: up:count
    expr: count(up == 1) by(job)
-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
repository {
  bitbucket {
    uri        = "http://127.0.0.1:7164"
    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: 1
    title: Number of rules parsed
    type: NUMBER
  - value: 1
    title: Number of rules checked
    type: NUMBER
  - value: 1
    title: Number of problems found
    type: NUMBER
  - value: 7
    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

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

GET /rest/api/latest/projects/prometheus/repos/rules/commits/fake-commit-id/diff/rules.yml
  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/123/activities
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

PUT /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/123/comments
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
severity: BLOCKER
version: 0
--- END ---

PUT /rest/api/1.0/projects/prometheus/repos/rules/pull-requests/123/comments
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json
--- BODY ---
state: RESOLVED
version: 0
--- END ---

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

  ------

  PromQL syntax error

  ```yaml
  5 |     expr: count(up == 1) bie(job)
                               ^^^ 
  ```

  unexpected identifier "bie"

  [Click here](https://prometheus.io/docs/prometheus/latest/querying/basics/) for PromQL documentation.

  ------

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

