Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#339] 0pdd Jira support #357

Merged
merged 17 commits into from
Jun 10, 2022
5 changes: 5 additions & 0 deletions 0pdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
'client_id' => '?',
'client_secret' => '?'
},
'jira' => {
'token' => '--the-token--',
'client_id' => '?',
'client_secret' => '?'
},
'sentry' => '',
's3' => {
'region' => '?',
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

source 'https://rubygems.org'

gem 'activesupport', '6.1.5'
gem 'atlassian-jwt', '~> 0.2.1'
gem 'aws-sdk-dynamodb', '1.59.0'
gem 'aws-sdk-s3', '1.90.0'
gem 'codecov', '0.5.1'
gem 'crack', '0.4.3'
gem 'gitlab', '4.17.0'
gem 'glogin', '0.7.0'
gem 'haml', '5.2.1'
gem 'jira-ruby', '2.2.0'
gem 'mail', '2.7.1'
gem 'mocha', '1.11.2', require: false
gem 'nokogiri', '1.13.6'
Expand Down
66 changes: 47 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
atlassian-jwt (0.2.1)
jwt (~> 2.1)
aws-eventstream (1.2.0)
aws-partitions (1.537.0)
aws-sdk-core (3.124.0)
aws-partitions (1.595.0)
aws-sdk-core (3.131.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
jmespath (~> 1, >= 1.6.1)
aws-sdk-dynamodb (1.59.0)
aws-sdk-core (~> 3, >= 3.112.0)
aws-sigv4 (~> 1.1)
aws-sdk-kms (1.52.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sdk-kms (1.57.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.90.0)
aws-sdk-core (~> 3, >= 3.112.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.4.0)
aws-sigv4 (1.5.0)
aws-eventstream (~> 1, >= 1.0.2)
base58 (0.2.3)
codecov (0.5.1)
simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.1.9)
concurrent-ruby (1.1.10)
crack (0.4.3)
safe_yaml (~> 1.0.0)
differ (0.1.2)
docile (1.4.0)
faraday (1.8.0)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
ffi (1.15.4)
faraday-retry (1.0.3)
ffi (1.15.5)
gitlab (4.17.0)
httparty (~> 0.18)
terminal-table (~> 1.5, >= 1.5.1)
Expand All @@ -62,15 +74,24 @@ GEM
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
jira-ruby (2.2.0)
activesupport
atlassian-jwt
multipart-post
oauth (~> 0.5, >= 0.5.0)
jmespath (1.6.1)
jwt (2.3.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
mocha (1.11.2)
multi_json (1.15.0)
multi_xml (0.6.0)
Expand All @@ -82,27 +103,28 @@ GEM
racc (~> 1.4)
nokogiri (1.13.6-x86_64-darwin)
racc (~> 1.4)
oauth (0.5.10)
octokit (4.20.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.21.0)
parser (3.0.3.1)
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
pdd (0.20.6)
nokogiri (~> 1.10)
rainbow (~> 3.0)
slop (~> 4.6)
power_assert (2.0.1)
public_suffix (4.0.6)
public_suffix (4.0.7)
racc (1.6.0)
rack (2.2.3.1)
rack-protection (2.2.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rainbow (3.0.0)
rainbow (3.1.1)
rake (13.0.3)
rb-fsevent (0.11.0)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
rubocop (0.69.0)
Expand Down Expand Up @@ -133,7 +155,7 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
simplecov_json_formatter (0.1.4)
sinatra (2.2.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -145,7 +167,7 @@ GEM
rack-protection (= 2.2.0)
sinatra (= 2.2.0)
tilt (~> 2.0)
slop (4.9.1)
slop (4.9.2)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -155,25 +177,31 @@ GEM
test-unit (3.4.0)
power_assert
tilt (2.0.10)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.6.1)
xcop (0.6.2)
differ (~> 0.1.2)
nokogiri (~> 1.10)
rainbow (~> 3.0)
slop (~> 4.4)
zeitwerk (2.5.4)

PLATFORMS
ruby
x86_64-darwin-19

DEPENDENCIES
activesupport (= 6.1.5)
atlassian-jwt (~> 0.2.1)
aws-sdk-dynamodb (= 1.59.0)
aws-sdk-s3 (= 1.90.0)
codecov (= 0.5.1)
crack (= 0.4.3)
gitlab (= 4.17.0)
glogin (= 0.7.0)
haml (= 5.2.1)
jira-ruby (= 2.2.0)
mail (= 2.7.1)
mocha (= 1.11.2)
nokogiri (= 1.13.6)
Expand Down
55 changes: 55 additions & 0 deletions objects/clients/jira.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2016-2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'rubygems'
require 'jira-ruby'

#
# Jira client
# API: https://github.com/sumoheavy/jira-ruby
#
class JiraClient
def initialize(config = {})
@config = config
end

def client
client = if @config['testing']
puts 'testing...'
# require_relative '../../test/fake_jira'
# FakeJira.new
else
username = @config['jira']['username'] if @config['jira']
token = @config['jira']['token'] if @config['jira']
options = {
username: username,
password: token,
site: 'http://localhost:8080/', # or 'https://<your_subdomain>.atlassian.net/' # often blank
auth_type: :basic,
read_timeout: 120
}
JIRA::Client.new(options)
end
TracePoint.new(:call) do |tp|
puts "#{tp.defined_class}##{tp.method_id}()" if tp.defined_class == client.class
end.enable
client
end
end
17 changes: 17 additions & 0 deletions objects/templates/jira_tickets_body.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The puzzle `#{puzzle.xpath('id')[0].text}` |
from ##{puzzle.xpath('ticket')[0].text} has to be resolved: |
\
#{url}
\
The puzzle was created by #{puzzle.xpath('author')[0].text} on |
#{Time.parse(puzzle.xpath('time')[0].text).strftime('%d-%b-%y')}. |
\
#{MaybeText.new("Estimate: #{puzzle.xpath('estimate')[0].text} minutes, ", puzzle.xpath('estimate')[0].text, '0')} |
#{MaybeText.new("role: #{puzzle.xpath('role')[0].text}.", puzzle.xpath('role')[0].text, 'IMP')} |
\
If you have any technical questions, don't ask me, |
submit new tickets instead. The task will be \"done\" when |
the problem is fixed and the text of the puzzle is |
_removed_ from the source code. Here is more about |
[PDD](http://www.yegor256.com/2009/03/04/pdd.html) and |
[about me](http://www.yegor256.com/2017/04/05/pdd-in-action.html). |
2 changes: 1 addition & 1 deletion objects/tickets/milestone_tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def submit(puzzle)
`#{parent[:milestone][:title]}` from issue ##{num}."
)
end
rescue Octokit::Error, Gitlab::Error::Error => e
rescue Octokit::Error, Gitlab::Error::Error, JIRA::Error::Error => e
@vcs.add_comment(
submitted[:number],
"For some reason I wasn't able to set milestone \
Expand Down
4 changes: 2 additions & 2 deletions objects/tickets/tagged_tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def submit(puzzle)
begin
needed.each { |t| @vcs.add_label(t, 'F74219') }
@vcs.add_labels_to_an_issue(issue_id, tags)
rescue Octokit::Error, Gitlab::Error::Error => e
rescue Octokit::Error, Gitlab::Error::Error, JIRA::Error::Error => e
@vcs.add_comment(
issue_id,
"I can't create #{@vcs.name} labels `#{needed.join('`, `')}`. \
Expand All @@ -53,7 +53,7 @@ def submit(puzzle)
[list of collaborators](#{@vcs.collaborators_link}):\
\n\n```#{e.class.name}\n#{e.message}\n#{e.backtrace.join("\n")}\n```"
)
rescue Octokit::NotFound, Gitlab::Error::NotFound => e
rescue Octokit::NotFound, Gitlab::Error::NotFound, JIRA::Error::NotFound => e
@vcs.add_comment(
issue_id,
"For some reason I wasn't able to add #{@vcs.name} labels \
Expand Down
2 changes: 1 addition & 1 deletion objects/tickets/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def notify(issue, message)
issue,
"@#{@vcs.issue(issue)[:author][:username]} #{message}"
)
rescue Octokit::NotFound, Gitlab::NotFound => e
rescue Octokit::NotFound, Gitlab::NotFound, JIRA::NotFound => e
puts "The issue most probably is not found, can't comment: #{e.message}"
end

Expand Down
2 changes: 1 addition & 1 deletion objects/vcs/github.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016-2021 Yegor Bugayenko
# Copyright (c) 2016-2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
Expand Down
Loading