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":"rules.yml","new_path":"rules.yml","diff":"@@ -1,7 +1,7 @@\n groups:\n - name: foo\n   rules:\n-  - record: rule1\n+  - record: rule3\n     expr: sum(foo) by(job)\n   - record: rule2\n     expr: sum(rule1) by(job)\n"}]
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:6222

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 GITLAB_AUTH_TOKEN=secret
exec pint -l debug --offline --no-color ci
! stdout .
cmp gitlab.got ../gitlab.expected

-- src/v1.yml --
groups:
- name: foo
  rules:
  - record: foo
    expr: count by (a, b, c, job) (bar)

-- src/v2.yml --
groups:
- name: foo
  rules:
  - record: foo
    expr: count by (a, b, c) (bar)

-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
repository {
  gitlab {
    uri        = "http://127.0.0.1:6222"
    timeout    = "30s"
    project    = "1234"
  }
}
rule {
  aggregate ".+" {
    comment  = "Must keep job label"
    severity = "warning"
    keep     = ["job"]
  }
}

-- 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/) **promql/aggregate** check.

  <details>
  <summary>required label is being removed via aggregation</summary>

  ```yaml
  5 |     expr: count by (a, b, c) (bar)
                      ^^^ 
  ```

  Query is using aggregation with `by(a, b, c)`, only labels included inside `by(...)` will be present on the results.

  `job` label is required and should be preserved when aggregating all rules.

  Rule comment: Must keep job label

  </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/aggregate.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
  old_line: 5
--- END ---

