Jira Weekly Done Issues to Slack - Gazi's Version

Customize this app
28
import logging
import requests
import os
from datetime import datetime, timedelta
import json
from pprint import pprint
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from flask import Flask, render_template_string

app = Flask(__name__)

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARNING)

def format_ticket(ticket, jira_domain):
    story_points = ticket['fields'].get('customfield_10016', 'Not set')  # Assuming 'customfield_10016' is for story points
    formatted_message = f"""
Ticket Title: *{ticket['fields']['summary']}*
Ticket ID: {ticket['id']}
Priority: {ticket['fields']['priority']['name']}
Assignee: {ticket['fields']['assignee']['displayName'] if ticket['fields']['assignee'] else "Unassigned"}
Story Points: {story_points}
URL: https://{jira_domain}.atlassian.net/browse/{ticket['key']}
Get full code

Jira Weekly Done Issues to Slack - Gazi's Version

Created: | Last Updated:

Introduction to the Template

This template, Jira Weekly Done Issues to Slack - Gazi's Version, provides a summary of completed Jira tasks posted to a specific Slack thread every week. It uses the Jira API to download closed tickets from the current week and posts the ticket details, including the ticket URL and Jira story points, into a Slack message thread.

Getting Started

To get started with this template, click Start with this Template.

Initial Setup

This template requires setting up environment secrets. Follow these steps to configure the necessary environment secrets:

  1. JIRA_DOMAIN: Your Jira domain (e.g., 'your-company').
  2. JIRA_EMAIL: Your Jira account email.
  3. JIRA_API_TOKEN: Generate this from your Atlassian account settings. Learn how to generate an API token.
  4. SLACK_TOKEN: Generate this from the Slack API website. Learn how to generate a Slack token.
  5. SLACK_CHANNEL: The channel ID where updates will be posted. You can find the channel ID by right-clicking on the channel name in Slack and selecting "Copy Link". The channel ID is the last part of the URL.

Set these as environment secrets in the Environment Secrets tab within the Lazy Builder.

Test

Press the Test button to begin the deployment of the app. The Lazy CLI will prompt you for any required user input.

Using the App

Once the app is deployed, it will provide a web interface accessible via a dedicated server link. The interface includes a button to manually trigger the weekly Jira update.

  1. Open the provided server link.
  2. Click the "Run Update" button to manually trigger the Jira update.

Integrating the App

The app will automatically post weekly updates to the specified Slack channel. If you need to integrate this app further, follow these steps:

  1. Jira Integration: Ensure your Jira account has the necessary permissions to access the tickets and generate API tokens.
  2. Slack Integration: Ensure your Slack app has the necessary permissions to post messages in the specified channel. You may need to add the chat:write scope to your Slack app.

Sample Slack Message

Here is an example of what the Slack message will look like:

Ticket Title: *Sample Ticket Title* Ticket ID: 12345 Priority: High Assignee: John Doe Story Points: 5 URL: https://your-company.atlassian.net/browse/ABC-123

By following these steps, you can successfully set up and use the Jira Weekly Done Issues to Slack - Gazi's Version template to keep your team updated on completed Jira tasks.

Technologies

Flask Flask
Jira Jira
Python Python
Slack Slack