Skip to content

Commit

Permalink
WIP: Removed extra API call and simplified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-medici committed Dec 18, 2024
1 parent 838f132 commit bee4e48
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
6 changes: 2 additions & 4 deletions github_jira_sync_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dumm_env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ GITHUB_CLIENT_SECRET=rezindkm3dod04h12yt8oktm8if51wtsfgljk04k
JIRA_INSTANCE="https://my-jira.atlassian.net"
[email protected]
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]"
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit bee4e48

Please sign in to comment.