import os import gitlab from dotenv import load_dotenv load_dotenv() TEST_PROJECT_ID = 80447540 gl_token = os.getenv("GITLAB_TOKEN") gl = gitlab.Gitlab('https://gitlab.com', private_token=gl_token) project = gl.projects.get(TEST_PROJECT_ID) ci_config = """ stages: - analyze context_brain_job: stage: analyze image: python:3.10-slim script: - apt-get update && apt-get install -y git - git clone https://oauth2:${GITLAB_TOKEN}@gitlab.com/gitlab-ai-hackathon/participants/35466397.git context_brain_repo - cd context_brain_repo - pip install -r requirements.txt - python src/main.py - mv gl-code-quality-report.json ../gl-code-quality-report.json artifacts: when: always reports: codequality: gl-code-quality-report.json rules: - if: $CI_MERGE_REQUEST_IID """ try: project.commits.create({ 'branch': 'main', 'commit_message': 'Add pipeline to main', 'actions': [{'action': 'update', 'file_path': '.gitlab-ci.yml', 'content': ci_config}] }) print("Added to main") except Exception as e: print("Check 1:", e) pass try: project.commits.create({ 'branch': 'feature/agentic-testing-v1', 'commit_message': 'Add pipeline to branch', 'actions': [{'action': 'create', 'file_path': '.gitlab-ci.yml', 'content': ci_config}] }) print("Added to branch") except Exception as e: print("Check 2:", e) pass