Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #44 from tom-borcin/fix/custom_field_assign
Browse files Browse the repository at this point in the history
Add try-except when assigning customfield
  • Loading branch information
tomassebestik authored May 23, 2023
2 parents 35cf4f8 + 19ec810 commit 9c26787
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions sync_issues_to_jira/sync_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from jira import JIRA
from jira import JIRA, JIRAError
from github import Github
from github.GithubException import GithubException
import json
Expand Down Expand Up @@ -71,8 +71,11 @@ def handle_issue_closed(jira, event):
# issues often get closed for the wrong reasons - ie the user
# found a workaround but the root cause still exists.
issue = _leave_jira_issue_comment(jira, event, "closed", False)
# Sets value of custom GitHub Issue field to Closed
issue.update(fields={'customfield_12100': {'value': 'Closed'}})
try :
# Sets value of custom GitHub Issue field to Closed
issue.update(fields={'customfield_12100': {'value': 'Closed'}})
except JIRAError as error:
print(f'Could not set GitHub Issue field to Closed when closing issue with error: {error}')
if issue is not None:
_update_link_resolved(jira, event["issue"], issue)

Expand Down Expand Up @@ -119,8 +122,11 @@ def handle_issue_deleted(jira, event):

def handle_issue_reopened(jira, event):
issue = _leave_jira_issue_comment(jira, event, "reopened", True)
# Sets value of custom GitHub Issue field to Open
issue.update(fields={'customfield_12100': {'value': 'Open'}})
try :
# Sets value of custom GitHub Issue field to Open
issue.update(fields={'customfield_12100': {'value': 'Open'}})
except JIRAError as error:
print(f'Could not set GitHub Issue field to Open when reopening issue with error: {error}')
_update_link_resolved(jira, event["issue"], issue)


Expand Down Expand Up @@ -298,12 +304,16 @@ def _create_jira_issue(jira, gh_issue):
"description": _get_description(gh_issue),
"issuetype": issuetype,
"labels": [_get_jira_label(l) for l in gh_issue["labels"]],
# Sets value of custom GitHub Issue field to Open
'customfield_12100': {'value': 'Open'},
}
_update_components_field(jira, fields, None)

issue = jira.create_issue(fields)

try :
# Sets value of custom GitHub Issue field to Open
issue.update(fields={'customfield_12100': {'value': 'Open'}})
except JIRAError as error:
print(f'Could not set GitHub Issue field to Open when creating new issue with error: {error}')

_add_remote_link(jira, issue, gh_issue)
_update_github_with_jira_key(gh_issue, issue)
Expand Down

0 comments on commit 9c26787

Please sign in to comment.