import logging
import os

import httpx

logger = logging.getLogger("gitops")


async def post(message):
    """Post a message to a slack channel

    Uses the environment variable `SLACK_URL` to know which channel to post to.
    This URL is obtained by registering an integration with Slack.
    """
    logger.info("POSTING TO SLACK")
    url = os.environ["SLACK_URL"]
    data = {"text": message}
    async with httpx.AsyncClient() as client:
        response = await client.post(url, json=data)
        if response.status_code >= 300:
            logger.warning("Failed to post a message to slack (see below):")
            logger.error(f"{message}", exc_info=True)

import logging
import os

import httpx

logger = logging.getLogger("gitops")


async def post(message):
    """Post a message to a slack channel

    Uses the environment variable `SLACK_URL` to know which channel to post to.
    This URL is obtained by registering an integration with Slack.
    """
    logger.info("POSTING TO SLACK")
    url = os.environ["SLACK_URL"]
    data = {"text": message}
    async with httpx.AsyncClient() as client:
        response = await client.post(url, json=data)
        if response.status_code >= 300:
            logger.warning("Failed to post a message to slack (see below):")
            logger.error(f"{message}", exc_info=True)

Post a message to a slack channel      Uses the environment variable `SLACK_URL` to know which channel to post to.     This URL is obtained by registering an integration with Slack.