Skip to content

Commit

Permalink
1.8.0 - Add Jira status mappings (#407)
Browse files Browse the repository at this point in the history
* Add Jira status mappings

* Update documentation

* Bump version
  • Loading branch information
ImDevinC committed Jan 5, 2024
1 parent b741c9c commit 5391c38
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
9 changes: 9 additions & 0 deletions backend/bot/incident/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,15 @@ async def set_status(
logger.error(
f"Error sending status update to incident channel {incident_data.channel_name}: {error}"
)

# Update jira ticket status last
if config.active.integrations.get(
"atlassian", {}).get("jira", {}).get("status_mapping", []):
from bot.jira.api import JiraApi
jira = JiraApi()
jira.update_issue_status(incident_status=action_value,
incident_name=incident_data.channel_name)

# Finally, updated the updated_at column
db_update_incident_updated_at_col(
channel_id=incident_data.channel_id,
Expand Down
33 changes: 33 additions & 0 deletions backend/bot/jira/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,36 @@ def test(self) -> bool:
except Exception as error:
logger.error(f"Error authenticating to Jira: {error}")
logger.error(f"Please check Jira configuration and try again.")

def update_issue_status(self, incident_status: str, incident_name: str):
status_mapping = config.active.integrations.get(
"atlassian", {}).get("jira", {}).get("status_mapping", [])
if not status_mapping:
logger.debug("No status mapping found for Jira integration")
return
jira_status = ""
for status in status_mapping:
if status.get("incident_status").lower() == incident_status.lower():
jira_status = status.get("jira_status")
break
if not jira_status:
logger.debug(
f"No Jira status found for incident status {incident_status}")
return

try:
project = config.active.integrations.get(
"atlassian").get("jira").get("project")
labels = [incident_name]
issue_type = config.active.integrations.get(
"atlassian").get("jira").get("issue_type")
logger.info(
f"Updating Jira issues with labels {labels} and issue type {issue_type} to status {jira_status}")
issues = self.jira.jql_get_list_of_tickets(
f"project=\"{project}\" and labels in ({','.join(labels)})")
for issue in issues:
logger.debug(
f"Updating Jira issue {issue.get('key')} to status {jira_status}")
self.jira.set_issue_status(issue.get("key"), jira_status)
except requests.exceptions.HTTPError as error:
logger.error(f"Error updating Jira issue: {error}")
2 changes: 1 addition & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iblog import logger, log_level
from typing import Dict, List

__version__ = "v1.7.7"
__version__ = "v1.8.0"

# .env parse
dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bases:

images:
- name: eb129/incident-bot
newTag: v1.7.7
newTag: v1.8.0

configMapGenerator:
- name: incident-bot-config
Expand Down
9 changes: 9 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ integrations:
auto_create_incident: false
# If auto_create_incident is true, this is the type of the Jira ticket that will be created.
auto_create_incident_type: Subtask
status_mapping:
- incident_status: Investigating
jira_status: Open
- incident_status: Identified
jira_status: In Progress
- incident_status: Monitoring
jira_status: In Review
- incident_status: Resolved
jira_status: Done
opsgenie:
# Note that providing the 'team' value here will limit creation of alerts to a single team.
team: oncalls
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy/overlays/production/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bases:

images:
- name: eb129/incident-bot-docs
newTag: v1.7.7
newTag: v1.8.0

generatorOptions:
disableNameSuffixHash: true
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.7.7
v1.8.0

0 comments on commit 5391c38

Please sign in to comment.