slackup 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a4dedeb8b780ba10d0d0b0aaec15408778b6ff7
4
- data.tar.gz: 29cec35036d341b5e8a517cfcc478ca2d59faa92
3
+ metadata.gz: b2a6ccd804fcb8f4b965e9a95e71fc893d3eb263
4
+ data.tar.gz: be9b759ec58de1e56ed08722e9cbfbb963a0e658
5
5
  SHA512:
6
- metadata.gz: 678224011c1df666ba67826313c457fd471b2bdc4691fcc495984f8eea78990283adee62d881f1424beec509958169c4747b0bfbff429e88323d075900698b8d
7
- data.tar.gz: f4ced7657011c11dd89310e719d8cd5c40773f846c0a0d969ce9689eb4228cdf4b226a380c5b8908f44fc4d1cad8a8694a4f9fb4da50e07d568d9be9a910f178
6
+ metadata.gz: 8286cfb800e9349830e4ebd2b219c521997707cfd7e7e0dbbb10e251e170e56348d0ffc882514e8608206840e0e0390d2875769a52f20a516a76456e10c69d11
7
+ data.tar.gz: 36307a23aff28e4927e5b74e507c0940685e557d41051766842246bd776411ac86a62761eb6d7fc0b2974227cfffb96f94fb4ce69ded2cc59b84d44c7d9dbf61
data/README.md CHANGED
@@ -20,6 +20,11 @@ where each team config is a dictionary (hash) as below:
20
20
  | name (required) | the team name. e.g. `some-team` in `some-team.slackup.com`. Is used as backup directory name for the team.
21
21
  | nickname (optional) | a nickname. When present, overrides `name` as the backup directory name for the team.
22
22
  | token (required) | https://api.slack.com/custom-integrations/legacy-tokens
23
+ | channels (optional) | array of whitelisted channels to include. Default is to include all
24
+ | groups (optional) | array of whitelisted groups to include. Default is to include all
25
+ | users (optional) | boolean whether to write out users
26
+ | stars (optional) | boolean whether to write out stars
27
+ | ims (optional) | boolean whether to write out ims
23
28
 
24
29
  e.g.
25
30
 
@@ -32,6 +37,14 @@ slack_teams.yml
32
37
  - name: another-team
33
38
  nickname: ateam
34
39
  token: xxxp-different-token
