fastlane-plugin-discord_notifier 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3001a33edbdf017d3f5c0e0b27042bad5faed8b868c9d411f062a92f5a93937b
4
- data.tar.gz: 484b513d6f1da18ca2564d20587fc632b40551ab7e307125a44ae4fca57c7e3e
3
+ metadata.gz: df02d5432c8eb9b837f56d41a5dcfacb0024acdc8f1a983df5dfd7767afc8333
4
+ data.tar.gz: 6e0b0dff9b4edbad76724402b4cbe47de7fb6dbdc8a2b334c84c07b18a2486aa
5
5
  SHA512:
6
- metadata.gz: ff1a4850e14eb14761965adbcc50b89342e62f7e6fd0d5d6261556e06bd110064340e418cee9d5020ff481c1b4edd69fa93387dbc308b6ff24325c8fa2080ed0
7
- data.tar.gz: ab56eadd8fca161bef9914b8668949b428b08710e7c3c7a14c5e2bb640f9d358f7a781eae42bd9eabfff91eed2c3d8da11cc7adf6d4ab0e3ae8ff935caba77b0
6
+ metadata.gz: 05b8709efcc84b6047898fd05219ea97a4a0bffc1e77cef6a27e26197839ea092547b649c3c60176197749d219b96e18be9201bb64d1759192bf599f4ba51bc6
7
+ data.tar.gz: dc7304c5f2a4deb38a1b0b851b66415f23147ba2a78bb89a019ef37cdc510c7d22fb3ae4ff7fbd94ed849e68a2622ff3098014d55b6ed63aabdefbbb1a0086e1
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2020 Nikos Theodosis <n.theodosis@stoiximan.gr>
3
+ Copyright (c) 2020 Nikos Theodosis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -14,14 +14,44 @@ fastlane add_plugin discord_notifier
14
14
 
15
15
  Discord Notifier
16
16
 
17
- **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
17
+ `discord_notifier` posts a message in a discord channel defined by a webhook created for your discord server.
18
+
19
+ ## Usage
20
+
21
+ To get started, first, create a webhook in your Discord server. You can find detailed instructions [here](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks). You will need the webhook url in each call to successfully post a message in your channel.
22
+
23
+ ```ruby
24
+ discord_notifier(
25
+ webhook_url:"<discord webhook url>",
26
+ title: "<a title>",
27
+ description: "<a description>",
28
+ success: "<true/false>", # Optional - Default is true
29
+ color: "FFFFF", # Optional
30
+ thumbnail_url:"<thumbnail url>", # Optional
31
+ image_url:"<image url>" # Optional
32
+ )
33
+ ```
34
+
35
+ ## Keys
36
+
37
+ | Key | Description | Optional
38
+ | --- | --- | ---|
39
+ | webhook_url | Discord webhook url | false
40
+ | title | Message title | false
41
+ | description | Message description | false
42
+ | thumbnail_url | Thumbnail url | true
43
+ | image_url | Message image url | true
44
+ | success | Show file differences that haven't been staged | true
45
+ | color | The color defined will be attributed to the message sidebar. The sidebar by default uses #4BB543 if `success` is set to true and #CC0000 if set to false. If color is set, it overrides the default color described before. | true
46
+ | gravatar_email | If set, then the author's image will be replaced by the resolved gravatar. If not and the next 3 keys are set, the author's image will be set as the user's discord avatar | true
47
+ | bot_token | Token of bot assigned to discord server | true
48
+ | client_id | Client id retrieved upon bot creation | true
49
+ | discord_user_id | User id of the discord user | true
18
50
 
19
51
  ## Example
20
52
 
21
53
  Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
54
 
23
- **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
24
-
25
55
  ## Run tests for this plugin
26
56
 
27
57
  To run both the tests, and code style validation, run
@@ -2,6 +2,7 @@ require 'fastlane/action'
2
2
  require_relative '../helper/discord_notifier_helper'
3
3
  require 'discordrb/webhooks'
4
4
 
5
+
5
6
  module Fastlane
6
7
  module Actions
7
8
  class DiscordNotifierAction < Action
@@ -14,6 +15,22 @@ module Fastlane
14
15
  unless params[:color].nil? || params[:color] == 0
