telegram-scrum-bot 0.0.2 → 0.0.3

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: a4ae321299b4e891424d806292ab0ff5379f3d1049e0b1b924beacf81c66f684
4
- data.tar.gz: 4ba69fc7910ba8e4c664f60e1559c4d7fd55e812ac8f308c7bf0227350181bd5
3
+ metadata.gz: 55d492159378ef10e11e36f11e618f8763ec3af1a51ea2774f85b3ad74a82584
4
+ data.tar.gz: 1ca6b9b4b58995ea9027fffef2e8754bfe340a2e8808385b05b4c56b1fe55c41
5
5
  SHA512:
6
- metadata.gz: a9d6b5ce93a5b0aad3ad398bd268f85bfe5e3b3326bb95029cf0eb8520ff4c5311e044c09e171c57b0808fb5fd6e21a134f4691741415bb33195f767e81d7ef4
7
- data.tar.gz: 832857d9617c601b6c48849ae32778cca8c042dd6539df04cfca39a81ab85d44337269276fd14d518776fe00c3402f7f057ebe48012cfaf8d4780aa63d14f7c8
6
+ metadata.gz: d4e0be2e9d9feef0f9008b5f36a019f998cb1624357c83823b7882c53b900ac7fd45a9a409a7fe57b776ecf65cc6a2fd67016317028104adf1b91c1c0472c4e6
7
+ data.tar.gz: a9cee0655c365abd6d7d2f0ca51eb443ca87ce56f5907783f4cc0404c9deb60b5378759247394922b5d48a88e656215c1ba5543dcbe3dc67ba600531ff22b6f3
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  ruby '2.5.0'
4
4
 
5
+ gem 'httparty', '~> 0.16.2'
5
6
  gem 'rspec', '~> 3.8'
6
7
  gem 'telegram_bot', '~> 0.0.8'
7
- gem 'github_api', '~> 0.18.2'
8
8
  gem 'ruby-trello', '~> 2.1'
data/Gemfile.lock CHANGED
@@ -24,39 +24,22 @@ GEM
24
24
  unf (>= 0.0.5, < 1.0.0)
25
25
  equalizer (0.0.11)
26
26
  excon (0.62.0)
27
- faraday (0.12.2)
28
- multipart-post (>= 1.2, < 3)
29
- github_api (0.18.2)
30
- addressable (~> 2.4)
31
- descendants_tracker (~> 0.0.4)
32
- faraday (~> 0.8)
33
- hashie (~> 3.5, >= 3.5.2)
34
- oauth2 (~> 1.0)
35
- hashie (3.6.0)
36
27
  http-cookie (1.0.3)
37
28
  domain_name (~> 0.5)
29
+ httparty (0.16.2)
30
+ multi_xml (>= 0.5.2)
38
31
  i18n (1.1.0)
39
32
  concurrent-ruby (~> 1.0)
40
33
  ice_nine (0.11.2)
41
34
  json (2.1.0)
42
- jwt (1.5.6)
43
35
  mime-types (3.2.2)
44
36
  mime-types-data (~> 3.2015)
45
37
  mime-types-data (3.2018.0812)
46
38
  minitest (5.11.3)
47
- multi_json (1.13.1)
48
39
  multi_xml (0.6.0)
49
- multipart-post (2.0.0)
50
40
  netrc (0.11.0)
51
41
  oauth (0.5.4)
52
- oauth2 (1.4.0)
53
- faraday (>= 0.8, < 0.13)
54
- jwt (~> 1.0)
55
- multi_json (~> 1.3)
56
- multi_xml (~> 0.5)
57
- rack (>= 1.2, < 3)
58
42
  public_suffix (3.0.3)
59
- rack (2.0.5)
60
43
  rest-client (2.0.2)
61
44
  http-cookie (>= 1.0.2, < 2.0)
62
45
  mime-types (>= 1.16, < 4.0)
@@ -99,7 +82,7 @@ PLATFORMS
99
82
  ruby
100
83
 
101
84
  DEPENDENCIES
102
- github_api (~> 0.18.2)
85
+ httparty (~> 0.16.2)
103
86
  rspec (~> 3.8)
104
87
  ruby-trello (~> 2.1)
105
88
  telegram_bot (~> 0.0.8)
Binary file
@@ -2,7 +2,7 @@ require 'yaml'
2
2
  require 'telegram_bot'
3
3
  require 'logger'
