diff --git a/github_jira_sync_app/main.py b/github_jira_sync_app/main.py index 0299775..0c7c2f1 100644 --- a/github_jira_sync_app/main.py +++ b/github_jira_sync_app/main.py @@ -14,7 +14,6 @@ from github import GithubException from github import GithubIntegration from github import Issue -from github import UnknownObjectException from jira import JIRA from mistletoe import Document # type: ignore[import] from mistletoe.contrib.jira_renderer import JIRARenderer # type: ignore[import] @@ -300,11 +299,10 @@ async def bot(request: Request, payload: dict = Body(...)): synced_label_absent_in_repo = False - if settings["add_gh_synced_label"]: + if settings.get("add_gh_synced_label", False): try: - repo.get_label(gh_synced_label_name) gh_issue.add_to_labels(gh_synced_label_name) - except UnknownObjectException: + except GithubException: logger.warning(nonexistent_gh_label_warning) synced_label_absent_in_repo = True diff --git a/tests/unit/dumm_env b/tests/unit/dumm_env index 0086b7f..0800721 100644 --- a/tests/unit/dumm_env +++ b/tests/unit/dumm_env @@ -6,5 +6,5 @@ GITHUB_CLIENT_SECRET=rezindkm3dod04h12yt8oktm8if51wtsfgljk04k JIRA_INSTANCE="https://my-jira.atlassian.net" JIRA_USERNAME=maksim.beliaev@canonical.com JIRA_TOKEN=mv38swy07r6ius3v90cffyi4 -DEFAULT_BOT_CONFIG='{"settings": {"components": null, "labels": ["jira"], "add_gh_comment": false, "add_gh_synced_label": false, "sync_description": true, "sync_comments": true, "epic_key": null, "jira_project_key": null, "label_mapping": null, "status_mapping": null}}' +DEFAULT_BOT_CONFIG='{"settings": {"components": null, "labels": ["jira"], "add_gh_comment": false, "sync_description": true, "sync_comments": true, "epic_key": null, "jira_project_key": null, "label_mapping": null, "status_mapping": null}}' BOT_NAME="syncronize-issues-to-jira[bot]" \ No newline at end of file diff --git a/tests/unit/url_responses/github_responses_synced_label_exists.yaml b/tests/unit/url_responses/github_responses_synced_label_exists.yaml index 38e9d92..b2384d0 100644 --- a/tests/unit/url_responses/github_responses_synced_label_exists.yaml +++ b/tests/unit/url_responses/github_responses_synced_label_exists.yaml @@ -1,14 +1,5 @@ # this file is generated automatically via responses. Use _recorder.record() responses: -# get the synced-to-jira label from the repo -- response: - auto_calculate_content_length: false - body: '{"id":208045946,"node_id":"MDU6TGFiZWwyMDgwNDU5NDY=","url":"https://api.github.com:443/repos/beliaev-maksim/test-ci/labels/synced-to-jira","name":"synced-to-jira","description":"TicketinJirahasbeencreatedforthisissue","color":"f29513","default":false}' - content_type: text/plain - method: GET - status: 200 - url: https://api.github.com:443/repos/beliaev-maksim/test-ci/labels/synced-to-jira - # add the synced-to-jira label to the new issue - response: auto_calculate_content_length: false diff --git a/tests/unit/url_responses/github_responses_synced_label_notfound.yaml b/tests/unit/url_responses/github_responses_synced_label_notfound.yaml index 9d4c033..c099b68 100644 --- a/tests/unit/url_responses/github_responses_synced_label_notfound.yaml +++ b/tests/unit/url_responses/github_responses_synced_label_notfound.yaml @@ -1,14 +1,14 @@ # this file is generated automatically via responses. Use _recorder.record() responses: -# get the (nonexistent) synced-to-jira label from the repo - response: auto_calculate_content_length: false - body: '{"message": "Not Found", "documentation_url": "https://docs.github.com/rest/issues/labels#get-a-label", "status": "404"}' + # this body is not accurate and requires capturing a real call + body: '[{"id":208045946,"node_id":"MDU6TGFiZWwyMDgwNDU5NDY=","url":"https://api.github.com:443/repos/beliaev-maksim/test-ci/labels/synced-to-jira","name":"synced-to-jira","description":"TicketinJirahasbeencreatedforthisissue","color":"f29513","default":false}]' content_type: text/plain - method: GET - status: 404 - url: https://api.github.com:443/repos/beliaev-maksim/test-ci/labels/synced-to-jira - + method: POST + # this error code is provisional + status: 422 + url: https://api.github.com:443/repos/beliaev-maksim/test-ci/issues/30/labels # add comment to GitHub issue with warning about misconfiguration - response: auto_calculate_content_length: false