rujira 0.1.4 → 0.1.6
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 +4 -4
- data/README.md +45 -19
- data/Rakefile +20 -2
- data/compose.yaml +1 -0
- data/lib/rujira/api/attachments.rb +9 -0
- data/lib/rujira/api/issue.rb +30 -16
- data/lib/rujira/api/project.rb +2 -1
- data/lib/rujira/api/search.rb +7 -3
- data/lib/rujira/api/server_info.rb +1 -1
- data/lib/rujira/connection.rb +1 -0
- data/lib/rujira/entity.rb +21 -4
- data/lib/rujira/tasks/jira.rb +64 -25
- data/lib/rujira/version.rb +1 -1
- data/lib/rujira.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c5b714472d56b23db8bfe6a5a96e60c3dfd6af7cb8176fbef27d839bc2ace3
|
4
|
+
data.tar.gz: 106ca92334c64b3129f4e66d8aaa570eaa4d09adcba9ac7dad1d4136d6c251a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae579ef0d21f37fb22002669d668ddf6f876a1940da8fd0e5cd6022f8458407913ea3ba398af98590daf75b8dcd4b4b783c0764c05081aef60e24a4db789450d
|
7
|
+
data.tar.gz: 19062bf410f45b08e1a1554743a7f179acb314d3e95a8a92c5d914b1147b64458797ea849da34c19e3867e6c726add88f23c810f186df2cd6f81c76794a1bb39
|
data/README.md
CHANGED
@@ -8,32 +8,58 @@
|
|
8
8
|
|
9
9
|
name = Rujira::Api::Myself.get.name
|
10
10
|
Rujira::Api::Project.get 'ITMG'
|
11
|
-
Rujira::Api::Issue.create
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
Rujira::Api::Issue.create do
|
12
|
+
data fields: {
|
13
|
+
project: { key: 'ITMG' },
|
14
|
+
summary: 'BOT: added a new feature.',
|
15
|
+
description: 'This task was generated by the bot when creating changes in the repository.',
|
16
|
+
issuetype: { name: 'Task' },
|
17
|
+
labels: ['bot'] }
|
18
|
+
params updateHistory: true
|
19
|
+
end
|
18
20
|
Rujira::Api::Issue.watchers 'ITMG-1', 'wilful'
|
19
21
|
Rujira::Api::Issue.get 'ITMG-1'
|
20
|
-
Rujira::Api::Search.get
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
result = Rujira::Api::Search.get do
|
23
|
+
data jql: 'project = ITMG and status IN ("To Do", "In Progress") ORDER BY issuekey',
|
24
|
+
maxResults: 10,
|
25
|
+
startAt: 0,
|
26
|
+
fields: ['id', 'key']
|
27
|
+
end
|
28
|
+
result.iter
|
29
|
+
Rujira::Api::Issue.comment 'ITMG-1' do
|
30
|
+
data body: 'Adding a new comment'
|
31
|
+
end
|
32
|
+
Rujira::Api::Issue.edit 'ITMG-1' do
|
33
|
+
data update: {
|
34
|
+
labels:[{add: 'rujira'},{remove: 'bot'}],
|
35
|
+
},
|
36
|
+
fields: {
|
37
|
+
assignee: { name: name },
|
38
|
+
summary: 'This is a shorthand for a set operation on the summary field'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
Rujira::Api::Issue.attachments 'ITMG-1', 'upload.png'
|
32
42
|
Rujira::Api::Issue.del 'ITMG-1'
|
33
43
|
|
44
|
+
## Rake tasks
|
45
|
+
|
46
|
+
require 'rujira/tasks/jira'
|
47
|
+
rake jira::whoami
|
48
|
+
rake jira:create -- '--project=ITMG' \
|
49
|
+
'--summary=The short summary information' \
|
50
|
+
'--description=The base description of task' \
|
51
|
+
'--issuetype=Task'
|
52
|
+
rake jira:search -- '-q project = ITMG'
|
53
|
+
|
34
54
|
## Testing
|
35
55
|
|
36
56
|
### Run the instance of jira
|
37
57
|
|
38
58
|
docker compose up -d
|
39
59
|
open http://localhost:8080
|
60
|
+
|
61
|
+
### Example with Curl
|
62
|
+
|
63
|
+
curl -H "Authorization: Bearer <JIRA_ACCESS_TOKEN>" 'http://localhost:8080/rest/api/2/search?expand=summary'
|
64
|
+
curl -D- -F "file=@upload.png" -X POST -H "X-Atlassian-Token: nocheck" \
|
65
|
+
-H "Authorization: Bearer <JIRA_ACCESS_TOKEN>" 'http://localhost:8080/rest/api/2/issue/ITMG-70/attachments'
|
data/Rakefile
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
7
|
+
require 'rujira'
|
8
|
+
require 'rujira/tasks/jira'
|
9
|
+
|
10
|
+
task default: %i[test]
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.libs << 'test'
|
14
|
+
t.test_files = FileList['test/test*.rb']
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
Rujira::Tasks::Jira.new
|
19
|
+
|
20
|
+
task :version do
|
21
|
+
puts Rujira::VERSION
|
22
|
+
end
|
data/compose.yaml
CHANGED
data/lib/rujira/api/issue.rb
CHANGED
@@ -5,56 +5,70 @@ module Rujira
|
|
5
5
|
# TODO
|
6
6
|
# https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/issue
|
7
7
|
class Issue < Item
|
8
|
-
def self.
|
8
|
+
def self.create(&block)
|
9
9
|
entity = Entity.build do
|
10
|
-
path
|
10
|
+
path 'issue'
|
11
|
+
method :POST
|
12
|
+
instance_eval(&block) if block_given?
|
11
13
|
end
|
12
14
|
new(entity.commit)
|
13
15
|
end
|
14
16
|
|
15
|
-
def self.
|
17
|
+
def self.get(id_or_key, &block)
|
16
18
|
entity = Entity.build do
|
17
19
|
path "issue/#{id_or_key}"
|
18
|
-
|
20
|
+
instance_eval(&block) if block_given?
|
19
21
|
end
|
20
|
-
entity.commit
|
22
|
+
new(entity.commit)
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.
|
25
|
+
def self.del(id_or_key, &block)
|
24
26
|
entity = Entity.build do
|
25
|
-
path
|
26
|
-
method :
|
27
|
-
|
27
|
+
path "issue/#{id_or_key}"
|
28
|
+
method :DELETE
|
29
|
+
instance_eval(&block) if block_given?
|
28
30
|
end
|
29
|
-
|
31
|
+
entity.commit
|
30
32
|
end
|
31
33
|
|
32
|
-
def self.edit(id_or_key,
|
34
|
+
def self.edit(id_or_key, &block)
|
33
35
|
entity = Entity.build do
|
34
36
|
path "issue/#{id_or_key}"
|
35
37
|
method :PUT
|
36
|
-
|
38
|
+
instance_eval(&block) if block_given?
|
37
39
|
end
|
38
40
|
new(entity.commit)
|
39
41
|
end
|
40
42
|
|
41
|
-
def self.comment(id_or_key,
|
43
|
+
def self.comment(id_or_key, &block)
|
42
44
|
entity = Entity.build do
|
43
45
|
path "issue/#{id_or_key}/comment"
|
44
46
|
method :POST
|
45
|
-
|
47
|
+
instance_eval(&block) if block_given?
|
46
48
|
end
|
47
49
|
Comment.new(entity.commit)
|
48
50
|
end
|
49
51
|
|
50
|
-
def self.watchers(id_or_key,
|
52
|
+
def self.watchers(id_or_key, &block)
|
51
53
|
entity = Entity.build do
|
52
54
|
path "issue/#{id_or_key}/watchers"
|
53
55
|
method :POST
|
54
|
-
|
56
|
+
instance_eval(&block) if block_given?
|
55
57
|
end
|
56
58
|
new(entity.commit)
|
57
59
|
end
|
60
|
+
|
61
|
+
def self.attachments(id_or_key, path, &block)
|
62
|
+
entity = Entity.build do
|
63
|
+
path "issue/#{id_or_key}/attachments"
|
64
|
+
method :POST
|
65
|
+
headers 'Content-Type': 'multipart/form-data', 'X-Atlassian-Token': 'nocheck',
|
66
|
+
'Transfer-Encoding': 'chunked', 'Content-Length': File.size(path).to_s
|
67
|
+
data file: Faraday::Multipart::FilePart.new(path, 'multipart/form-data')
|
68
|
+
instance_eval(&block) if block_given?
|
69
|
+
end
|
70
|
+
Attachments.new(entity.commit)
|
71
|
+
end
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
data/lib/rujira/api/project.rb
CHANGED
@@ -5,9 +5,10 @@ module Rujira
|
|
5
5
|
# TODO
|
6
6
|
# https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/project
|
7
7
|
class Project < Item
|
8
|
-
def self.get(id_or_key)
|
8
|
+
def self.get(id_or_key, &block)
|
9
9
|
entity = Entity.build do
|
10
10
|
path "project/#{id_or_key}"
|
11
|
+
instance_eval(&block) if block_given?
|
11
12
|
end
|
12
13
|
new(entity.commit)
|
13
14
|
end
|
data/lib/rujira/api/search.rb
CHANGED
@@ -5,13 +5,17 @@ module Rujira
|
|
5
5
|
# TODO
|
6
6
|
# https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/search
|
7
7
|
class Search < Item
|
8
|
-
def self.get(
|
8
|
+
def self.get(&block)
|
9
9
|
entity = Entity.build do
|
10
10
|
path 'search'
|
11
|
-
data data
|
12
11
|
method :POST
|
12
|
+
instance_eval(&block) if block_given?
|
13
13
|
end
|
14
|
-
entity.commit
|
14
|
+
new(entity.commit)
|
15
|
+
end
|
16
|
+
|
17
|
+
def iter
|
18
|
+
data['issues'].map do |issue|
|
15
19
|
Issue.new(issue)
|
16
20
|
end
|
17
21
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Rujira
|
4
4
|
module Api
|
5
5
|
# TODO
|
6
|
-
# https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/
|
6
|
+
# https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/serverInfo
|
7
7
|
class ServerInfo < Item
|
8
8
|
def self.get
|
9
9
|
entity = Entity.build do
|
data/lib/rujira/connection.rb
CHANGED
data/lib/rujira/entity.rb
CHANGED
@@ -5,6 +5,8 @@ module Rujira
|
|
5
5
|
class Entity
|
6
6
|
def initialize
|
7
7
|
@method = :GET
|
8
|
+
@params = {}
|
9
|
+
@headers = {}
|
8
10
|
@rest_api = 'rest/api/2'
|
9
11
|
end
|
10
12
|
|
@@ -17,6 +19,14 @@ module Rujira
|
|
17
19
|
entity
|
18
20
|
end
|
19
21
|
|
22
|
+
def params(params)
|
23
|
+
@params = params
|
24
|
+
end
|
25
|
+
|
26
|
+
def headers(headers)
|
27
|
+
@headers = headers
|
28
|
+
end
|
29
|
+
|
20
30
|
def method(method)
|
21
31
|
@method = method
|
22
32
|
end
|
@@ -60,20 +70,26 @@ module Rujira
|
|
60
70
|
|
61
71
|
def get
|
62
72
|
request do
|
63
|
-
client.get path
|
73
|
+
client.get path do |req|
|
74
|
+
req.params = @params
|
75
|
+
end
|
64
76
|
end
|
65
77
|
end
|
66
78
|
|
67
79
|
def delete
|
68
80
|
request do
|
69
|
-
client.delete path
|
81
|
+
client.delete path do |req|
|
82
|
+
req.params = @params
|
83
|
+
end
|
70
84
|
end
|
71
85
|
end
|
72
86
|
|
73
87
|
def post
|
74
88
|
request do
|
75
89
|
client.post path do |req|
|
76
|
-
req.
|
90
|
+
req.headers = @headers
|
91
|
+
req.params = @params
|
92
|
+
req.body = data
|
77
93
|
end
|
78
94
|
end
|
79
95
|
end
|
@@ -81,7 +97,8 @@ module Rujira
|
|
81
97
|
def put
|
82
98
|
request do
|
83
99
|
client.put path do |req|
|
84
|
-
req.
|
100
|
+
req.params = @params
|
101
|
+
req.body = data
|
85
102
|
end
|
86
103
|
end
|
87
104
|
end
|
data/lib/rujira/tasks/jira.rb
CHANGED
@@ -11,47 +11,86 @@ module Rujira
|
|
11
11
|
include ::Rake::DSL if defined?(::Rake::DSL)
|
12
12
|
|
13
13
|
def initialize
|
14
|
+
@options = {
|
15
|
+
issuetype: 'Task'
|
16
|
+
}
|
17
|
+
@parser = OptionParser.new
|
14
18
|
define
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def parser
|
22
|
+
yield
|
23
|
+
args = @parser.order!(ARGV) {}
|
24
|
+
@parser.parse!(args)
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
name
|
25
|
-
|
27
|
+
def options(name)
|
28
|
+
@options[name]
|
29
|
+
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
# rubocop:disable Metrics/AbcSize
|
32
|
+
# rubocop:disable Metrics/MethodLength
|
33
|
+
def define
|
34
|
+
generate 'whoami' do
|
35
|
+
puts Rujira::Api::Myself.get.name
|
32
36
|
end
|
33
|
-
|
37
|
+
generate 'url' do
|
38
|
+
puts Rujira::Configuration.url
|
39
|
+
end
|
40
|
+
generate 'server_info' do
|
41
|
+
puts Rujira::Api::ServerInfo.get.data.to_json
|
42
|
+
end
|
43
|
+
generate 'create' do
|
44
|
+
parser do
|
45
|
+
@parser.banner = "Usage: rake jira:task:create -- '[options]'"
|
46
|
+
@parser.on('-p PROJECT', '--project=PROJECT') { |project| @options[:project] = project.strip }
|
47
|
+
@parser.on('-s SUMMARY', '--summary=SUMMARY') { |summary| @options[:summary] = summary.strip }
|
48
|
+
@parser.on('-d DESCRIPTION', '--description=DESCRIPTION') do |description|
|
49
|
+
@options[:description] = description.strip
|
50
|
+
end
|
51
|
+
@parser.on('-i ISSUETYPE', '--issuetype=ISSUETYPE') { |issuetype| @options[:issuetype] = issuetype.strip }
|
52
|
+
end
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
result = Rujira::Api::Issue.create fields: {
|
55
|
+
project: { key: @options[:project] },
|
56
|
+
summary: @options[:summary],
|
57
|
+
issuetype: { name: @options[:issuetype] },
|
58
|
+
description: @options[:description]
|
59
|
+
}
|
60
|
+
url = Rujira::Configuration.url
|
61
|
+
puts "// A new task been posted, check it out at #{url}/browse/#{result.data['key']}"
|
62
|
+
end
|
63
|
+
generate 'search' do
|
64
|
+
parser do
|
65
|
+
@parser.banner = "Usage: rake jira:task:search -- '[options]'"
|
66
|
+
@parser.on('-q JQL', '--jql=JQL') { |jql| @options[:jql] = jql }
|
67
|
+
end
|
38
68
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
69
|
+
result = Rujira::Api::Search.get jql: @options[:jql]
|
70
|
+
result.iter.each { |i| puts JSON.pretty_generate(i.data) }
|
71
|
+
end
|
72
|
+
generate 'attach' do
|
73
|
+
parser do
|
74
|
+
@parser.banner = "Usage: rake jira:task:attach -- '[options]'"
|
75
|
+
@parser.on('-f FILE', '--file=FILE') { |jql| @options[:file] = jql }
|
76
|
+
@parser.on('-i ID', '--issue=ID') { |jql| @options[:id] = jql }
|
43
77
|
end
|
78
|
+
|
79
|
+
result = Rujira::Api::Issue.attachments @options[:id], @options[:file]
|
80
|
+
JSON.pretty_generate(result)
|
44
81
|
end
|
45
82
|
end
|
83
|
+
# rubocop:enable Metrics/AbcSize
|
84
|
+
# rubocop:enable Metrics/MethodLength
|
46
85
|
|
47
|
-
def
|
48
|
-
|
49
|
-
desc
|
86
|
+
def generate(name, &block)
|
87
|
+
fullname = "jira:#{name}"
|
88
|
+
desc "Run #{fullname}"
|
50
89
|
|
51
|
-
Rake::Task[
|
90
|
+
Rake::Task[fullname].clear if Rake::Task.task_defined?(fullname)
|
52
91
|
namespace :jira do
|
53
92
|
task name do
|
54
|
-
|
93
|
+
instance_eval(&block)
|
55
94
|
end
|
56
95
|
end
|
57
96
|
end
|
data/lib/rujira/version.rb
CHANGED
data/lib/rujira.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
+
require 'faraday/multipart'
|
4
5
|
require 'json'
|
5
6
|
require_relative 'rujira/version'
|
6
7
|
require_relative 'rujira/connection'
|
@@ -11,6 +12,7 @@ require_relative 'rujira/api/search'
|
|
11
12
|
require_relative 'rujira/api/issue'
|
12
13
|
require_relative 'rujira/api/project'
|
13
14
|
require_relative 'rujira/api/comment'
|
15
|
+
require_relative 'rujira/api/attachments'
|
14
16
|
require_relative 'rujira/api/myself'
|
15
17
|
require_relative 'rujira/api/server_info'
|
16
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rujira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Semenov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The library is developed for the purposes of the organization, new features
|
14
14
|
can be added as MR. Welcome!
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- compose.yaml
|
27
27
|
- lib/rujira.rb
|
28
|
+
- lib/rujira/api/attachments.rb
|
28
29
|
- lib/rujira/api/comment.rb
|
29
30
|
- lib/rujira/api/issue.rb
|
30
31
|
- lib/rujira/api/item.rb
|