remote-coffee-slack 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8cac3181a643cd6331c3f40df9fa674f5b5cf37f60ed9d333f3e27653868303a
4
+ data.tar.gz: a3ea3e71d1879ccd90d9cf79f2ecfa6970798864d5fcf867c64e12dbb9cae2f4
5
+ SHA512:
6
+ metadata.gz: e8c4414242cc5b851a009fb37e7a115d2d4e7095250204a07ddbffb6c9275a87c0feba2b3bb18203150272d9e090ede4343e0055484c8ac88b2651846e754928
7
+ data.tar.gz: 7f7df451900a7adc839e1fa3c8a11b019df664ca336c6b78417eb70069eab65630ad36977e1987094d0c0a08371e184e41826d22f31ad3ad632ebe7361a62253
@@ -0,0 +1,2 @@
1
+ SLACK_BOT_TOKEN = your_app_token
2
+ SLACK_CHANNEL = '#general'
@@ -0,0 +1,35 @@
1
+ name: CI
2
+ on:
3
+ pull_request:
4
+ branches: [ master ]
5
+ push:
6
+ branches: [ master ]
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby_version: [ '2.5', '2.6', '2.7' ]
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v2
16
+ - name: Setup ruby ${{ matrix.ruby_version }}
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby_version }}
20
+ - name: Setup cache key and directory for gems cache
21
+ uses: actions/cache@v1
22
+ with:
23
+ path: vendor/bundle
24
+ key: ${{ runner.os }}-gem-use-ruby-${{ matrix.ruby_version }}-${{ hashFiles('**/Gemfile.lock') }}
25
+ - name: Bundle install
26
+ run: |
27
+ gem install bundler
28
+ bundle config path vendor/bundle
29
+ bundle install --jobs 4 --retry 3
30
+ - name: Run tests
31
+ run: |
32
+ bundle exec rake test
33
+ env:
34
+ SLACK_BOT_TOKEN: TEST-TOKEN
35
+ SLACK_CHANNEL: '#general'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .env
11
+ .env.test
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.4
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at JuanCrg90@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in remote_coffee_slack.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+
8
+ group :test do
9
+ gem "minitest", "~> 5.0"
10
+ gem 'vcr'
11
+ gem 'webmock'
12
+ end
13
+
14
+ group :test, :development do
15
+ gem "pry"
16
+ gem 'dotenv', "~> 2.7.6"
17
+ end
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ remote-coffee-slack (0.1.0)
5
+ slack-ruby-client (~> 0.15.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ coderay (1.1.3)
13
+ crack (0.4.4)
14
+ dotenv (2.7.6)
15
+ faraday (1.0.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday_middleware (1.0.0)
18
+ faraday (~> 1.0)
19
+ gli (2.19.2)
20
+ hashdiff (1.0.1)
21
+ hashie (4.1.0)
22
+ method_source (1.0.0)
23
+ minitest (5.14.2)
24
+ multipart-post (2.1.1)
25
+ pry (0.13.1)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ public_suffix (4.0.6)
29
+ rake (12.3.3)
30
+ slack-ruby-client (0.15.1)
31
+ faraday (>= 1.0)
32
+ faraday_middleware
33
+ gli
34
+ hashie
35
+ websocket-driver
36
+ vcr (6.0.0)
37
+ webmock (3.9.1)
38
+ addressable (>= 2.3.6)
39
+ crack (>= 0.3.2)
40
+ hashdiff (>= 0.4.0, < 2.0.0)
41
+ websocket-driver (0.7.3)
42
+ websocket-extensions (>= 0.1.0)
43
+ websocket-extensions (0.1.5)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ dotenv (~> 2.7.6)
50
+ minitest (~> 5.0)
51
+ pry
52
+ rake (~> 12.0)
53
+ remote-coffee-slack!
54
+ vcr
55
+ webmock
56
+
57
+ BUNDLED WITH
58
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Juan Carlos Ruiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # RemoteCoffeeSlack
2
+ ![CI](https://github.com/Calzada-Code/remote-coffee-slack/workflows/CI/badge.svg)
3
+
4
+ A Ruby gem that helps you to create groups for a remote coffee in your Slack organization.
5
+
6
+ ![remote-cofee-slack](./remote-coffee-slack.png)
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'remote_coffee_slack'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install remote_coffee_slack
24
+
25
+
26
+ ## Usage
27
+
28
+ Create a new slack app in your slack workspace and add the following Bot Token Scopes:
29
+ `channels:read `, `chat:write`, `users:read`
30
+
31
+ Initalize the gem adding the following block:
32
+
33
+ ```ruby
34
+ RemoteCoffeeSlack.configure do |config|
35
+ config.slack_bot_token = your-Bot-User-OAuth-Access-Token
36
+ config.slack_channel = the-slack-channel-what-you-will-take-as-water-cooler
37
+ end
38
+ ```
39
+
40
+ In your Ruby application where you want to trigger the `RemoteCoffeeSlack` pairing event you should call
41
+
42
+ ```ruby
43
+ RemoteCoffeeSlack.notify_next_session
44
+ ```
45
+
46
+ This will action will perform the following steps:
47
+ - Get the users inside the configured channel.
48
+ - Create the groups for the next coffee session.
49
+ - Publish the list in the confifured channel.
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remote_coffee_slack. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Calzada-Code/remote-coffee-slack/blob/master/CODE_OF_CONDUCT.md).
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
65
+
66
+ ## Code of Conduct
67
+
68
+ Everyone interacting in the RemoteCoffeeSlack project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Calzada-Code/remote-coffee-slack/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'dotenv/load'
5
+ require "remote_coffee_slack"
6
+
7
+ RemoteCoffeeSlack.configure do |config|
8
+ config.slack_bot_token = ENV['SLACK_BOT_TOKEN']
9
+ config.slack_channel = ENV['SLACK_CHANNEL']
10
+ end
11
+
12
+ require "pry"
13
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require "remote_coffee_slack/version"
2
+
3
+ require "remote_coffee_slack/slack_client"
4
+ require "remote_coffee_slack/members"
5
+ require "remote_coffee_slack/session_notifier"
6
+
7
+ module RemoteCoffeeSlack
8
+ class << self
9
+ attr_accessor :config
10
+ attr_accessor :slack_client
11
+ end
12
+
13
+ def self.configure
14
+ self.config ||= Configuration.new
15
+ yield config
16
+ end
17
+
18
+ def self.slack_client
19
+ @slack_client ||= SlackClient.new.client
20
+ end
21
+
22
+ def self.select_coffee_mates
23
+ @select_coffee_mates ||= Members.select_coffee_mates(slack_client)
24
+ end
25
+
26
+ def self.notify_next_session
27
+ SessionNotifier.perform(slack_client, select_coffee_mates)
28
+ end
29
+
30
+ class Configuration
31
+ attr_accessor :slack_bot_token, :slack_channel
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ module RemoteCoffeeSlack
2
+ class Members
3
+ MATES_PER_GROUP = 2
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ @members = retrieve_channel_members
8
+ end
9
+
10
+ def self.select_coffee_mates(client)
11
+ new(client).select_coffee_mates
12
+ end
13
+
14
+ def select_coffee_mates
15
+ members_handlers.shuffle.each_slice(MATES_PER_GROUP).to_a
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :client, :members
21
+
22
+ def retrieve_channel_members
23
+ channel_members = []
24
+ params = {
25
+ channel: RemoteCoffeeSlack.config.slack_channel,
26
+ limit: 10,
27
+ sleep_interval: 5,
28
+ max_retries: 20
29
+ }
30
+
31
+ client.conversations_members(params) do |response|
32
+ channel_members.concat(response.members)
33
+ end
34
+
35
+ channel_members
36
+ end
37
+
38
+ def members_handlers
39
+ human_members.map do |member|
40
+ "@#{member}"
41
+ end
42
+ end
43
+
44
+ def human_members
45
+ members.reject do |member|
46
+ client.users_info(user: member).user.is_bot
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,36 @@
1
+ module RemoteCoffeeSlack
2
+ class SessionNotifier
3
+ def initialize(client, coffee_mates)
4
+ @client = client
5
+ @coffee_mates = coffee_mates
6
+ end
7
+
8
+ def perform
9
+ client.chat_postMessage(
10
+ channel: RemoteCoffeeSlack.config.slack_channel,
11
+ text: next_session_message,
12
+ as_user: true)
13
+ end
14
+
15
+ def self.perform(client, coffee_mates)
16
+ new(client, coffee_mates).perform
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :client, :coffee_mates
22
+
23
+ def next_session_message
24
+ <<-TEXT
25
+ The mates for the next coffee session are:
26
+ #{coffee_mates_formated}
27
+ TEXT
28
+ end
29
+
30
+ def coffee_mates_formated
31
+ coffee_mates.map do |mates|
32
+ "<#{mates.first}> and <#{mates.last}>\n"
33
+ end.join
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ require 'slack-ruby-client'
2
+
3
+ module RemoteCoffeeSlack
4
+ class SlackClient
5
+ attr_reader :client
6
+
7
+ def initialize
8
+ ::Slack.configure do |config|
9
+ config.token = RemoteCoffeeSlack.config.slack_bot_token
10
+ raise 'Missing API token' unless config.token
11
+ end
12
+
13
+ @client = Slack::Web::Client.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module RemoteCoffeeSlack
2
+ VERSION = "0.1.0"
3
+ end
Binary file
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/remote_coffee_slack/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "remote-coffee-slack"
5
+ spec.version = RemoteCoffeeSlack::VERSION
6
+ spec.authors = ["Juan Carlos Ruiz"]
7
+ spec.email = ["JuanCrg90@gmail.com"]
8
+
9
+ spec.summary = %q{Organize remote coffee pairs in your slack workspace.}
10
+ spec.description = %q{Organize remote coffee pairs in your slack workspace.}
11
+ spec.homepage = "https://calzadacode.dev/"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/Calzada-Code/remote-cofee-slack"
17
+ spec.metadata["changelog_uri"] = "https://github.com/Calzada-Code/remote-cofee-slack"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency 'slack-ruby-client', '~> 0.15.1'
29
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote-coffee-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Carlos Ruiz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-ruby-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.1
27
+ description: Organize remote coffee pairs in your slack workspace.
28
+ email:
29
+ - JuanCrg90@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".env.sample"
35
+ - ".github/workflows/ci.yml"
36
+ - ".gitignore"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - lib/remote_coffee_slack.rb
47
+ - lib/remote_coffee_slack/members.rb
48
+ - lib/remote_coffee_slack/session_notifier.rb
49
+ - lib/remote_coffee_slack/slack_client.rb
50
+ - lib/remote_coffee_slack/version.rb
51
+ - remote-coffee-slack.png
52
+ - remote_coffee_slack.gemspec
53
+ homepage: https://calzadacode.dev/
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://calzadacode.dev/
58
+ source_code_uri: https://github.com/Calzada-Code/remote-cofee-slack
59
+ changelog_uri: https://github.com/Calzada-Code/remote-cofee-slack
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Organize remote coffee pairs in your slack workspace.
79
+ test_files: []