4
4
 
5
- require_relative 'github'
5
+ require_relative 'github_wrapper'
6
6
  require_relative 'trello'
7
7
 
8
8
  module TelegramBot
@@ -122,16 +122,23 @@ module TelegramBot
122
122
  elsif @github_repository.empty?
123
123
  message = "Debe indicar el repositorio de Github, puede hacerlo con /setgithubrepository"
124
124
  else
125
- github = GitHubConnector.new(username: @github_username,
126
- repository: @github_repository)
127
- message = "Incidentes registrados en: @#{github.username}/#{github.repository}:\n\n"
128
- github.get_issues.each do |issue|
129
- if issue.instance_of?(Issue)
130
- message << " issue ##{issue.number}\n #{issue.title}\n"
131
- message << " -----\n\n"
132
- else
133
- message << issue
125
+ begin
126
+ github = GitHubWrapper::Repository.find(username: @github_username,
127
+ repository: @github_repository)
128
+
129
+ message = "Incidentes registrados en: @#{github.username}/#{github.repository}:\n\n"
130
+ github.get_issues(state: 'open').each do |issue|
131
+ if issue.instance_of?(GitHubWrapper::Issue)
132
+ message << " issue ##{issue.number}\n #{issue.title}\n"
133
+ message << " -----\n\n"
134
+ else
135
+ message << issue
136
+ end
134
137
  end
138
+ rescue TypeError => e
139
+ message << "User/Repository not found: #{e}"
140
+ rescue StandardError => e
141
+ message << "Error: #{e}"
135
142
  end
136
143
  end
