Skip to content

Error reading guidelines files #753

@shaked-hadas

Description

@shaked-hadas

Hi
I've set up GitStream on my gitlab repo, but when I open a PR, the gitStream ci fails with this errors:

{
  errorName: 'FiltersValidator: ',
  error: ValidationError: Line 12: Invalid filter function readFile in expression {{ "../cm/REVIEW_RULES.md" | readFile() | dump }}
      at FiltersValidator.validateExistingFilter (/node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:770:13)
      at /node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:821:16
      at Array.forEach (<anonymous>)
      at FiltersValidator.validate (/node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:810:23)
      at /node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:6907:31
      at Array.forEach (<anonymous>)
      at RuleParser.validateCM (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:6905:29)
      at RuleParser._callee11$ (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:7035:18)
      at tryCatch (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:197:16)
      at Generator.<anonymous> (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:285:17)
}
{
  errorName: 'ContextVariableValidator: ',
  error: ValidationError: Line [12]: Invalid context variable "../cm/REVIEW_RULES.md" in expression {{ "../cm/REVIEW_RULES.md" | readFile() | dump }}
      at /node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:745:17
      at Array.forEach (<anonymous>)
      at /node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:743:10
      at Array.forEach (<anonymous>)
      at ContextVariableValidator.validate (/node_modules/@linearb/gitstream-core-js/dist/gitstream-core-js.cjs.development.js:732:23)
      at /node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:6907:31
      at Array.forEach (<anonymous>)
      at RuleParser.validateCM (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:6905:29)
      at RuleParser._callee11$ (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:7035:18)
      at tryCatch (/node_modules/@linearb/gitstream-core/dist/gitstream-core.cjs.development.js:197:16)
}
(node:18) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Error in code-review@v1 action: Request failed with status code 403
Error in describe-changes@v1 action: Request failed with status code 403
Validator error - FiltersValidator: ValidationError: Line 12: Invalid filter function readFile in expression {{ "../cm/REVIEW_RULES.md" | readFile() | dump }}
Validator error - ContextVariableValidator: ValidationError: Line [12]: Invalid context variable "../cm/REVIEW_RULES.md" in expression {{ "../cm/REVIEW_RULES.md" | readFile() | dump }}
Sending results to rules resolver...
Failed sending evaluated rules to the resolver. { error: 'Request failed with status code 403' }

Here is my .cm file:

# -*- mode: yaml -*-
    # This example configuration provides basic automations to get started with gitStream.
    # View the gitStream quickstart for more examples: https://docs.gitstream.cm/examples/
    manifest:
      version: 1.0
    
    automations:
      # Use LinearB's AI service to review the changes
      linearb_ai_review:
        if:
          - {{ not pr.draft }}
          - {{ not is.bot }}
        run:
          - action: code-review@v1
            args:
              guidelines: {{ "../cm/REVIEW_RULES.md" | readFile() | dump }}
    
      # Use LinearB's AI service to add a description to the PR
      linearb_ai_description:
        if:
          - {{ not pr.draft }}
          - {{ not (is.bot_author or is.bot_branch) }}
        run:
          - action: describe-changes@v1
            args:
              concat_mode: append
    
      # Add a label indicating how long it will take to review the PR.
      estimated_time_to_review:
        if:
          - true
        run:
          - action: add-label@v1
            args:
              label: "{{ calc.etr }} min review"
              color: {{ colors.red if (calc.etr >= 20) else ( colors.yellow if (calc.etr >= 5) else colors.green ) }}
      # Post a comment that lists the best experts for the files that were modified.
      explain_code_experts:
        if:
          - true
        run:
          - action: explain-code-experts@v1
            args:
              gt: 10

    
    # +----------------------------------------------------------------------------+
    # | Custom Expressions                                                         |
    # | https://docs.gitstream.cm/how-it-works/#custom-expressions                 |
    # +----------------------------------------------------------------------------+
    
    calc:
      etr: {{ branch | estimatedReviewTime }}
    
    colors:
      red: 'b60205'
      yellow: 'fbca04'
      green: '0e8a16'
    
    is:
      bot_author: {{ pr.author | match(list=['github-actions', '_bot_', '[bot]', 'dependabot']) | some }}
      bot_branch: {{ branch.name | match(list=['renovate/']) | some }}

and .gitlab-ci.yml file:

# Code generated by gitStream - DO NOT EDIT
variables:
  DOCKER_DRIVER: overlay2
  DOCKER_HOST: tcp://docker:2375
  DOCKER_TLS_CERTDIR: ""

stages:
  - gitstream-main

image: docker:latest

services:
  - name: docker:dind

before_script:
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

gitstream-job:
  stage: gitstream-main
  only:
    variables:
      - $GITSTREAM_MAIN_JOB
  except:
    variables:
      - $GITSTREAM_BLOCK_MERGE
  script:
    - apk update && apk add git && apk add docker
    - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}${repoUrl} gitstream/repo
    - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}${cmUrl} gitstream/cm
    - cd gitstream && cd repo && git fetch --all && git checkout $base_ref && git pull && ls && git checkout $head_ref && git pull && ls
    - docker pull gitstream/rules-engine:latest
    - |
      docker run -v $CI_PROJECT_DIR/gitstream:/code \
      -e HEAD_REF=$head_ref \
      -e BASE_REF=$base_ref \
      -e CLIENT_PAYLOAD="$client_payload" \
      -e RULES_RESOLVER_URL=$resolver_url \
      -e RULES_RESOLVER_TOKEN=$resolver_token \
      -e DEBUG_MODE=true  gitstream/rules-engine:latest

I've tried stating few different guidelines files, both on the target repo and on the cm repo, and it still fails with the same error.
Am I missing something?

Thanks for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working👀.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions