From f97fa2210e22624f294c00f38b1c5d3a2f314b24 Mon Sep 17 00:00:00 2001 From: iperezx Date: Fri, 13 Feb 2026 12:52:04 -0800 Subject: [PATCH 1/2] Add Black formatting autocommit --- .github/workflows/black-autocommit.yml | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/black-autocommit.yml diff --git a/.github/workflows/black-autocommit.yml b/.github/workflows/black-autocommit.yml new file mode 100644 index 0000000..c44287c --- /dev/null +++ b/.github/workflows/black-autocommit.yml @@ -0,0 +1,35 @@ +name: Black Auto-Commit + +on: + pull_request: # only run for PRs (e.g., branch "test" -> "main") + +permissions: + contents: write # allow pushing commits to the branch that opened the PR + +jobs: + black: + runs-on: ubuntu-latest + steps: + - name: Check out PR branch + uses: actions/checkout@v4 + with: + # When triggered by pull_request, checkout@v4 checks out the PR HEAD. + fetch-depth: 0 # needed to push + persist-credentials: true # lets the action use GITHUB_TOKEN to push + + - name: Run Black (format in-place) + id: black + uses: rickstaa/action-black@v1 + with: + # no --check: we WANT it to rewrite files + black_args: "." + + - name: Commit & push if files were reformatted + if: steps.black.outputs.is_formatted == 'true' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: ":art: Apply Black formatting" + # By default it commits to the currently checked out branch (the PR branch). + # Optionally restrict to Python paths: + # file_pattern: | + # **/*.py From c77ea24c37885c3ac4f1bc88cde77b5d2385ee72 Mon Sep 17 00:00:00 2001 From: iperezx <33365058+iperezx@users.noreply.github.com> Date: Fri, 13 Feb 2026 20:52:52 +0000 Subject: [PATCH 2/2] :art: Apply Black formatting --- api/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/app.py b/api/app.py index 5a2da4f..aa12047 100644 --- a/api/app.py +++ b/api/app.py @@ -5,28 +5,35 @@ app = FastAPI(title="Example Items API", version="1.0.0") + class ItemBase(BaseModel): name: str = Field(..., min_length=1, max_length=100) description: Optional[str] = None price: float = Field(..., gt=0) in_stock: bool = True + class ItemCreate(ItemBase): pass + class Item(ItemBase): id: str + items_db: dict[str, Item] = {} + @app.get("/") def root(): return {"message": "Welcome to the Items API"} + @app.get("/health") def health_check(): return {"status": "ok"} + @app.post("/items", response_model=Item, status_code=201) def create_item(item: ItemCreate): item_id = str(uuid4()) @@ -34,6 +41,7 @@ def create_item(item: ItemCreate): items_db[item_id] = new_item return new_item + @app.get("/items", response_model=List[Item]) def list_items( min_price: Optional[float] = Query(None, gt=0), @@ -46,12 +54,14 @@ def list_items( results = [i for i in results if i.in_stock == in_stock] return results + @app.get("/items/{item_id}", response_model=Item) def get_item(item_id: str): if item_id not in items_db: raise HTTPException(status_code=404, detail="Item not found") return items_db[item_id] + @app.put("/items/{item_id}", response_model=Item) def update_item(item_id: str, updated_item: ItemCreate): if item_id not in items_db: @@ -61,6 +71,7 @@ def update_item(item_id: str, updated_item: ItemCreate): items_db[item_id] = item return item + @app.delete("/items/{item_id}", status_code=204) def delete_item(item_id: str): if item_id not in items_db: