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":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" id=123 srcBranch=modify dstBranch=main'
stderr 'msg="Listing existing comments" reporter=BitBucket'
stderr 'msg="Creating a new comment" reporter=BitBucket'
cmp bitbucket.got ../bitbucket1.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" id=123 srcBranch=modify dstBranch=main'
stderr 'msg="Listing existing comments" reporter=BitBucket'
stderr 'msg="Trying to delete a stale existing comment" path=rules.yml line=5'
cmp bitbucket.got ../bitbucket2.expected

-- 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"
  }
}

-- bitbucket1.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/123/activities
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

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.

  <details>
  <summary>PromQL syntax error</summary>

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

  unexpected identifier "bie"

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

  </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/syntax.html).
severity: NORMAL
anchor:
  path: rules.yml
  lineType: ADDED
  fileType: TO
  diffType: EFFECTIVE
  line: 5
--- 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 ---
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 ---

-- bitbucket2.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/123/activities
  Accept-Encoding: gzip
  Authorization: Bearer "12345"
  Content-Type: application/json

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.

  <details>
  <summary>PromQL syntax error</summary>

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

  unexpected identifier "bie"

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

  </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/syntax.html).
severity: NORMAL
anchor:
  path: rules.yml
  lineType: ADDED
  fileType: TO
  diffType: EFFECTIVE
  line: 5
--- 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 ---
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 ---

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/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 ---

