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

2 legos: post slack image, comment on Github issue #366

Merged
merged 7 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"action_type": "LEGO_TYPE_AWS",
"action_entry_function": "aws_get_redshift_query_details",
"action_needs_credential": "true",
"action_output_type": "ACTION_OUTPUT_TYPE_DICT",
"action_output_type": "ACTION_OUTPUT_TYPE_STR",
"action_is_check": "false",
"action_supports_iteration": "true",
"action_supports_poll": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InputSchema(BaseModel):
description='Id of Redshift Query', title='queryId'

)


@beartype
def aws_get_redshift_query_details(handle, region: str, queryId:str) -> Dict:
Expand All @@ -30,6 +31,14 @@ def aws_get_redshift_query_details(handle, region: str, queryId:str) -> Dict:
response = client.describe_statement(
Id=queryId
)
return response
resultReady = response['HasResultSet']
queryTimeNs = response['Duration']
ResultRows = response['ResultRows']
details = {"Status": response['Status'],
"resultReady": resultReady,
"queryTimeNs":queryTimeNs,
"ResultRows":ResultRows
}
return details


Binary file added Github/legos/github_issue_comment/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Github/legos/github_issue_comment/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions Github/legos/github_issue_comment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">](https://unskript.com/assets/favicon.png)
<h2>Github Add Comment to an Issue</h2>

<br>

## Description
This Action adds a comment to the desired issue

## Lego Details

def github_comment_on_issue(handle, owner:str, repository:str, issue_number:str, issue_comment:str) -> str:

handle: Object of type unSkript Github Connector
owner: String, Username of the GitHub user. Eg: "johnwick"
repository: String, Full name of the GitHub repository. Eg: "unskript/Awesome-CloudOps-Automation"
issue_number: The issue that you wish to comment on.
issue_comment: The text to be added as a comment.

## Lego Input
This Lego take 5 inputs handle, owner, repository, issue_number and issue_comment

## Lego Output
Here is a sample output.
<img src="./1.jpg">

<img src="./2.jpg">


## See it in Action

You can see this Lego in action following this link [unSkript Live](https://us.app.unskript.io)
Empty file.
11 changes: 11 additions & 0 deletions Github/legos/github_issue_comment/github_issue_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"action_title": "Github Comment on an Issue",
"action_description": "Add a comment to the selected GitHub Issue",
"action_type": "LEGO_TYPE_GITHUB",
"action_entry_function": "github_issue_comment",
"action_needs_credential": "true",
"action_output_type": "ACTION_OUTPUT_TYPE_DICT",
dougsillars marked this conversation as resolved.
Show resolved Hide resolved
"action_is_check": "false",
"action_supports_iteration": "true",
"action_supports_poll": "true"
}
49 changes: 49 additions & 0 deletions Github/legos/github_issue_comment/github_issue_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##
## Copyright (c) 2023 unSkript, Inc
## All rights reserved.
##

import pprint
from typing import Optional, List, Dict
from pydantic import BaseModel, Field
from github import GithubException


class InputSchema(BaseModel):
owner: str = Field(
description='Username of the GitHub user. Eg: "johnwick"',
title='Owner'
)
repository: str = Field(
description='Name of the GitHub repository. Eg: "Awesome-CloudOps-Automation"',
title='Repository',
)
issue_comment: str = Field(
description='The Comment to add to the Issue',
title='Issue Comment'
)
issue_number: str = Field(
description='Github Issue where Comment is to be added.',
title='Issue Number'
)


def github_comment_on_issue_printer(output):
if output is None:
return
pprint.pprint(output)


def github_comment_on_issue(handle, owner:str, repository:str, issue_number:str, issue_comment:str) -> str:
issue_number = int(issue_number)
owner = handle.get_user(owner)
repo_name = owner.login +'/'+ repository
repo = handle.get_repo(repo_name)
# Get the issue by its number
issue = repo.get_issue(issue_number)

# Add a comment to the issue
newComment = issue.create_comment(issue_comment)
return "added comment"


Binary file added Slack/legos/slack_post_image/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Slack/legos/slack_post_image/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions Slack/legos/slack_post_image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">](https://unskript.com/assets/favicon.png)
<h1>Post Slack Message with an Image</h1>

## Description
This Lego Post Slack Message with an Image and gives a message sent status.


## Lego Details

slack_post_image(handle: object, channel: str, message: str, image: str)

handle: Object of type unSkript AWS Connector
channel: Name of slack channel.
message: Message sent to channel.
image: File Name of the image to be sent in the message.

Note: Your Slack App will need the ```files:write``` scope. Your Bot will also need to be a member of the channel that you wish to send the message to.


## Lego Input
This Lego take four inputs handle, channel, message and image.

## Lego Output
Here is a sample output.
<img src="./1.jpg">
<img src="./2.jpg">

## See it in Action
You can see this Lego in action following this link [unSkript Live](https://unskript.com)
Empty file.
10 changes: 10 additions & 0 deletions Slack/legos/slack_post_image/slack_post_image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ "action_title": "Post Slack Image",
"action_description": "Post Slack Image",
"action_type": "LEGO_TYPE_SLACK",
"action_entry_function": "slack_post_image",
"action_needs_credential": true,
"action_output_type": "ACTION_OUTPUT_TYPE_STR",
"action_supports_poll": true,
"action_supports_iteration": true
}

56 changes: 56 additions & 0 deletions Slack/legos/slack_post_image/slack_post_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##
# Copyright (c) 2021 unSkript, Inc
# All rights reserved.
##

import pprint

from pydantic import BaseModel, Field
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

pp = pprint.PrettyPrinter(indent=2)

from beartype import beartype

## note: Your Slack App will need the files:write scope. Your Bot will also need to be a member of the channel

class InputSchema(BaseModel):
channel: str = Field(
title='Channel',
description='Name of slack channel.')
message: str = Field(
title='message',
description='Message for slack channel.')
image: str = Field(
title='image',
description='Path to image to be sent.')

@beartype
def slack_post_image_printer(output):
if output is not None:
pprint.pprint(output)
else:
return


@beartype
def slack_post_image(
handle: WebClient,
channel: str,
message:str,
image: str) -> str:

try:
result = handle.files_upload(
channels = channel,
initial_comment=message,
file=image
)
return f"Successfully Sent Message on Channel: #{channel}"

except Exception as e:
print("\n\n")
pp.pprint(
f"Failed sending message to slack channel {channel}, Error: {e.__str__()}")
return f"Unable to send message on {channel}"
2 changes: 1 addition & 1 deletion Slack/legos/slack_post_message/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1>Post Slack Message </h1>

## Description
This Lego Post Slack Messageand gives a message sent status.
This Lego Post Slack Message and gives a message sent status.


## Lego Details
Expand Down
2 changes: 1 addition & 1 deletion Slack/legos/slack_post_message/slack_post_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def slack_post_message(
response = handle.chat_postMessage(
channel=channel,
text=message)
return f"Successfuly Sent Message on Channel: #{channel}"
return f"Successfully Sent Message on Channel: #{channel}"
except SlackApiError as e:
pp.pprint(
f"Failed sending message to slack channel {channel}, Error: {e.response['error']}")
Expand Down