15
16
  color = params[:color]
16
17
  end
18
+
19
+ begin
20
+ user = Helper::DiscordUserHelper.findUser(params[:bot_token], params[:client_id], params[:discord_user_id])
21
+ discord_avatar = user.avatar_url
22
+ rescue => ex
23
+ UI.important('Fetching user data failed. Continuing anyway...')
24
+ end
25
+
26
+ author_name = ENV['USER']
27
+ unless user.nil?
28
+ author_name = user.name
29
+ end
30
+
31
+ unless params[:gravatar_email].nil? || params[:gravatar_email].empty?
32
+ discord_avatar = Helper::DiscordUserHelper.gravatarImageUrl(params[:gravatar_email])
33
+ end
17
34
 
18
35
  client = Discordrb::Webhooks::Client.new(url: params[:webhook_url])
19
36
  client.execute do |builder|
@@ -27,7 +44,8 @@ module Fastlane
27
44
  url: params[:image_url]
28
45
  )
29
46
  embed.author = Discordrb::Webhooks::EmbedAuthor.new(
30
- name: params[:author]
47
+ name: author_name,
48
+ icon_url: discord_avatar
31
49
  )
32
50
  embed.colour = color
33
51
  embed.timestamp = Time.now
@@ -81,11 +99,6 @@ module Fastlane
81
99
  optional: true,
82
100
  type: String
83
101
  ),
84
- FastlaneCore::ConfigItem.new(
85
- key: :author,
86
- optional: true,
87
- type: String
88
- ),
89
102
  FastlaneCore::ConfigItem.new(
90
103
  key: :success,
91
104
  optional: true,
@@ -96,6 +109,29 @@ module Fastlane
96
109
  key: :color,
97
110
  optional: true,
98
111
  type: String
112
+ ),
113
+ FastlaneCore::ConfigItem.new(
114
+ key: :gravatar_email,
115
+ optional: true,
116
+ type: String
117
+ ),
118
+ FastlaneCore::ConfigItem.new(
119
+ key: :bot_token,
120
+ env_name: "DISCORD_BOT_TOKEN",
121
+ optional: true,
122
+ type: String
123
+ ),
124
+ FastlaneCore::ConfigItem.new(
125
+ key: :client_id,
126
+ env_name: "DISCORD_CLIENT_ID",
127
+ optional: true,
128
+ type: String
129
+ ),
130
+ FastlaneCore::ConfigItem.new(
131
+ key: :discord_user_id,
132
+ env_name: "DISCORD_USER_ID",
133
+ optional: true,
134
+ type: String
99
135
  )
100
136
  ]
101
137
  end
@@ -1,4 +1,6 @@
1
1
  require 'fastlane_core/ui/ui'
2
+ require 'digest/md5'
3
+ require 'discordrb'
2
4
 
3
5
  module Fastlane
4
6
  UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
@@ -12,5 +14,28 @@ module Fastlane
12
14
  UI.message("Hello from the discord_notifier plugin helper!")
13
15
  end
14
16
  end
17
+
18
+ class DiscordUserHelper
19
+
20
+ def self.gravatarImageUrl(email)
21
+ email_address = ENV["FASTLANE_USER"].downcase
22
+ # create the md5 hash
23
+ hash = Digest::MD5.hexdigest(email)
24
+ # compile URL which can be used in <img src="RIGHT_HERE"...
25
+ image_src = "https://www.gravatar.com/avatar/#{hash}"
26
+
27
+ return image_src
28
+ end
29
+
30
+ def self.findUser(bot_token, client_id, user_id)
31
+ bot = Discordrb::Bot.new(
32
+ token: bot_token,
33
+ client_id: client_id
34
+ )
35
+ user = bot.user(user)
36
+
37
+ return user
38
+ end
39
+ end
15
40
  end
16
41
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module DiscordNotifier
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-discord_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikos Theodosis
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.145.0
139
139
  description:
140
- email: n.theodosis@stoiximan.gr
140
+ email: nikolas.theodosis@gmail.com
141
141
  executables: []
142
142
  extensions: []
143
143
  extra_rdoc_files: []