From 204057c82f8d8f2c26e66808dec5cd5e724623ea Mon Sep 17 00:00:00 2001 From: Lorenzo Medici Date: Tue, 17 Dec 2024 17:28:36 +0200 Subject: [PATCH] Warning comment always added in case of synced-with-jira label not existing --- README.md | 7 +++---- github_jira_sync_app/main.py | 2 +- tests/unit/test_server.py | 3 ++- .../auth_github_responses_sync_label_not_found.yaml | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f4067af..fd84593 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,9 @@ settings: # (Optional) (Default: false) Add a new comment in GitHub with a link to Jira created issue add_gh_comment: false - # (Optional) (Default: false) Add a 'synced-to-jira' label to newly created issues when a corresponding - # ticket is created in Jira. This is meant to replace the comment depending on project preferences, - # but comments will still be added if is true. - # The 'synced-to-jira' label must already be present in the GitHub repo and will not be created by the bot. + # (Optional) (Default: false) Add a 'synced-to-jira' label to newly created issues once a + # corresponding ticket is successfully created in Jira. + # This label serves as confirmation that the issue sync process was completed successfully. add_gh_synced_label: false # (Optional) (Default: true) Synchronize issue description from GitHub to Jira diff --git a/github_jira_sync_app/main.py b/github_jira_sync_app/main.py index ad66db6..26197ee 100644 --- a/github_jira_sync_app/main.py +++ b/github_jira_sync_app/main.py @@ -308,7 +308,7 @@ async def bot(request: Request, payload: dict = Body(...)): logger.warning(nonexistent_gh_label_warning) synced_label_absent_in_repo = True - if settings["add_gh_comment"]: + if settings["add_gh_comment"] or synced_label_absent_in_repo: gh_comment_body = gh_comment_body_template.format(jira_issue_link=new_issue.permalink()) if synced_label_absent_in_repo: diff --git a/tests/unit/test_server.py b/tests/unit/test_server.py index 448309c..b05fc90 100644 --- a/tests/unit/test_server.py +++ b/tests/unit/test_server.py @@ -277,7 +277,8 @@ def test_issue_created_and_sync_label_not_present(signature_mock): 6. Validate via JQL that this issue does not exist in Jira 7. Create new issue in Jira 8. Try and validate that synced-to-jira label exists in repo - 9. Label doesn't exist, nothing is done on the GitHub issue + 9. Label doesn't exist, warning comment is added to GitHub issue even though + is false """ responses._add_from_file( UNITTESTS_DIR / "url_responses" / "auth_github_responses_sync_label_not_found.yaml" diff --git a/tests/unit/url_responses/auth_github_responses_sync_label_not_found.yaml b/tests/unit/url_responses/auth_github_responses_sync_label_not_found.yaml index 9b5e5db..e171616 100644 --- a/tests/unit/url_responses/auth_github_responses_sync_label_not_found.yaml +++ b/tests/unit/url_responses/auth_github_responses_sync_label_not_found.yaml @@ -39,3 +39,13 @@ responses: method: GET status: 404 url: https://api.github.com:443/repos/beliaev-maksim/test-ci/labels/synced-to-jira + +# add comment to GitHub issue with warning about misconfiguration +- response: + auto_calculate_content_length: false + body: > + {"id":1,"node_id":"MDEyOklzc3VlQ29tbWVudDE=","url":"https://api.github.com:443/repos/beliaev-maksim/test-ci/issues/comments/12345","html_url":"https://github.com/beliaev-maksim/test-ci/issues/30#issuecomment-12345","body":"Thank you for reporting your feedback to us!\n\nThe internal ticket has been created:{jira_issue_link}.\n\n>This message was auto generated\n\nWarning: 'synced-to-jira' label doesn't exist in the GitHub repo.","user":{"login":"beliaev-maksim","id":51964909,"node_id":"MDQ6VXNlcjUxOTY0OTA5","avatar_url":"https://avatars.githubusercontent.com/u/51964909?v=4","gravatar_id":"","url":"https://api.github.com/users/beliaev-maksim","html_url":"https://github.com/beliaev-maksim","followers_url":"https://api.github.com/users/beliaev-maksim/followers","following_url":"https://api.github.com/users/beliaev-maksim/following{/other_user}","gists_url":"https://api.github.com/users/beliaev-maksim/gists{/gist_id}","starred_url":"https://api.github.com/users/beliaev-maksim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beliaev-maksim/subscriptions","organizations_url":"https://api.github.com/users/beliaev-maksim/orgs","repos_url":"https://api.github.com/users/beliaev-maksim/repos","events_url":"https://api.github.com/users/beliaev-maksim/events{/privacy}","received_events_url":"https://api.github.com/users/beliaev-maksim/received_events","type":"User","site_admin":false},"created_at":"2011-04-14T16:00:49Z","updated_at":"2011-04-14T16:00:49Z","issue_url":"https://api.github.com:443/repos/beliaev-maksim/test-ci/issues/30","author_association":"COLLABORATOR"} + content_type: text/plain + method: POST + status: 201 + url: https://api.github.com:443/repos/beliaev-maksim/test-ci/issues/30/comments \ No newline at end of file