Codium-ai / pr-agent

🚀CodiumAI PR-Agent: An AI-Powered 🤖 Tool for Automated Pull Request Analysis, Feedback, Suggestions and More! 💻🔍
Apache License 2.0
5.63k stars 519 forks source link

gitlab pipeline not working in self hosted gitlab , facing issue #1171

Closed prasadnaikg-ldp closed 1 week ago

prasadnaikg-ldp commented 3 weeks ago

pr_agent_job: stage: pr_agent image: name: codiumai/pr-agent:latest entrypoint: [""] script:

despite getting following issue : File "/app/pr_agent/git_providers/init.py", line 62, in get_git_provider_with_context raise ValueError(f"Failed to get git provider for {pr_url}") from e ValueError: Failed to get git provider for https://selfhostedgitlab.com/abc/abcd/abcde/merge_requests/19

mrT23 commented 2 weeks ago

Self hosted gitlab is fully supported in PR-Agent pro. I am not sure if its supported in free PR-Agent.

Try first with CLI, and see if you can connect there

paolomainardi commented 2 weeks ago

I use it on a self-hosted GitLab, and it works without any issues.

I've created this Gitlab component to simplify the usage:

spec:
  inputs:
    job-prefix:
      description: "Define a prefix for the job name"
      default: codium
    stage:
      description: "Define the stage for the job"
      default: .pre
    pr-agent-version:
      description: "Define the version of the PR Agent to use"
      default: latest
    auto_review:
      description: "Enable/Disable auto review"
      type: boolean
      default: true
    auto_describe:
      description: "Enable/Disable auto describe"
      type: boolean
      default: true
    describe_publish_labels:
      description: "Publish gitlab labels when describe"
      type: boolean
      default: false
    gitlab_pat:
      description: "GitLab Personal Access Token"
    auto_improve:
      description: "Enable/Disable auto improve"
      type: boolean
      default: true
    # Supported models: https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/__init__.py
    # At the moment we just support Openai and Anthropic.
    ai_model:
      description: "Model to use for the PR Agent, at the moment we support openai and anthropic."
      default: openai
    ai_key:
      description: "API Key for the AI Provider"
---
"$[[ inputs.job-prefix ]].mr-agent":
  stage: "$[[ inputs.stage ]]"
  image:
    name: codiumai/pr-agent:$[[ inputs.pr-agent-version ]]
    entrypoint: [""]
  script:
    - |
      cd /app
      echo "Running PR Agent action step"
      export MR_URL="$CI_MERGE_REQUEST_PROJECT_URL/merge_requests/$CI_MERGE_REQUEST_IID"
      echo "MR_URL=$MR_URL"
      export config__git_provider="gitlab"
      export gitlab__PERSONAL_ACCESS_TOKEN=$[[ inputs.gitlab_pat ]]
      export gitlab__url=$CI_SERVER_PROTOCOL://$CI_SERVER_FQDN
      export ai_model=$[[ inputs.ai_model ]]
      export pr_description__publish_labels=$[[ inputs.describe_publish_labels ]]

      # Handle the AI provider key.
      echo "Confiuring $ai_model model"
      if [ "$ai_model" == "openai" ]; then
        export openai__key=$[[ inputs.ai_key ]]
      elif [ "$ai_model" == "anthropic" ]; then   
        export config__model="anthropic/claude-3-5-sonnet-20240620"
        export config__model_turbo="anthropic/claude-3-5-sonnet-20240620"
        export config__fallback_models="['anthropic/claude-3-5-sonnet-20240620']"
        export anthropic__key=$[[ inputs.ai_key ]]
      fi

      if $[[ inputs.auto_describe ]]; then
        python -m pr_agent.cli --pr_url="$MR_URL" describe
      fi
      if $[[ inputs.auto_review ]]; then
        python -m pr_agent.cli --pr_url="$MR_URL" review
      fi
      if $[[ inputs.auto_improve ]]; then
        python -m pr_agent.cli --pr_url="$MR_URL" improve
      fi
  allow_failure: true
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
mrT23 commented 1 week ago

@prasadnaikg-ldp Closing. If you try CLI and it works, you can re-open