40
+ channels:
41
+ - general
42
+ # - random
43
+ groups:
44
+ - core-maintainers
45
+ users: true
46
+ stars: false
47
+ ims: true
35
48
  ```
36
49
 
37
50
  slack_teams.json
@@ -46,10 +46,7 @@ class Slackup
46
46
  def self.backup(team_config = team_config())
47
47
  team_config.each do |config|
48
48
  fork do
49
- name = config.fetch("nickname") { config.fetch("name") }
50
- token = config.fetch("token")
51
- client = configure_client(token)
52
- new(name, client).execute
49
+ new(config).execute
53
50
  end
54
51
  end
55
52
  p Process.waitall
@@ -57,9 +54,10 @@ class Slackup
57
54
 
58
55
  attr_reader :name, :client
59
56
  alias dirname name
60
- def initialize(name, client)
61
- @name = name
62
- @client = client
57
+ def initialize(config, client=nil)
58
+ @config = config
59
+ @name = config.fetch("nickname") { config.fetch("name") }
60
+ @client = client || configure_client
63
61
  FileUtils.mkdir_p(name)
64
62
  end
65
63
 
@@ -69,14 +67,23 @@ class Slackup
69
67
 
70
68
  def write!
71
69
  Dir.chdir(dirname) do
72
- Channels.new(name, client).write!
73
- Groups.new(name, client).write!
74
- Stars.new(name, client).write!
70
+ Channels.new(config, client).write!
71
+ Groups.new(config, client).write!
72
+ Stars.new(config, client).write!
75
73
  user_client.write!
76
- Ims.new(name, client).write!
74
+ Ims.new(config, client).write!
77
75
  end
78
76
  end
79
77
 
78
+ def configure_client
79
+ token = config.fetch("token")
80
+ self.class.configure_client(token)
81
+ end
82
+
83
+ protected
84
+
85
+ attr_reader :config
86
+
80
87
  private
81
88
 
82
89
  def authorize!
@@ -122,7 +129,7 @@ class Slackup
122
129
  end
123
130
 
124
131
  def user_client
125
- @user_client ||= Users.new(name, client)
132
+ @user_client ||= Users.new(config, client)
126
133
  end
127
134
 
128
135
  def users
@@ -5,8 +5,28 @@ class Slackup::Channels < Slackup
5
5
  end
6
6
  alias channels list
7
7
 
8
+ def configured_channels
9
+ @configured_channels ||= config.fetch("channels", [])
10
+ end
11
+
12
+ def write_channel?(channel)
13
+ whitelisted_channel = channel["name"] if configured_channels.empty?
14
+ whitelisted_channel ||= configured_channels.find do |channel_name|
15
+ channel["name_normalized"] == channel_name or
16
+ channel["name"] == channel_name
17
+ end
18
+ if whitelisted_channel
19
+ p [name, :channels, "Writing #{whitelisted_channel}"]
20
+ true
21
+ else
22
+ p [name, :channels, "Skipping #{channel["name"]}"]
23
+ false
24
+ end
25
+ end
26
+
8
27
  def write!
9
28
  channels.each do |channel|
29
+ next unless write_channel?(channel)
10
30
  write_messages(channel)
11
31
  end
12
32
  end
@@ -30,9 +30,28 @@ class Slackup::Groups < Slackup
30
30
  end
31
31
  alias groups list
32
32
 
33
+ def configured_groups
34
+ @configured_groups ||= config.fetch("groups", [])
35
+ end
36
+
37
+ def write_group?(group)
38
+ whitelisted_group = group["name"] if configured_groups.empty?
39
+ whitelisted_group ||= @configured_groups.find do |group_name|
40
+ group["name"] == group_name
41
+ end
42
+ if whitelisted_group
43
+ p [name, :groups, "Writing #{whitelisted_group}"]
44
+ true
45
+ else
46
+ p [name, :groups, "Skipping #{group["name"]}"]
47
+ false
48
+ end
49
+ end
50
+
33
51
  def write!
34
52
  Dir.chdir(groups_dir) do
35
53
  groups.each do |group|
54
+ next unless write_group?(group)
36
55
  write_messages(group)
37
56
  end
38
57
  end
@@ -17,9 +17,21 @@ class Slackup::Ims < Slackup
17
17
  end
18
18
  alias ims list
19
19
 
20
+ def write_ims?
21
+ if config.fetch("ims", true)
22
+ p [name, :ims, "Writing"]
23
+ true
24
+ else
25
+ p [name, :ims, "Skipping"]
26
+ false
27
+ end
28
+ end
29
+
20
30
  def write!
31
+ return unless write_ims?
21
32
  Dir.chdir(ims_dir) do
22
33
  ims.each do |im|
34
+ # p [:ims, im.user, format_username(im.user)]
23
35
  write_messages(im)
24
36
  end
25
37
  end
@@ -5,7 +5,18 @@ class Slackup::Stars < Slackup
5
5
  end
6
6
  alias stars list
7
7
 
8
+ def write_stars?
9
+ if config.fetch("stars", true)
10
+ p [name, :stars, "Writing"]
11
+ true
12
+ else
13
+ p [name, :stars, "Skipping"]
14
+ false
15
+ end
16
+ end
17
+
8
18
  def write!
19
+ return unless write_stars?
9
20
  with_messages "stars", list do |messages|
10
21
  File.open(backup_filename("stars"), "w") do |f|
11
22
  f.write(serialize(messages))
@@ -53,7 +53,18 @@ class Slackup::Users < Slackup
53
53
  end
54
54
  alias users list
55
55
 
56
+ def write_users?
57
+ if config.fetch("users", true)
58
+ p [name, :users, "Writing"]
59
+ true
60
+ else
61
+ p [name, :users, "Skipping"]
62
+ false
63
+ end
64
+ end
65
+
56
66
  def write!
67
+ return unless write_users?
57
68
  File.open(backup_filename("users"), "w") do |f|
58
69
  f.write(serialize(users.map(&:to_hash)))
59
70
  end
@@ -1,3 +1,3 @@
1
1
  class Slackup
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Fleischer