137
144
  {
@@ -147,7 +154,8 @@ module TelegramBot
147
154
  elsif github_repository.empty?
148
155
  message = "Debe indicar el repositorio de Github, puede hacerlo con /setgithubrepository"
149
156
  else
150
- trello = TelegramBot::TrelloConnector.new(username: @github_username, repository: @github_repository)
157
+ trello = TelegramBot::TrelloConnector.new(username: @github_username,
158
+ repository: @github_repository)
151
159
  message = trello.show_statistics
152
160
  end
153
161
  {
@@ -0,0 +1,105 @@
1
+ module TelegramBot
2
+ module GitHubWrapper
3
+ require 'httparty'
4
+ class Repository
5
+ include HTTParty
6
+
7
+ base_uri("https://api.github.com/repos")
8
+ @@headers = {
9
+ 'User-Agent': 'telegram-scrum-bot'
10
+ }
11
+
12
+ attr_reader :username, :repository, :description, :private_repo, :issues
13
+
14
+ def initialize(username:, repository:, description:, private_repo:)
15
+ @username = username
16
+ @repository = repository
17
+ @description = description
18
+ @private_repo = private_repo
19
+ @issues = []
20
+ end
21
+
22
+ alias_method :private?, :private_repo
23
+
24
+ # Returns the issues from a public repository
25
+ def get_issues(state: 'all', sort: "created", order_direction: 'asc')
26
+ query = {
27
+ "state" => state,
28
+ "sort" => sort,
29
+ "direction" => order_direction
30
+ }
31
+
32
+ response = self.class.get("/#{@username}/#{@repository}/issues",
33
+ headers: @@headers,
34
+ query: query)
35
+
36
+ if response.success?
37
+ JSON.parse(response.body).each do |issue|
38
+ @issues << Issue.new(id: issue.fetch('id', ''),
39
+ number: issue.fetch('number', ''),
40
+ title: issue.fetch('title', ''),
41
+ body: issue.fetch('body', ''),
42
+ state: issue.fetch('state', ''),
43
+ url: issue.fetch('url', ''))
44
+ end
45
+ else
46
+ raise response.response
47
+ end
48
+ @issues
49
+ end
50
+
51
+ # Find a particular repository
52
+ def self.find(username:, repository:)
53
+ response = get("/#{username}/#{repository}",
54
+ headers: @@headers)
55
+
56
+ if response.success?
57
+ self.new(username: username,
58
+ repository: repository,
59
+ description: response.fetch("description", ""),
60
+ private_repo: response.fetch("private", ""))
61
+ else
62
+ raise response.response
63
+ end
64
+ end
65
+ end
66
+
67
+ class Issue
68
+ attr_accessor :id, :number, :title, :body, :state, :url
69
+
70
+ def initialize(id:, number:, title:, body:, state:, url:)
71
+ self.id = id
72
+ self.number = number
73
+ self.title = title
74
+ self.body = body
75
+ self.state = state
76
+ self.url = url
77
+ end
78
+
79
+ def to_s
80
+ "issue: #{id}\n" +
81
+ "number: #{number}\n" +
82
+ "title: #{title}\n" +
83
+ "body: #{body}\n" +
84
+ "state: #{state}\n" +
85
+ "url: #{url}\n"
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ if __FILE__ == $0
92
+ begin
93
+ github = TelegramBot::GitHubWrapper::Repository.find(username: 'hackvan', repository: 'telegram-bot')
94
+ puts "repository: #{github.username}/#{github.repository}"
95
+ puts "private repo: #{github.private?}"
96
+ github.get_issues(state: "open").each do |issue|
97
+ puts issue
98
+ puts "-" * 80
99
+ end
100
+ rescue TypeError => e
101
+ puts "User/Repository not found: #{e}"
102
+ rescue StandardError => e
103
+ puts "Error: #{e}"
104
+ end
105
+ end
@@ -1,16 +1,16 @@
1
1
  module TelegramBot
2
2
  require 'trello'
3
3
 
4
- @@trello_developer_public_key = ''
5
- @@trello_member_token = ''
4
+ @@trello_dev_public_key = ''
5
+ @@trello_member_token = ''
6
6
 
7
7
  def self.set_trello_tokens(key, token)
8
- @@trello_developer_public_key = key
9
- @@trello_member_token = token
8
+ @@trello_dev_public_key = key
9
+ @@trello_member_token = token
10
10
 
11
11
  Trello.configure do |config|
12
- config.developer_public_key = @@trello_developer_public_key
13
- config.member_token = @@trello_member_token
12
+ config.developer_public_key = @@trello_dev_public_key
13
+ config.member_token = @@trello_member_token
14
14
  end
15
15
  end
16
16
 
@@ -27,10 +27,9 @@ module TelegramBot
27
27
  @board_name = @github_repository.split(/[-_]/i).map(&:capitalize).join(' ')
28
28
 
29
29
  @board = find_or_create_board_by_name
30
- create_scrum_lists!(@board)
31
- close_default_lists!(@board)
32
- # archive_existing_cards!
33
- populate_issues_cards!
30
+ create_scrum_lists(@board)
31
+ close_default_lists(@board)
32
+ populate_issues_cards
34
33
  end
35
34
 
36
35
  def show_statistics
@@ -58,7 +57,7 @@ module TelegramBot
58
57
  @board.lists.detect { |list| list.name =~ /backlog/i }
59
58
  end
60
59
 
61
- def create_scrum_lists!(board)
60
+ def create_scrum_lists(board)
62
61
  LIST_NAMES.reverse.each do |name, index|
63
62
  list = board.lists.detect { |list| list.name =~ /#{name}/i }
64
63
  unless list
@@ -69,7 +68,7 @@ module TelegramBot
69
68
  self
70
69
  end
71
70
 
72
- def close_default_lists!(board)
71
+ def close_default_lists(board)
73
72
  board.lists.each do |list|
74
73
  unless LIST_NAMES.include?(list.name)
75
74
  list.update_fields(closed: true)
@@ -78,23 +77,30 @@ module TelegramBot
78
77
  end
79
78
  end
80
79
 
81
- def archive_existing_cards!
80
+ def archive_existing_cards
82
81
  find_backlog_list.archive_all_cards
83
82
  end
84
83
 
85
- def populate_issues_cards!
84
+ def populate_issues_cards
86
85
  backlog_list = find_backlog_list
87
86
  if backlog_list
88
- github = GitHubConnector.new(username: @github_username, repository: @github_repository)
89
- github.get_issues.each do |issue|
90
- if issue.instance_of?(Issue)
91
- card = backlog_list.cards.detect { |c| c.name =~ /^##{issue.number}\s[-]/i }
87
+ begin
88
+ github = GitHubWrapper::Repository.find(username: @github_username,
89
+ repository: @github_repository)
90
+ github.get_issues(state: 'open').each do |issue|
91
+ if issue.instance_of?(GitHubWrapper::Issue)
92
+ card = backlog_list.cards.detect { |c| c.name =~ /^##{issue.number}\s[-]/i }
92
93
 
93
- unless card
94
- Trello::Card.create(name: "##{issue.number} - #{issue.title}", desc: issue.body, list_id: backlog_list.id)
95
- @statistics[:cards_created] += 1
94
+ unless card
95
+ Trello::Card.create(name: "##{issue.number} - #{issue.title}", desc: issue.body, list_id: backlog_list.id)
96
+ @statistics[:cards_created] += 1
97
+ end
96
98
  end
97
99
  end
100
+ rescue TypeError => e
101
+ puts "User/Repository not found: #{e}"
102
+ rescue StandardError => e
103
+ puts "Error: #{e}"
98
104
  end
99
105
  end
100
106
  self
@@ -104,7 +110,7 @@ end
104
110
 
105
111
  if __FILE__ == $0
106
112
  require 'yaml'
107
- require_relative 'github'
113
+ require_relative 'github_wrapper'
108
114
  config = YAML.load_file("./config/secrets.yml")
109
115
  TelegramBot.set_trello_tokens(config['trello']['key'], config['trello']['token'])
110
116
  trello = TelegramBot::TrelloConnector.new(username: 'hackvan', repository: 'telegram-bot')
@@ -1,3 +1,4 @@
1
1
  module TelegramBot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3".freeze
3
+ RELEASE_DATE = "2018-10-05".freeze
3
4
  end
@@ -4,7 +4,7 @@ require "telegram-bot/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'telegram-scrum-bot'
7
- spec.date = '2018-09-30'
7
+ spec.date = TelegramBot::RELEASE_DATE
8
8
  spec.version = TelegramBot::VERSION
9
9
  spec.authors = ["Diego Camacho"]
10
10
  spec.email = 'hackvan@gmail.com'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-scrum-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Camacho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-30 00:00:00.000000000 Z
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: telegram_bot
@@ -95,10 +95,10 @@ files:
95
95
  - bin/console
96
96
  - bin/setup
97
97
  - exe/telegram-scrum-bot
98
+ - icon-scrum-bot.jpg
98
99
  - lib/telegram-bot.rb
99
100
  - lib/telegram-bot/bot.rb
100
- - lib/telegram-bot/github.rb
101
- - lib/telegram-bot/issue.rb
101
+ - lib/telegram-bot/github_wrapper.rb
102
102
  - lib/telegram-bot/trello.rb
103
103
  - lib/telegram-bot/version.rb
104
104
  - telegram-scrum-bot.gemspec
@@ -1,45 +0,0 @@
1
- require 'github_api'
2
- require_relative 'issue'
3
-
4
- module TelegramBot
5
- class GitHubConnector
6
- attr_reader :github_object, :username, :repository, :issues_list
7
-
8
- def initialize(username:, repository:)
9
- @github_object = Github.new
10
- @username = username
11
- @repository = repository
12
- @issues_list = []
13
- end
14
-
15
- def get_issues(state: 'open', order_mode: 'asc')
16
- begin
17
- issues = @github_object.issues.list user: @username,
18
- repo: @repository,
19
- state: state,
20
- sort: 'created',
21
- direction: order_mode
22
- issues.each do |issue|
23
- @issues_list << Issue.new(id: issue.id,
24
- number: issue.number,
25
- title: issue.title,
26
- body: issue.body,
27
- state: issue.state,
28
- url: issue.url)
29
- end
30
- rescue Github::Error::NotFound => exception
31
- @issues_list << "Usuario/Repositorio no encontrado"
32
- end
33
- @issues_list
34
- end
35
- end
36
- end
37
-
38
- if __FILE__ == $0
39
- github = TelegramBot::GitHubConnector.new(username: 'hackvan', repository: 'telegram-bot')
40
- github.get_issues(state: 'all').each do |issue|
41
- puts issue
42
- puts "-" * 80
43
- end
44
- end
45
-
@@ -1,23 +0,0 @@
1
- module TelegramBot
2
- class Issue
3
- attr_accessor :id, :number, :title, :body, :state, :url
4
-
5
- def initialize(id:, number:, title:, body:, state:, url:)
6
- @id = id
7
- @number = number
8
- @title = title
9
- @body = body
10
- @state = state
11
- @url = url
12
- end
13
-
14
- def to_s
15
- "issue: #{@id}\n" +
16
- "number: #{@number}\n" +
17
- "title: #{@title}\n" +
18
- "body: #{@body}\n" +
19
- "state: #{@state}\n" +
20
- "url: #{@url}\n"
21
- end
22
- end
23
- end