diff --git a/damspam/__init__.py b/damspam/__init__.py index b1f4059333a4c91a0e70548056e431aa42713403..c1b077db0db6b130e5028c7f07a882dd247396cd 100644 --- a/damspam/__init__.py +++ b/damspam/__init__.py @@ -530,9 +530,13 @@ class DamSpamIssue: readonly: bool = attr.ib(default=False) @property - def is_closed(self): + def is_closed(self) -> bool: return self.issue.state == "closed" + @property + def is_assigned_to_spambot(self) -> bool: + return SPAMBOT_USER_ID in [a["id"] for a in self.issue.assignees] + def block_issue_creator( self, recursive: bool = True, @@ -691,8 +695,8 @@ class DamSpamIssue: if not project_name: return "Failed to extract project name" - if SPAMBOT_USER_ID in [a["id"] for a in self.issue.assignees]: - return "Project already assigned to spambot" + if self.is_assigned_to_spambot: + return "Issue already assigned to spambot" try: author = self.issue.author @@ -855,7 +859,7 @@ class Secrets: try: if not_read_only(self, "Pushing changes"): self.git_cmds_submodule([["git", "push", "origin", "master"]]) - self.git_cmds([["git", "push", "origin", "master"]]) + self.git_cmds([["git", "push", "origin", "main"]]) except Exception as e: logger.error(e) raise SecretsUpdateError("Failed to push damspam config") diff --git a/damspam/cli.py b/damspam/cli.py index d7b119d4240f3f535a0b204d39d8e59d0f1e02a8..3e983c5f2bee8d1083738f30453a29a2269f512c 100644 --- a/damspam/cli.py +++ b/damspam/cli.py @@ -550,7 +550,7 @@ def do_request_webhook( @damspam.command( - name="hook-request-webhook", + name="hook-process-webhook-request", help="Handle the webhook payload from a webhook request", ) @click.option( @@ -648,6 +648,8 @@ def do_request_webhook_webhook( ds_issue = builder.build_damspam_issue() if ds_issue.is_closed: die("Issue already closed") + if ds_issue.is_assigned_to_spambot: + die("Issue already assigned to spambot") error = ds_issue.process_webhook_request() if error is not None: ds_issue.close_with_message(error) diff --git a/tests/test_damspam.py b/tests/test_damspam.py index 8c11cc4c92c28f785fdde7ceacda9a4c288f7008..e9fd03b134d76e5c951a534eb90db3186175ace3 100644 --- a/tests/test_damspam.py +++ b/tests/test_damspam.py @@ -773,7 +773,7 @@ def init_fake_git_repo(path: Path, repo_name: Path, submodule_name: Path) -> Pat submodule_dir = path / submodule_name submodule_dir.mkdir() - # The repo used as submodule + # The repo used as submodule (master branch) with open(submodule_dir / "damspam.yaml", "w") as fd: fd.write( "\n".join( @@ -811,8 +811,8 @@ def init_fake_git_repo(path: Path, repo_name: Path, submodule_name: Path) -> Pat cwd=submodule_dir, ) - # The parent module - subprocess.run(["git", "init", "-b", "master"], cwd=repo_dir) + # The parent module (main branch) + subprocess.run(["git", "init", "-b", "main"], cwd=repo_dir) subprocess.run( ["git", "config", "--local", "receive.denyCurrentBranch", "ignore"], cwd=repo_dir,