http method github GET /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 []
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/reviews 200 {}
http method github GET /api/v3/repos/cloudflare/pint/pulls/1/comments 200 []
http method github GET /api/v3/repos/cloudflare/pint/issues/1/comments 200 []
http method github POST /api/v3/repos/cloudflare/pint/pulls/1/comments 200 {}
http start github 127.0.0.1:6119

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 GITHUB_AUTH_TOKEN=12345
env GITHUB_PULL_REQUEST_NUMBER=1
! exec pint -l debug --offline --no-color ci --fail-on=warning
! stdout .
stderr 'level=INFO msg="Pull request review created" status="200 OK"'
cmp github.got ../github.expected

-- src/v1.yml --
- alert: rule1
  expr: sum(foo) by(job)
- alert: rule2
  expr: sum(foo) by(job)
  for: 0s

-- src/v2.yml --
- alert: rule1
  expr: sum(foo) by(job)
  for: 0s
- alert: rule2
  expr: sum(foo) by(job)
  for: 0s

-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
parser {
  relaxed = [".*"]
}
repository {
  github {
    baseuri   = "http://127.0.0.1:6119"
    uploaduri = "http://127.0.0.1:6119"
    owner     = "cloudflare"
    repo      = "pint"
  }
}
rule {
  label "severity" {
    value    = "critical|warning|info"
    required = true
    comment  = "Use correct severity"
  }
}

-- github.expected --
GET /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

GET /api/v3/repos/cloudflare/pint/issues/1/comments
  Accept: application/vnd.github.squirrel-girl-preview
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
  :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **rule/label** check.

  <details>
  <summary>required label not set</summary>

  ```yaml
  3 |   for: 0s
             ^^
  ```

  `severity` label is required.

  Rule comment: Use correct severity

  </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/label.html).
path: rules.yml
line: 3
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
  :warning: **Warning** reported by [pint](https://cloudflare.github.io/pint/) **alerts/comparison** check.

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

  ```yaml
  2 |   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).
path: rules.yml
line: 3
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

POST /api/v3/repos/cloudflare/pint/pulls/1/comments
  Accept: application/vnd.github.squirrel-girl-preview, application/vnd.github.comfort-fade-preview+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
body: |
  :information_source: **Information** reported by [pint](https://cloudflare.github.io/pint/) **alerts/for** check.

  <details>
  <summary>redundant field with default value</summary>

  ```yaml
  3 |   for: 0s
             ^^
  ```

  `0s` is the default value of `for`, this line is unnecessary.

  </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/for.html).
path: rules.yml
line: 3
side: RIGHT
commit_id: <COMMIT ID>
--- END ---

GET /api/v3/repos/cloudflare/pint/pulls/1/reviews
  Accept: application/vnd.github.v3+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  X-Github-Api-Version: 2022-11-28

POST /api/v3/repos/cloudflare/pint/pulls/1/reviews
  Accept: application/vnd.github.v3+json
  Accept-Encoding: gzip
  Authorization: Bearer 12345
  Content-Type: application/json
  X-Github-Api-Version: 2022-11-28
--- BODY ---
commit_id: <COMMIT ID>
body: |+
  ### This pull request was validated by [pint](https://github.com/cloudflare/pint).
  :heavy_exclamation_mark:	Problems found.
  | Severity | Number of problems |
  | --- | --- |
  | Warning | 2 |
  | Information | 1 |
  <details><summary>Stats</summary>
  <p>

  | Stat | Value |
  | --- | --- |
  | Version | unknown |
  | Number of rules parsed | 2 |
  | Number of rules checked | 2 |
  | Number of problems found | 3 |
  | Number of offline checks | 10 |
  | Number of online checks | 0 |
  | Checks duration | 0 |

  </p>
  </details>

  <details><summary>Problems</summary>
  <p>

  ```
  Warning: required label not set (rule/label)
    ---> rules.yml:1-3 -> `rule1`
  3 |   for: 0s
             ^^ `severity` label is required.

  Warning: always firing alert (alerts/comparison)
    ---> rules.yml:2 -> `rule1`
  2 |   expr: sum(foo) by(job)
                  ^^^
                  This query doesn't have any condition and so this alert will always fire if it matches
                  anything.

  Information: redundant field with default value (alerts/for)
    ---> rules.yml:3 -> `rule1`
  3 |   for: 0s
             ^^ `0s` is the default value of `for`, this line is unnecessary.

  ```

  </p>
  </details>

event: COMMENT
--- END ---

