Weekly Jira Issue Count to Slack

 
import os
import pandas as pd
from jira import JIRA
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from tabulate import tabulate
import schedule
import time

# TODO: Obtain the Jira server URL, username, API token, and project name.

jira_server = os.environ['JIRA_SERVER']
jira_username = os.environ['JIRA_USERNAME']
jira_api_token = os.environ['JIRA_API_TOKEN']
jira_project_name = os.environ['JIRA_PROJECT_NAME']

jira = JIRA(server=jira_server, basic_auth=(jira_username, jira_api_token))

# TODO: Define the JQL query to fetch issues that had status change in the last week.

jql_query = f'project = "{jira_project_name}" AND status changed DURING (startOfWeek(), endOfWeek())'

# TODO: Obtain the Slack token and channel ID.

About this template

This app fetches Jira issues that had status change in the last week, calculates the count of issues in different issue types, further breaks down each issue type by issue status, prepares a summary for it in form of a table using tabulate, posts the summary in a Slack channel, and schedules the app to run every time the server is started and then every week afterwards. The app requires the following environment variables to be set: - `JIRA_SERVER`: The URL of your Jira server. - `JIRA_USERNAME`: Your Jira username. - `JIRA_API_TOKEN`: Your Jira API token. - `JIRA_PROJECT_NAME`: The name of your Jira project. - `SLACK_TOKEN`: Your Slack token. - `CHANNEL_ID`: The ID of the Slack channel where the summary will be posted.

Introduction to the Weekly Jira Issue Count to Slack Template

Welcome to the step-by-step guide on how to set up and use the Weekly Jira Issue Count to Slack template. This template is designed to help you automate the process of fetching Jira issues that had a status change in the last week, calculate the count of issues in different types, break down each issue type by status, and post a summary in a Slack channel. The app also schedules itself to run every week, ensuring you stay updated with minimal effort.

To get started, simply click on "Start with this Template" on the Lazy platform.

Setting Environment Secrets

Before you can use this template, you'll need to set up some environment secrets. These are necessary for the app to communicate with your Jira and Slack accounts. Here's what you need to do:

  • Go to the Environment Secrets tab within the Lazy Builder.
  • Set the following secrets with the respective values:
    • `JIRA_SERVER`: The URL of your Jira server.
    • `JIRA_USERNAME`: Your Jira username.
    • `JIRA_API_TOKEN`: Your Jira API token. You can generate this from your Jira account settings.
    • `JIRA_PROJECT_NAME`: The name of your Jira project.
    • `SLACK_TOKEN`: Your Slack token. This is obtained from your Slack app settings.
    • `CHANNEL_ID`: The ID of the Slack channel where the summary will be posted.

External Integrations

For this template to function correctly, you'll need to have access to both Jira and Slack. Ensure you have the necessary permissions to create an API token in Jira and a bot token in Slack. If you don't have these permissions, please contact your Jira and Slack administrators.

Using the Test Button

Once you have set up the environment secrets, you can use the Test button to begin the deployment of the app. The Lazy CLI will prompt you for any required user input. There's no need to worry about installing libraries or setting up the environment, as Lazy handles all of that for you.

After using the Test button, if the app requires an API, Lazy will provide you with a dedicated server link to use the API. In the case of FastAPI, you will also receive a docs link to interact with the app.

How to Use the Interface

Once the app is deployed, it will automatically run the job to fetch and post the Jira issue summary to the specified Slack channel. The app is scheduled to run this job every week, but you can trigger it manually by using the Test button again.

If you need to make any changes to the JQL query or the Slack message format, you can do so directly within the Lazy Builder interface. Remember to save your changes and use the Test button to redeploy the app with the new configuration.

That's it! You've successfully set up the Weekly Jira Issue Count to Slack template. Your Slack channel will now receive automated weekly updates on the Jira issue status changes, helping you and your team stay informed and responsive.

Category
Technology
Last published
July 20, 2024

More templates like this

MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.

Python
Flask

Discord Moderation Bot

The Discord bot monitors all messages in the server. If a message contains profanity, the bot deletes it and sends a warning to the channel. The bot also notifies the host about the deletion via a direct message. Additionally, the bot outputs a helpful error message to a channel if there is a permissions error, guiding the server admin to enable the required permission in the Discord Developer portal.

Discord
Python
Flask

Basic Slack Bot

This is a simple starting point for a Slack bot it just responds hi to a mention.

Slack
Home
/
Weekly Jira Issue Count to Slack