in devai-api/app/gitlab_utils.py [0:0]
def _create_branch() -> str:
"""Creates a new branch in GitLab for a merge request.
Returns:
str: The name of the newly created branch.
"""
gitlab_url = os.environ["GITLAB_URL"]
gitlab_base_branch = os.environ["GITLAB_BASE_BRANCH"]
gitlab_repo_name = os.environ["GITLAB_REPOSITORY"]
gitlab_access_token = os.environ["GITLAB_PERSONAL_ACCESS_TOKEN"]
gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_access_token)
project = gl.projects.get(gitlab_repo_name)
new_branch_name = f'feature/generated-{datetime.datetime.now().strftime("%m%d%Y-%H%M")}'
project.branches.create({'branch': new_branch_name, 'ref': gitlab_base_branch})
print("Created new branch:", new_branch_name)
return new_branch_name