Open bartbot opened 6 months ago
None
)[!TIP] I can email you when I complete this pull request if you set up your email here!
The sandbox appears to be unavailable or down.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
sweepai/config/server.py
✓ https://github.com/bartbot/sweep/commit/1c5a24ca37747700d1d39919d09f443fc34d2787 Edit
Modify sweepai/config/server.py with contents:
• Replace the GitHub-specific environment variables with their GitLab equivalents. Specifically, replace `GITHUB_APP_PEM`, `GITHUB_APP_ID`, and `GITHUB_BOT_USERNAME` with `GITLAB_APP_SECRET`, `GITLAB_APP_ID`, and `GITLAB_BOT_USERNAME` respectively.
• Update the default values for the GitLab environment variables based on the GitLab Oauth Application documentation. For example, `GITLAB_APP_ID` should default to `` in the development environment.
• Remove any GitHub-specific logic related to these environment variables. For example, the logic for appending "[bot]" to the `GITHUB_BOT_USERNAME` should be removed.
--- +++ @@ -9,16 +9,9 @@ load_dotenv(dotenv_path=".env") -os.environ["GITHUB_APP_PEM"] = os.environ.get("GITHUB_APP_PEM") or base64.b64decode( - os.environ.get("GITHUB_APP_PEM_BASE64", "") +os.environ["GITLAB_APP_SECRET"] = os.environ.get("GITLAB_APP_SECRET") or base64.b64decode( + os.environ.get("GITLAB_APP_SECRET_BASE64", "") ).decode("utf-8") - -if os.environ["GITHUB_APP_PEM"]: - os.environ["GITHUB_APP_ID"] = ( - (os.environ.get("GITHUB_APP_ID") or os.environ.get("APP_ID")) - .replace("\\n", "\n") - .strip('"') - ) os.environ["TRANSFORMERS_CACHE"] = os.environ.get( "TRANSFORMERS_CACHE", "/tmp/cache/model" @@ -66,25 +59,26 @@ if not GITLAB_REDIRECT_URI: raise ValueError("GitLab Redirect URI not found in environment variables.") # deprecated: old logic transfer so upstream can use this +# Default GitLab App IDs based on environment if GITLAB_APP_ID is None: if ENV == "prod": - GITLAB_APP_ID = "" + GITLAB_APP_ID = os.environ.get("GITLAB_APP_ID", " ") elif ENV == "dev": - GITLAB_APP_ID = " " + GITLAB_APP_ID = os.environ.get("GITLAB_APP_ID", " ") elif ENV == "staging": - GITLAB_APP_ID = " " + GITLAB_APP_ID = os.environ.get("GITLAB_APP_ID", " ") GITHUB_BOT_USERNAME = os.environ.get("GITHUB_BOT_USERNAME") # deprecated: left to support old logic -if not GITHUB_BOT_USERNAME: +# Set GitLab Bot Username based on environment +GITLAB_BOT_USERNAME = os.environ.get("GITLAB_BOT_USERNAME") +if not GITLAB_BOT_USERNAME: if ENV == "prod": - GITHUB_BOT_USERNAME = "sweep-ai[bot]" + GITLAB_BOT_USERNAME = " " elif ENV == "dev": - GITHUB_BOT_USERNAME = "sweep-nightly[bot]" + GITLAB_BOT_USERNAME = " " elif ENV == "staging": - GITHUB_BOT_USERNAME = "sweep-canary[bot]" -elif not GITHUB_BOT_USERNAME.endswith("[bot]"): - GITHUB_BOT_USERNAME = GITHUB_BOT_USERNAME + "[bot]" + GITLAB_BOT_USERNAME = " " GITLAB_LABEL_NAME = os.environ.get("GITLAB_LABEL_NAME", "sweep") GITLAB_LABEL_COLOR = os.environ.get("GITLAB_LABEL_COLOR", "9400D3") @@ -92,10 +86,7 @@ "GITLAB_LABEL_DESCRIPTION", "Sweep your software chores" ) GITHUB_APP_PEM = os.environ.get("GITHUB_APP_PEM") -GITHUB_APP_PEM = GITHUB_APP_PEM or os.environ.get("PRIVATE_KEY") -if GITHUB_APP_PEM is not None: - GITHUB_APP_PEM = GITHUB_APP_PEM.strip(' \n"') # Remove whitespace and quotes - GITHUB_APP_PEM = GITHUB_APP_PEM.replace("\\n", "\n") + GITLAB_CONFIG_BRANCH = os.environ.get("GITLAB_CONFIG_BRANCH", "sweep/add-sweep-config") GITLAB_DEFAULT_CONFIG = os.environ.get( @@ -230,7 +221,8 @@ WHITELISTED_USERS = os.environ.get("WHITELISTED_USERS", None) if WHITELISTED_USERS: WHITELISTED_USERS = WHITELISTED_USERS.split(",") - WHITELISTED_USERS.append(GITHUB_BOT_USERNAME) + # Append the GitLab bot username to the list of whitelisted users +WHITELISTED_USERS.append(GITLAB_BOT_USERNAME) DEFAULT_GPT4_32K_MODEL = os.environ.get("DEFAULT_GPT4_32K_MODEL", "gpt-4-1106-preview") DEFAULT_GPT35_MODEL = os.environ.get("DEFAULT_GPT35_MODEL", "gpt-3.5-turbo-1106")
sweepai/utils/gitlab_utils.py
✓ https://github.com/bartbot/sweep/commit/79b9e984365bfcf635e614b2f5355735b6af0316 Edit
Modify sweepai/utils/gitlab_utils.py with contents:
• Update the `get_gitlab_token` function to use the new GitLab environment variables. Specifically, replace `client_id` and `client_secret` with `GITLAB_APP_ID` and `GITLAB_APP_SECRET` respectively.
• Update the error message in the exception raised when the token cannot be obtained to reference the new GitLab environment variables.
--- +++ @@ -41,11 +41,11 @@ # Therefore, we can remove this function. -def get_gitlab_token(client_id: str, client_secret: str): +def get_gitlab_token(GITLAB_APP_ID: str, GITLAB_APP_SECRET: str): data = { 'grant_type': 'client_credentials', - 'client_id': client_id, - 'client_secret': client_secret + 'client_id': GITLAB_APP_ID, + 'client_secret': GITLAB_APP_SECRET } headers = { 'Content-Type': 'application/x-www-form-urlencoded' @@ -56,7 +56,7 @@ return response.json()['access_token'] time.sleep(timeout) raise Exception( - "Could not get token, please double check your PRIVATE_KEY and GITLAB_APP_ID in the .env file. Make sure to restart uvicorn after." + "Could not get token, please double check your GITLAB_APP_SECRET and GITLAB_APP_ID in the .env file. Make sure to restart uvicorn after." )
sweepai/utils/gitlab_utils_test.py
⋯ Edit
Create sweepai/utils/gitlab_utils_test.py with contents:
• Write unit tests for the `get_gitlab_token` function. The tests should cover all possible scenarios, including successful token retrieval and failure cases.
• The tests should mock the requests to the GitLab API and verify that the correct parameters are sent based on the environment variables.
• The tests should also verify that the function correctly handles the API responses and raises an exception when the token cannot be obtained.
Working on it...
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
Details
Sweep: update GITHUB environment variables in sweepai/config/server.py to their GitLab equivalents. Use GitLab Oauth Application documentation to source appropriate environment variables for sweepai/config/server.py.
Ensure that these variables are compatible with GitLab's Applications API here: https://docs.gitlab.com/ee/api/applications.html
Checklist
- [X] Modify `sweepai/config/server.py` ✓ https://github.com/bartbot/sweep/commit/1c5a24ca37747700d1d39919d09f443fc34d2787 [Edit](https://github.com/bartbot/sweep/edit/sweep/update_github_environment_variables_in_s/sweepai/config/server.py#L11-L97) - [X] Modify `sweepai/utils/gitlab_utils.py` ✓ https://github.com/bartbot/sweep/commit/79b9e984365bfcf635e614b2f5355735b6af0316 [Edit](https://github.com/bartbot/sweep/edit/sweep/update_github_environment_variables_in_s/sweepai/utils/gitlab_utils.py#L44-L60) - [ ] Create `sweepai/utils/gitlab_utils_test.py` ⋯ [Edit](https://github.com/bartbot/sweep/edit/sweep/update_github_environment_variables_in_s/sweepai/utils/gitlab_utils_test.py)