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

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

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 config'

exec git checkout -b v2
cp ../src/rules.yml rules.yml
exec git add .
exec git commit -am 'add new rules file'

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

-- src/rules.yml --
groups:
- name: foo
  rules:
  - alert: rule1
    expr: sum(foo) by(job)

-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
repository {
  gitlab {
    uri        = "http://127.0.0.1:6245"
    timeout    = "30s"
    project    = "1234"
  }
}

-- 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/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/) **alerts/comparison** check.

  <details>
  <summary>always firing alert</summary>

  ```yaml
  5 |     expr: sum(foo) by(job)
                    ^^^
  ```

  This query doesn't have any condition and so this alert will always fire if it matches anything.

  Prometheus alerting rules will trigger an alert for each query that returns *any* result.
  Unless you do want an alert to always fire you should write your query in a way that returns results only when some condition is met.
  In most cases this can be achieved by having some condition in the query expression.
  For example `up == 0` or `rate(error_total[2m]) > 0`.
  Be careful as some PromQL operations will cause the query to always return the results, for example using the [bool modifier](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators).

  </details>

  ------

  :information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/alerts/comparison.html).
position:
  base_sha: base
  head_sha: head
  start_sha: start
  new_path: rules.yml
  old_path: rules.yml
  position_type: text
  new_line: 5
--- END ---

