Skip to content

Commit

Permalink
Add support for sweep.yml as an alternative to the default `sweep.y…
Browse files Browse the repository at this point in the history
…aml`

This is the preferred file extension outside of the python ecosystem.
Preferably it would be entierly customizable but that would be a much
larger refector and out of scope for this commit.
  • Loading branch information
filiphsps committed Dec 13, 2023
1 parent bb084a7 commit 172a885
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/components/PRPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function PRPreview({ repoName, prId }) {
}}
>
{parsedDiff.map(({chunks, from, oldStart}) => (
from !== "/dev/null" && from !== "sweep.yaml" &&
from !== "/dev/null" && (from !== "sweep.yaml" || from !== "sweep.yml") &&
<>
<p style={{
marginTop: 0,
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/usage/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ We highly recommend linters, as well as Netlify/Vercel preview builds. Sweep aut

### Set up `sweep.yaml`

You can set up `sweep.yaml` to
You can set up `sweep.yaml` (or `sweep.yml`) to
* Provide up to date docs by setting up `docs` (https://docs.sweep.dev/usage/config#docs)
* Set up automated formatting and linting by setting up `sandbox` (https://docs.sweep.dev/usage/config#sandbox). Never have Sweep commit a failing `npm lint` again.
* Give Sweep a high level description of where to find files in your repo by editing the `repo_description` field.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/usage/config.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sweep Config

You can configure Sweep by modifying the `sweep.yaml` file, which should be in the root directory of your repository.
You can configure Sweep by modifying the `sweep.yaml` (or `sweep.yml`) file, which should be in the root directory of your repository.

After making your first Sweep issue, Sweep will make a PR to add the config file for you. If it's not there, you can create it yourself and add the following default config file:

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/usage/sandbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The sandbox executes a set of commands to validate Sweep's changes using linters

## Configuration

Go to your local clone of your repo. Create your `sweep.yaml` if it doesn't already exist and copy the following template into it:
Go to your local clone of your repo. Create your `sweep.yaml` (or `sweep.yml`) if it doesn't already exist and copy the following template into it:

<details>
<summary>Template&nbsp;`sweep.yaml`&nbsp;to copy</summary>
Expand Down
5 changes: 5 additions & 0 deletions sandbox/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def from_yaml(cls, yaml_string: str):
def from_config(cls, path: str = "sweep.yaml"):
if os.path.exists(path):
return cls.from_yaml(open(path).read())
elif os.path.exists(path.replace(".yaml", ".yml")):
return cls.from_yaml(open(path.replace(".yaml", ".yml")).read())
else:
return cls()

Expand Down Expand Up @@ -101,6 +103,9 @@ def get_sandbox_from_config():
if os.path.exists("sweep.yaml"):
config = yaml.load(open("sweep.yaml", "r"), Loader=yaml.FullLoader)
return Sandbox(**config.get("sandbox", {}))
elif os.path.exists("sweep.yml"):
config = yaml.load(open("sweep.yml", "r"), Loader=yaml.FullLoader)
return Sandbox(**config.get("sandbox", {}))
else:
return Sandbox()

Expand Down
10 changes: 8 additions & 2 deletions sandbox/src/sandbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ def from_yaml(cls, yaml_string: str):
def from_config(cls, path: str = "sweep.yaml"):
if os.path.exists(path):
return cls.from_yaml(open(path).read())
elif os.path.exists(path.replace(".yaml", ".yml")):
return cls.from_yaml(open(path.replace(".yaml", ".yml")).read())
else:
return cls()

@classmethod
def from_directory(cls, path: str):
if os.path.exists(os.path.join(path, "sweep.yaml")):
sandbox = cls.from_yaml(open(os.path.join(path, "sweep.yaml")).read())
if os.path.exists(os.path.join(path, "sweep.yaml")) or os.path.exists(os.path.join(path, "sweep.yml")):
if os.path.exists(os.path.join(path, "sweep.yaml")):
sandbox = cls.from_yaml(open(os.path.join(path, "sweep.yaml")).read())
else:
sandbox = cls.from_yaml(open(os.path.join(path, "sweep.yml")).read())

is_default_sandbox = True
if sandbox.install != ["trunk init"]:
is_default_sandbox = False
Expand Down
2 changes: 2 additions & 0 deletions sweepai/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ def remove_buttons_from_description(body):
):
if request_dict["head_commit"] and (
"sweep.yaml" in request_dict["head_commit"]["added"]
or "sweep.yml" in request_dict["head_commit"]["added"]
or "sweep.yaml" in request_dict["head_commit"]["modified"]
or "sweep.yml" in request_dict["head_commit"]["modified"]
):
_, g = get_github_client(request_dict["installation"]["id"])
repo = g.get_repo(request_dict["repository"]["full_name"])
Expand Down
40 changes: 37 additions & 3 deletions sweepai/config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SweepConfig(BaseModel):
".pem",
".ttf",
"sweep.yaml",
"sweep.yml"
]
# Image formats
max_file_limit: int = 60_000
Expand Down Expand Up @@ -122,6 +123,9 @@ def get_branch(repo: Repository, override_branch: str | None = None) -> str:
sweep_yaml_dict = {}
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

sweep_yaml_dict = yaml.safe_load(
contents.decoded_content.decode("utf-8")
)
Expand Down Expand Up @@ -153,6 +157,9 @@ def get_branch(repo: Repository, override_branch: str | None = None) -> str:
def get_config(repo: Repository):
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

config = yaml.safe_load(contents.decoded_content.decode("utf-8"))
return SweepConfig(**config)
except SystemExit:
Expand All @@ -167,6 +174,9 @@ def get_config(repo: Repository):
def get_draft(repo: Repository):
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

config = yaml.safe_load(contents.decoded_content.decode("utf-8"))
return config.get("draft", False)
except SystemExit:
Expand All @@ -180,6 +190,9 @@ def get_draft(repo: Repository):
def get_gha_enabled(repo: Repository) -> bool:
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

gha_enabled = yaml.safe_load(contents.decoded_content.decode("utf-8")).get(
"gha_enabled", True
)
Expand All @@ -197,6 +210,9 @@ def get_gha_enabled(repo: Repository) -> bool:
def get_description(repo: Repository) -> dict:
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

sweep_yaml = yaml.safe_load(contents.decoded_content.decode("utf-8"))
description = sweep_yaml.get("description", "")
rules = sweep_yaml.get("rules", [])
Expand All @@ -212,6 +228,9 @@ def get_description(repo: Repository) -> dict:
def get_sandbox_config(repo: Repository):
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

description = yaml.safe_load(contents.decoded_content.decode("utf-8")).get(
"sandbox", {}
)
Expand All @@ -226,6 +245,9 @@ def get_sandbox_config(repo: Repository):
def get_branch_name_config(repo: Repository):
try:
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

description = yaml.safe_load(contents.decoded_content.decode("utf-8")).get(
"branch_use_underscores", False
)
Expand All @@ -239,7 +261,11 @@ def get_branch_name_config(repo: Repository):
@lru_cache(maxsize=None)
def get_documentation_dict(repo: Repository):
try:
sweep_yaml_content = repo.get_contents("sweep.yaml").decoded_content.decode(
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

sweep_yaml_content = contents.decoded_content.decode(
"utf-8"
)
sweep_yaml = yaml.safe_load(sweep_yaml_content)
Expand All @@ -254,7 +280,11 @@ def get_documentation_dict(repo: Repository):
@lru_cache(maxsize=None)
def get_blocked_dirs(repo: Repository):
try:
sweep_yaml_content = repo.get_contents("sweep.yaml").decoded_content.decode(
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

sweep_yaml_content = contents.decoded_content.decode(
"utf-8"
)
sweep_yaml = yaml.safe_load(sweep_yaml_content)
Expand All @@ -269,7 +299,11 @@ def get_blocked_dirs(repo: Repository):
@lru_cache(maxsize=None)
def get_rules(repo: Repository):
try:
sweep_yaml_content = repo.get_contents("sweep.yaml").decoded_content.decode(
contents = repo.get_contents("sweep.yaml")
if contents is None:
contents = repo.get_contents("sweep.yml")

sweep_yaml_content = contents.decoded_content.decode(
"utf-8"
)
sweep_yaml = yaml.safe_load(sweep_yaml_content)
Expand Down
9 changes: 7 additions & 2 deletions sweepai/handlers/create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def create_pr_changes(
else:
pr_description = f"{pull_request.content}"
pr_title = pull_request.title
if "sweep.yaml" in pr_title:
if "sweep.yaml" in pr_title or "sweep.yml" in pr_title:
pr_title = "[config] " + pr_title
except MaxTokensExceeded as e:
logger.error(e)
Expand Down Expand Up @@ -237,7 +237,12 @@ def create_config_pr(
except SystemExit:
raise SystemExit
except Exception:
pass
try:
repo.get_contents("sweep.yml")
except SystemExit:
raise SystemExit
except Exception:
pass

title = "Configure Sweep"
branch_name = GITHUB_CONFIG_BRANCH
Expand Down
2 changes: 1 addition & 1 deletion sweepai/handlers/on_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def edit_sweep_comment(message: str, index: int, pr_message="", done=False):
sweep_yml_exists = False
sweep_yml_failed = False
for content_file in repo.get_contents(""):
if content_file.name == "sweep.yaml":
if content_file.name == "sweep.yaml" or content_file.name == "sweep.yml":
sweep_yml_exists = True

# Check if YAML is valid
Expand Down
4 changes: 2 additions & 2 deletions tests/archive/test_diff_parsing3.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,10 @@ def log_error(error_type, exception, priority=0):
sweep_context=sweep_context,
)
# Check repository for sweep.yml file.
# Check repository for sweep.yaml/sweep.yml file.
sweep_yml_exists = False
for content_file in repo.get_contents(""):
if content_file.name == "sweep.yaml":
if content_file.name == "sweep.yaml" or content_file.name == "sweep.yml":
sweep_yml_exists = True
break
Expand Down
4 changes: 2 additions & 2 deletions tests/archive/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,10 @@ def edit_sweep_comment(message: str, index: int, pr_message="", done=False):
cloned_repo=cloned_repo,
)
# Check repository for sweep.yml file.
# Check repository for sweep.yaml/sweep.yml file.
sweep_yml_exists = False
for content_file in repo.get_contents(""):
if content_file.name == "sweep.yaml":
if content_file.name == "sweep.yaml" or content_file.name == "sweep.yml":
sweep_yml_exists = True
break
Expand Down
4 changes: 2 additions & 2 deletions tests/archive/test_naive_chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ def edit_sweep_comment(message: str, index: int, pr_message="", done=False):
sweep_context=sweep_context,
)
# Check repository for sweep.yml file.
# Check repository for sweep.yaml/sweep.yml file.
sweep_yml_exists = False
for content_file in repo.get_contents(""):
if content_file.name == "sweep.yaml":
if content_file.name == "sweep.yaml" or content_file.name == "sweep.yml":
sweep_yml_exists = True
break
Expand Down
4 changes: 2 additions & 2 deletions tests/search/test_lexical_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ def edit_sweep_comment(message: str, index: int, pr_message="", done=False):
sweep_context=sweep_context,
)
# Check repository for sweep.yml file.
# Check repository for sweep.yaml/sweep.yml file.
sweep_yml_exists = False
for content_file in repo.get_contents(""):
if content_file.name == "sweep.yaml":
if content_file.name == "sweep.yaml" or content_file.name == "sweep.yml":
sweep_yml_exists = True
break
Expand Down

0 comments on commit 172a885

Please sign in to comment.