[PR #10011/c2480730 backport][stable-9] fix: github_deploy_key check key exists on 422 (#10035)

fix: github_deploy_key check key exists on 422 (#10011)

* fix: github_deploy_key check key exists on 422

If we get a 422 response code as we add a key, check if it's because the key already exists or for another reason.

fixes: #6718

* chore: add changelog 10011-github_deploy_key-check-key-present

* chore: fix changelog fragment

* chore: fix changelog fragment

* Update changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c248073079)

Co-authored-by: Alex Garel <alex@garel.org>
This commit is contained in:
patchback[bot] 2025-04-21 13:20:35 +02:00 committed by GitHub
parent 8b1a193a49
commit 2448503e8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -259,7 +259,12 @@ class GithubDeployKey(object):
key_id = response_body["id"]
self.module.exit_json(changed=True, msg="Deploy key successfully added", id=key_id)
elif status_code == 422:
self.module.exit_json(changed=False, msg="Deploy key already exists")
# there might be multiple reasons for a 422
# so we must check if the reason is that the key already exists
if self.get_existing_key():
self.module.exit_json(changed=False, msg="Deploy key already exists")
else:
self.handle_error(method="POST", info=info)
else:
self.handle_error(method="POST", info=info)