Skip to content

Commit

Permalink
Add send mattermost message action
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Sep 13, 2024
1 parent 59eb2c9 commit 87be851
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AsanaGetUserIdForGithubHandleAction < Action
def self.run(params)
github_handle = params[:github_handle]

mapping_file = File.expand_path('../assets/github-asana-user-id-mapping.yml', __dir__)
mapping_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_get_user_id_for_github_handle/github-asana-user-id-mapping.yml")
user_mapping = YAML.load_file(mapping_file)
asana_user_id = user_mapping[github_handle]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "yaml"
require "httparty"
require "json"
require_relative "../helper/ddg_apple_automation_helper"

module Fastlane
module Actions
class MattermostSendMessageAction < Action
def self.run(params)
github_handle = params[:github_handle]
template_name = params[:template_name]
mm_webhook_url = params[:mattermost_webhook_url]

mapping_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("mattermost_send_message/github-mattermost-user-id-mapping.yml")
user_mapping = YAML.load_file(mapping_file)
mattermost_user_handle = user_mapping[github_handle]

if mattermost_user_handle.nil? || mattermost_user_handle.to_s.empty?
UI.message("Mattermost user handle not known for #{github_handle}, skipping sending message")
return
end

template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("mattermost_send_message/templates/#{template_name}.yml")
template_content = YAML.safe_load(Helper::DdgAppleAutomationHelper.load_file(template_file))
text = template_content["text"].gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') }

payload = {
"channel" => mattermost_user_handle,
"username" => "GitHub Actions",
"text" => text,
"icon_url" => "https://duckduckgo.com/assets/logo_header.v108.svg"
}

response = HTTParty.post(mm_webhook_url, {
headers: { 'Content-Type' => 'application/json' },
body: payload.to_json
})

# Check response status
if response.success?
puts("Message sent successfully!")
else
puts("Failed to send message: #{response.body}")
end
end

def self.description
"This action sends a message to Mattermost, reporting the outcome to the user who triggered the workflow"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
""
end

def self.details
# Optional:
""
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :mattermost_webhook_url,
env_name: "MM_WEBHOOK_URL",
description: "Mattermost webhook URL",
optional: false,
type: String),
FastlaneCore::ConfigItem.new(key: :github_handle,
description: "Github user handle",
optional: false,
type: String),
FastlaneCore::ConfigItem.new(key: :template_name,
description: "Name of a template file (without extension) for the message. Templates can be found in assets/mattermost_send_message/templates subdirectory.
The file is processed before being posted",
optional: false,
type: String)
]
end

def self.is_supported?(platform)
true
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
aataraxiaa: "@psmith"
afterxleep: "@dbernal"
alessandroboron: "@aboron"
amddg44: "@amallon"
ayoy: "@dkapusta"
brindy: "@brindy"
bwaresiak: "@bartek"
Bunn: "@fbunn"
dharb: "@dave"
diegoreymendez: "@dreymendez"
dus7: "@mariusz"
federicocappelli: "@fcappelli"
GioSensation: "@emanuele"
graeme: "@garthur"
jaceklyp: "@jlyp"
jonathanKingston: "@jkingston"
jotaemepereira: "@jpereira"
ladamski: "@ladamski"
mallexxx: "@amartemyanov"
miasma13: "@msmaga"
muodov: "@mtsoy"
quanganhdo: "@ado"
samsymons: "@ssymons"
shakyShane: "@sosbourne"
SabrinaTardio: "@stardio"
THISISDINOSAUR: "@esullivan"
tomasstrba: "@tom"
viktorjansson: "@viktor"
vinay-nadig-0042: "@vnadig"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: ":warning: **iOS release job failed** :thisisfine: | [:github: Workflow run summary](${WORKFLOW_URL})"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: "**Notarized macOS app `${RELEASE_TYPE}` build is ready** :goose_honk_tada: | [:github: Workflow run summary](${WORKFLOW_URL})${ASANA_LINK}",
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: ":rotating_light: **Notarized macOS app `${RELEASE_TYPE}` build failed** | [:github: Workflow run summary](${WORKFLOW_URL})${ASANA_LINK}"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: "**${APP_PLATFORM} app has been successfully uploaded to ${DESTINATION}** :goose_honk_tada: | [:github: Workflow run summary](${WORKFLOW_URL})"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: ":rotating_light: **macOS app ${DESTINATION} workflow failed** | [:github: Workflow run summary](${WORKFLOW_URL})"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: ":rotating_light: **macOS app variants workflow failed** | [:github: Workflow run summary](${WORKFLOW_URL})"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: "**macOS app variants have been published successfully** :goose_honk_tada: | [:github: Workflow run summary](${WORKFLOW_URL})"

0 comments on commit 87be851

Please sign in to comment.