Lambda function to evaluate Apple Style Guide Validator responses
============================================================

This lambda takes the raw responses from the Apple Style Guide Validator, evaluates them, and then packages the result into a payload for downstream consumers.
---------------------------

### Python environment
Requires: python3.13
You can use a UV virtual environment or use Docker as is preferred in the Orchard Python Lambda [boilerplate](https://github.com/theorchard/docs/tree/master/boilerplates/python-lambda).
```commandline
uv venv
uv sync
```

## Setup Docker
* Install [docker](https://docs.docker.com/get-docker/)
* Clone this repository
* Navigate to the lambda you want to work on in `lambda/`

## Running

### Start Container
```
docker-compose up --build -d function
```

### Execute Function
Use the HTTP client of your choice. The body of the request is the `event` passed into the function.

```
curl --request POST \
  --url http://localhost:9000/2015-03-31/functions/function/invocations \
  --header 'Content-Type: application/json' \
  --data @tests/sample_event.json
```

### Load Changes
The `src` directory and `config.py` are mounted into the container via the `docker-compose.yaml` configuration. This means you don't need to re-build the entire container to see changes. **However** the container will need to be restarted. This process should be as quick as restarting uwsgi when making changes to a web application.
```
docker-compose restart function
```
:zap: You should add this command to a post-write hook in your preferred editor to automatically restart.

### Deploy to Dev

If you would like to deploy your lambda to the AWS Dev environment before pushing to AWS ECR make sure that the Docker image is built for the proper platform (especially if you are using M1 chip).
So instead of
```shell
docker build -t my-lambda .
```
do
```shell
docker build -t my-lambda --platform=linux/amd64 .
```

## Linting and Testing

### Run Container
```
docker compose run --build --rm lint-and-test
```

### Set pytest Options

Sometimes you may want to customize how tests run using [pytest options](https://docs.pytest.org/en/stable/usage.html) when doing development locally, only running a subset of tests using `-k` for example.

```
docker compose run --build --rm -e TEST_ARGS="-s -k some_test" lint-and-test
```


### Set pytest-cov Options
By default test coverage is calculated for files in `./src` and displayed in a table after tests run. To see output as HTML override `COV_REPORT` and see results in the **host** at `./htmlcov/index.html` after running tests.

```
docker compose run --build --rm -e COV_REPORT=html lint-and-test
```


### Skip Linting
When developing locally, you might not want to worry about linting when working to make tests pass.

```
docker compose run --build --rm -e SKIP_LINT=1 lint-and-test
```

### Datadog Configuration

In order to get traces and metrics (in addition to logs) from the [Datadog Lambda Library](https://docs.datadoghq.com/serverless/installation/python/?tab=containerimage), you'll need to have the following environment variables:
    ENVIRONMENT
    DD_LAMBDA_HANDLER (your lambda's original handler, e.g. "src.app.handler")
These can be set via terraform, for example [here](https://github.com/theorchard/terraform-infra/blob/master/qa/lambda-sound-recordings/lambda_sr_add_version.tf#L84-L91).
Notice, the linked example in terraform-infra is utilizing our terraform-lambda module, which does a lot of the setup work under the hood.
