Repository: getmoto/moto

Issue:
ECRBackend delete_repository ignoring force argument
## Bug Description

Recently in issue #4128 has been made a improvement to the delete_repository method in the ECRBackend class (moto==2.2.1 >=), but when we try to delete a repository with images inside, the `force` execution flow has not been implemented, which has broken our test/CI pipelines this week raising:

```
botocore.errorfactory.RepositoryNotEmptyException: An error occurred (RepositoryNotEmptyException) when calling the DeleteRepository operation: The repository with name 'abc-job-dev' in registry with id '123456789012' cannot be deleted because it still contains images
```

When we run this mocked code:

```
ecr_client = boto3.client("ecr")
ecr_client.delete_repository(
   repositoryName=job.image,
   force=True,  # remove all repository images
)
```

Basically, the temporary solution has been to hardcode moto to 2.2.0.



Discussion:
Thanks for raising this @victor-mariano-leite - will mark it as a bug.
@bblommers you can assign me, will create a PR today

Resolving patch:
diff --git a/moto/ecr/models.py b/moto/ecr/models.py
--- a/moto/ecr/models.py
+++ b/moto/ecr/models.py
@@ -371,10 +371,10 @@ def create_repository(
 
         return repository
 
-    def delete_repository(self, repository_name, registry_id=None):
+    def delete_repository(self, repository_name, registry_id=None, force=False):
         repo = self._get_repository(repository_name, registry_id)
 
-        if repo.images:
+        if repo.images and not force:
             raise RepositoryNotEmptyException(
                 repository_name, registry_id or DEFAULT_REGISTRY_ID
             )
diff --git a/moto/ecr/responses.py b/moto/ecr/responses.py
--- a/moto/ecr/responses.py
+++ b/moto/ecr/responses.py
@@ -51,7 +51,11 @@ def describe_repositories(self):
     def delete_repository(self):
         repository_str = self._get_param("repositoryName")
         registry_id = self._get_param("registryId")
-        repository = self.ecr_backend.delete_repository(repository_str, registry_id)
+        force = self._get_param("force")
+
+        repository = self.ecr_backend.delete_repository(
+            repository_str, registry_id, force
+        )
         return json.dumps({"repository": repository.response_object})
 
     def put_image(self):


Test patch:
diff --git a/tests/test_ecr/test_ecr_boto3.py b/tests/test_ecr/test_ecr_boto3.py
--- a/tests/test_ecr/test_ecr_boto3.py
+++ b/tests/test_ecr/test_ecr_boto3.py
@@ -305,6 +305,38 @@ def test_delete_repository():
     response["repositories"].should.have.length_of(0)
 
 
+@mock_ecr
+def test_delete_repository_with_force():
+    client = boto3.client("ecr", region_name="us-east-1")
+    repo_name = "test-repo"
+    client.create_repository(repositoryName=repo_name)
+    client.put_image(
+        repositoryName=repo_name,
+        imageManifest=json.dumps(_create_image_manifest()),
+        imageTag="latest",
+    )
+
+    # when
+    # when
+    response = client.delete_repository(repositoryName=repo_name, force=True)
+
+    # then
+    repo = response["repository"]
+    repo["repositoryName"].should.equal(repo_name)
+    repo["repositoryArn"].should.equal(
+        f"arn:aws:ecr:us-east-1:{ACCOUNT_ID}:repository/{repo_name}"
+    )
+    repo["registryId"].should.equal(ACCOUNT_ID)
+    repo["repositoryUri"].should.equal(
+        f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/{repo_name}"
+    )
+    repo["createdAt"].should.be.a(datetime)
+    repo["imageTagMutability"].should.equal("MUTABLE")
+
+    response = client.describe_repositories()
+    response["repositories"].should.have.length_of(0)
+
+
 @mock_ecr
 def test_put_image():
     client = boto3.client("ecr", region_name="us-east-1")