http method gitlab GET /api/v4/user 200 {"id": 555}
http method gitlab GET /api/v4/projects/1234/merge_requests/1/versions 200 [{"id": 2, "head_commit_sha": "head", "base_commit_sha": "base", "start_commit_sha": "start"},{"id": 1, "head_commit_sha": "head", "base_commit_sha": "base", "start_commit_sha": "start"}]
http method gitlab GET /api/v4/projects/1234/merge_requests/1/diffs 200 [{"old_path":"alert.yml","new_path":"alert.yml","diff":""},{"old_path":"record.yml","new_path":"record.yml","diff":""}]
http method gitlab GET /api/v4/projects/1234/merge_requests/1/discussions 200 []
http method gitlab GET /api/v4/projects/1234/merge_requests 200 [{"iid": 1}]
http method gitlab POST /api/v4/projects/1234/merge_requests/1/discussions 200 {}
http start gitlab 127.0.0.1:6218

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

cp ../src/v1/alert.yml .
cp ../src/v1/record.yml .
exec ln -s alert.yml symlink.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/alert.yml .
cp ../src/v2/record.yml .
exec git commit -am 'v2'

env GITLAB_AUTH_TOKEN=secret
exec pint -l error --offline --no-color ci
! stdout .
cmp stderr ../stderr.txt
cmp gitlab.got ../gitlab.expected

-- stderr.txt --
Warning: rule results used by another rule (rule/dependency)
  ---> record.yml:6 (deleted) -> `up:sum`

-- src/v1/alert.yml --
groups:
- name: g1
  rules:
  - alert: Alert
    expr: 'up:sum == 0'
    annotations:
      summary: 'Service is down'
    labels:
      cluster: dev
  - alert: AlertBroken
    expr: 'up:sum == 0'
    annotations:
      summary: 'Service is down'
    labels:
      cluster: dev
-- src/v1/record.yml --
groups:
- name: g1
  rules:
  - record: unused:sum1
    expr: sum(up)
  - record: up:sum
    expr: sum(up)
  - record: unused:sum2
    expr: sum(up)
-- src/v2/alert.yml --
groups:
- name: g1
  rules:
  - alert: AlertBroken
    expr: 'up:sum == 0'
    annotations:
      summary: 'Service is down'
    labels:
      cluster: dev
-- src/v2/record.yml --
groups:
- name: g1
  rules:
  - record: unused:sum1
    expr: sum(up)
  - record: unused:sum2
    expr: sum(up)
-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
repository {
  gitlab {
    uri        = "http://127.0.0.1:6218"
    timeout    = "30s"
    project    = "1234"
  }
}
parser {
  include    = [".+.yml"]
}
prometheus "prom" {
  uri      = "http://127.0.0.1:7162"
  timeout  = "5s"
  required = true
}

-- gitlab.expected --
GET /api/v4/user
  Accept: application/json
  Accept-Encoding: gzip
  Private-Token: secret

GET /api/v4/projects/1234/merge_requests
  Accept: application/json
  Accept-Encoding: gzip
  Private-Token: secret

GET /api/v4/projects/1234/merge_requests/1/versions
  Accept: application/json
  Accept-Encoding: gzip
  Private-Token: secret

GET /api/v4/projects/1234/merge_requests/1/diffs
  Accept: application/json
  Accept-Encoding: gzip
  Private-Token: secret

GET /api/v4/projects/1234/merge_requests/1/discussions
  Accept: application/json
  Accept-Encoding: gzip
  Private-Token: secret

POST /api/v4/projects/1234/merge_requests/1/discussions
  Accept: application/json
  Accept-Encoding: gzip
  Content-Type: application/json
  Private-Token: secret
--- BODY ---
body: |
  :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **rule/dependency** check.

  ------

  rule results used by another rule

  <details>
  <summary>More information</summary>
  If you remove the recording rule generating `up:sum`, and there is no other source of this metric, then any other rule depending on it will break.
  List of found rules that are using `up:sum`:

  - `AlertBroken` at `alert.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/rule/dependency.html).
position:
  base_sha: base
  head_sha: head
  start_sha: start
  new_path: record.yml
  old_path: record.yml
  position_type: text
  old_line: 6
--- END ---

