Duo-Guardian / scripts /create_gcp_test_mr.py
Daksh C Jain
added split nodes
392da6f
import os
import gitlab
from dotenv import load_dotenv
load_dotenv()
TEST_PROJECT_ID = 80447540
BRANCH_NAME = "feature/final-e2e-test"
def main():
gl_token = os.getenv("GITLAB_TOKEN")
if not gl_token:
print("Missing GITLAB_TOKEN")
return
gl = gitlab.Gitlab('https://gitlab.com', private_token=gl_token)
project = gl.projects.get(TEST_PROJECT_ID)
try:
project.branches.create({'branch': BRANCH_NAME, 'ref': 'main'})
print(f"Created branch {BRANCH_NAME}")
except Exception as e:
print(f"Branch might already exist: {e}")
# Code to commit
gcp_code = """
from google.cloud import storage
from google.cloud import exceptions
def upload_user_data(bucket_name, data_file, destination_blob_name):
# Potential issue: using a generic wildcard or hardcoded outdated project ID
# This might match some active Error Reporting logs if the model is smart.
# Security risk: No error handling for unauthenticated requests
storage_client = storage.Client(project="legacy-gcp-project-id")
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
# We are directly uploading without validating file type or size
blob.upload_from_filename(data_file)
return True
"""
data = {
'branch': BRANCH_NAME,
'commit_message': 'Add GCP Cloud Storage logic',
'actions': [
{
'action': 'create',
'file_path': 'gcp_storage_handler.py',
'content': gcp_code
}
]
}
try:
project.commits.create(data)
print("Committed gcp_storage_handler.py")
except Exception as e:
print(f"Commit issue (file might exist): {e}")
try:
data['actions'][0]['action'] = 'update'
project.commits.create(data)
print("Updated gcp_storage_handler.py")
except Exception as e2:
pass
try:
mr = project.mergerequests.create({
'source_branch': BRANCH_NAME,
'target_branch': 'main',
'title': 'Feature: GCP Storage Integration',
'description': 'This MR introduces a new Cloud Storage upload flow. Needs context brain analysis to identify potential GCP runtime risks or security flaws.'
})
print(f"✅ MR created successfully: {mr.web_url}")
except Exception as e:
print(f"MR creation failed: {e}")
if __name__ == "__main__":
main()