http response bitbucket /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint 200 OK
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests 200 {}
http start bitbucket 127.0.0.1:6076

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 BITBUCKET_AUTH_TOKEN="12345"
! exec pint -l warn --no-color ci --require-owner
! stdout .
cmp stderr ../stderr.txt

-- src/v1.yml --
groups:
- name: mygroup
  rules:
  - record: rule1
    expr: sum(foo) by(job)
-- src/v2.yml --
groups:
- name: mygroup
  rules:
  - alert: syntax error
    expr: sum(foo) bar

  - alert: missing required fields
    expr: no_such_metric{job="fake"}

  - record: vector_matching
    expr: up{job="prometheus"} / prometheus_build_info{job="prometheus"}

  - alert: count
    expr: up{job="prometheus"} == 0
    for: 2m
    labels:
      notify: blackhole

  - alert: for_and_rate
    expr: rate(no_such_metric[10s])
    for: 0m
    labels:
      notify: blackhole

  - alert: template
    expr: sum(no_such_metric) by(foo) > 0
    labels:
      value: '{{ $value }}'
    annotations:
      instance: 'sum on {{ $labels.instance }} is {{ $value }}'

  - alert: fragile
    expr: errors / sum(requests) without(rack)

  - record: regexp
    expr: sum(no_such_metric{job=~"fake"})

  - alert: dups
    expr: errors / sum(requests) without(rack)
    #expr: errors / sum(requests) without(rack)
    #alert: dups
-- src/.pint.hcl --
ci {
  baseBranch = "main"
}
parser {
  include    = [".+.yml"]
}
repository {
  bitbucket {
    uri        = "http://127.0.0.1:6076"
    timeout    = "10s"
    project    = "prometheus"
    repository = "rules"
  }
}
rule {
  match {
    kind = "recording"
  }
  aggregate ".+" {
    severity = "bug"
    keep     = ["job"]
  }
}
rule {
  match {
    kind = "alerting"
  }
  annotation "link" {
    severity = "bug"
    value    = "http://runbooks.example.com/(.+)"
    required = true
  }
}
rule {
  match {
    kind = "alerting"
  }
  ignore {
    kind = "alerting"
    label "notify" {
      value = "blackhole"
    }
  }
  annotation "summary" {
    severity = "bug"
    required = true
  }
  annotation "dashboard" {
    severity = "bug"
    value    = "https://grafana.example.com/(.+)"
  }
  label "priority" {
    severity = "bug"
    value    = "(1|2|3|4|5)"
    required = true
  }
  label "notify" {
    severity = "bug"
    required = true
  }
  label "component" {
    severity = "bug"
    required = true
  }
}

-- stderr.txt --
Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `link` annotation is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `summary` annotation is required.

Bug: required label not set (rule/label)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `component` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `notify` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `priority` label is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:4-5 -> `syntax error`
5 |     expr: sum(foo) bar
              ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Fatal: PromQL syntax error (promql/syntax)
  ---> rules.yml:5 -> `syntax error`
5 |     expr: sum(foo) bar
                       ^^^ unexpected identifier "bar"

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `link` annotation is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `summary` annotation is required.

Bug: required label not set (rule/label)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `component` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `notify` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `priority` label is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:7-8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Warning: always firing alert (alerts/comparison)
  ---> rules.yml:8 -> `missing required fields`
8 |     expr: no_such_metric{job="fake"}
              ^^^^^^^^^^^^^^^^^^^^^^^^^^ This query doesn't have any condition and so this alert will always fire if it matches anything.

Bug: missing owner (rule/owner)
  ---> rules.yml:10-11 -> `vector_matching`
11 |     expr: up{job="prometheus"} / prometheus_build_info{job="prometheus"}
               ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:13-17 -> `count`
17 |       notify: blackhole
           ^^^ `link` annotation is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:13-17 -> `count`
17 |       notify: blackhole
           ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:19-23 -> `for_and_rate`
23 |       notify: blackhole
           ^^^ `link` annotation is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:19-23 -> `for_and_rate`
23 |       notify: blackhole
           ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Warning: always firing alert (alerts/comparison)
  ---> rules.yml:20 -> `for_and_rate`
20 |     expr: rate(no_such_metric[10s])
                    ^^^^^^^^^^^^^^^^^^^ 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:21 -> `for_and_rate`
21 |     for: 0m
              ^^ `0m` is the default value of `for`, this line is unnecessary.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `link` annotation is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `summary` annotation is required.

Bug: template uses non-existent label (alerts/template)
  ---> rules.yml:25-30 -> `template`
26 |     expr: sum(no_such_metric) by(foo) > 0
                                   ^^ Query is using aggregation with `by(foo)`, only labels included inside `by(...)` will be present on the results.
   | [...]
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
                                       ^^^^^^^^^ Template is using `instance` label but the query results won't have this label.

Bug: required label not set (rule/label)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `component` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `notify` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `priority` label is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:25-30 -> `template`
30 |       instance: 'sum on {{ $labels.instance }} is {{ $value }}'
           ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Bug: value used in labels (alerts/template)
  ---> rules.yml:28 -> `template`
28 |       value: '{{ $value }}'
                   ^^^^^^^^^^^^ Using `$value` in labels will generate a new alert on every value change, move it to annotations.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `link` annotation is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `summary` annotation is required.

Bug: required label not set (rule/label)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `component` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `notify` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `priority` label is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:32-33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Warning: always firing alert (alerts/comparison)
  ---> rules.yml:33 -> `fragile`
33 |     expr: errors / sum(requests) without(rack)
               ^^^^^^ This query doesn't have any condition and so this alert will always fire if it matches anything.

Bug: missing owner (rule/owner)
  ---> rules.yml:35-36 -> `regexp`
36 |     expr: sum(no_such_metric{job=~"fake"})
               ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Warning: redundant regexp (promql/regexp)
  ---> rules.yml:36 -> `regexp`
36 |     expr: sum(no_such_metric{job=~"fake"})
                                  ^^^^^^^^^^^ Unnecessary regexp match on static string `job=~"fake"`, use `job="fake"` instead.

Bug: required label is being removed via aggregation (promql/aggregate)
  ---> rules.yml:36 -> `regexp`
36 |     expr: sum(no_such_metric{job=~"fake"})
               ^^^ Query is using aggregation that removes all labels.
                   `job` label is required and should be preserved when aggregating all rules.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `link` annotation is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `summary` annotation is required.

Bug: required label not set (rule/label)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `component` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `notify` label is required.

Bug: required label not set (rule/label)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `priority` label is required.

Bug: missing owner (rule/owner)
  ---> rules.yml:38-39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^ `rule/owner` comments are required in all files, please add a `# pint file/owner $owner` somewhere in this file and/or `# pint rule/owner $owner` on top of each rule.

Warning: always firing alert (alerts/comparison)
  ---> rules.yml:39 -> `dups`
39 |     expr: errors / sum(requests) without(rack)
               ^^^^^^ This query doesn't have any condition and so this alert will always fire if it matches anything.

level=ERROR msg="Execution completed with error(s)" err="submitting reports: fatal error(s) reported"
