Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging the step marketplace fix into argo-hub #382

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions workflows/slack/versions/0.0.2/images/post-to-channel/lib/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import os
import sys
import logging
import json
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

def main():
log_format = "%(asctime)s:%(levelname)s:%(name)s.%(funcName)s: %(message)s"
logging.basicConfig(format = log_format, level = os.environ['LOG_LEVEL'].upper())

channel=os.getenv('SLACK_CHANNEL')
message=os.getenv('SLACK_MESSAGE', "")
token =os.getenv('SLACK_TOKEN')
channel =os.getenv('SLACK_CHANNEL')
message =os.getenv('SLACK_MESSAGE', "")
token =os.getenv('SLACK_TOKEN')
attachments =os.getenv('SLACK_ATTACHMENTS', "")

if ( channel == None ):
logging.error("SLACK_CHANNEL is not defined")
Expand All @@ -25,6 +27,13 @@ def main():
logging.error("SLACK_TOKEN is not defined")
sys.exit(1)

if ( attachments != "" ):
try:
attachments = json.loads(attachments)
except ValueError as e:
logging.error(f"Error decoding attachments: {e}")
sys.exit(3)

logging.info("Connecting to Slack")
client = WebClient(token=token)

Expand All @@ -41,8 +50,7 @@ def main():
sys.exit(3)

try:
response = client.chat_postMessage(channel=channel, text=message)
assert response["message"]["text"] == message
response = client.chat_postMessage(channel=channel, text=message, attachments=attachments)
except SlackApiError as e:
# You will get a SlackApiError if "ok" is False
assert e.response["ok"] is False
Expand Down