File size: 1,436 Bytes
6236a08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392da6f
6236a08
 
 
 
 
 
 
 
 
 
 
 
392da6f
6236a08
 
 
 
 
 
 
 
392da6f
6236a08
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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