mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 08:03:39 +00:00
community: prevent gitlab commit on main branch for Gitlab tool (#27750)
### About
- **Description:** In the Gitlab utilities used for the Gitlab tool
there is no check to prevent pushing to the main branch, as this is
already done for Github (for example here:
5a2cfb49e0/libs/community/langchain_community/utilities/github.py (L587)
).
This PR add this check as already done for Github.
- **Issue:** None
- **Dependencies:** None
This commit is contained in:
parent
0a472e2a2d
commit
3dfdb3e6fb
@ -207,6 +207,12 @@ class GitLabAPIWrapper(BaseModel):
|
||||
Returns:
|
||||
str: A success or failure message
|
||||
"""
|
||||
if self.gitlab_branch == self.gitlab_base_branch:
|
||||
return (
|
||||
"You're attempting to commit directly"
|
||||
f"to the {self.gitlab_base_branch} branch, which is protected. "
|
||||
"Please create a new branch and try again."
|
||||
)
|
||||
file_path = file_query.split("\n")[0]
|
||||
file_contents = file_query[len(file_path) + 2 :]
|
||||
try:
|
||||
@ -253,6 +259,12 @@ class GitLabAPIWrapper(BaseModel):
|
||||
Returns:
|
||||
A success or failure message
|
||||
"""
|
||||
if self.gitlab_branch == self.gitlab_base_branch:
|
||||
return (
|
||||
"You're attempting to commit directly"
|
||||
f"to the {self.gitlab_base_branch} branch, which is protected. "
|
||||
"Please create a new branch and try again."
|
||||
)
|
||||
try:
|
||||
file_path = file_query.split("\n")[0]
|
||||
old_file_contents = (
|
||||
@ -299,6 +311,12 @@ class GitLabAPIWrapper(BaseModel):
|
||||
Returns:
|
||||
str: Success or failure message
|
||||
"""
|
||||
if self.gitlab_branch == self.gitlab_base_branch:
|
||||
return (
|
||||
"You're attempting to commit directly"
|
||||
f"to the {self.gitlab_base_branch} branch, which is protected. "
|
||||
"Please create a new branch and try again."
|
||||
)
|
||||
try:
|
||||
self.gitlab_repo_instance.files.delete(
|
||||
file_path, self.gitlab_branch, "Delete " + file_path
|
||||
|
Loading…
Reference in New Issue
Block a user