rujira 0.1.5 → 0.1.6

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: 96e27cf9c81ca531b4420dd97af3d4bd9a05707667e4027e47356e28d701ffd1
4
- data.tar.gz: 696c3a16896f5b5147efdcb8e1f4a8aa7d621af24da5b658e958cfbbbd9c50c2
3
+ metadata.gz: b6c5b714472d56b23db8bfe6a5a96e60c3dfd6af7cb8176fbef27d839bc2ace3
4
+ data.tar.gz: 106ca92334c64b3129f4e66d8aaa570eaa4d09adcba9ac7dad1d4136d6c251a8
5
5
  SHA512:
6
- metadata.gz: 36b03ae34cb00d9af66ca8680c2809fc97b9039bddbc803d12f4067535c7a689b3adb5a5a1a9edf2fa5de044e7136e73306a2838b26f18009cf3989bc400e34a
7
- data.tar.gz: 440e05d095d25d262942abcde295ebb48568a22b12a66bdaeb24531f9e2ed17cdd4c3d969ec9c1d5169f6e5cb34d26be353c3491b8c93dc7fe53e7a96d53e3fc
6
+ metadata.gz: ae579ef0d21f37fb22002669d668ddf6f876a1940da8fd0e5cd6022f8458407913ea3ba398af98590daf75b8dcd4b4b783c0764c05081aef60e24a4db789450d
7
+ data.tar.gz: 19062bf410f45b08e1a1554743a7f179acb314d3e95a8a92c5d914b1147b64458797ea849da34c19e3867e6c726add88f23c810f186df2cd6f81c76794a1bb39
data/README.md CHANGED
@@ -8,28 +8,37 @@
8
8
 
9
9
  name = Rujira::Api::Myself.get.name
10
10
  Rujira::Api::Project.get 'ITMG'
11
- Rujira::Api::Issue.create fields: {
12
- project: { key: 'ITMG' },
13
- summary: 'BOT: added a new feature.',
14
- description: 'This task was generated by the bot when creating changes in the repository.',
15
- issuetype: { name: 'Task' },
16
- labels: ['bot']
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
- result = Rujira::Api::Search.get jql: 'project = ITMG and status IN ("To Do", "In Progress") ORDER BY issuekey',
21
- maxResults: 10,
22
- startAt: 0,
23
- fields: ['id', 'key']
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
24
28
  result.iter
25
- Rujira::Api::Issue.comment 'ITMG-1', body: 'Adding a new comment'
26
- Rujira::Api::Issue.edit 'ITMG-1', update: {
27
- labels:[{add: 'rujira'},{remove: 'bot'}],
28
- },
29
- fields: {
30
- assignee: { name: name },
31
- summary: 'This is a shorthand for a set operation on the summary field'
32
- }
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'
33
42
  Rujira::Api::Issue.del 'ITMG-1'
34
43
 
35
44
  ## Rake tasks
@@ -52,3 +61,5 @@
52
61
  ### Example with Curl
53
62
 
54
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/compose.yaml CHANGED
@@ -5,6 +5,7 @@ services:
5
5
  restart: always
6
6
  image: atlassian/jira-software
7
7
  environment: {}
8
+ # JVM_SUPPORT_RECOMMENDED_ARGS: "-Datlassian.recovery.password=<PASSWORD>"
8
9
  ports:
9
10
  - 8080:8080
10
11
  volumes:
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rujira
4
+ module Api
5
+ # TODO
6
+ # https://docs.atlassian.com/software/jira/docs/api/REST/8.17.1/#api/2/comment/%7BcommentId%7D/properties
7
+ class Attachments < Item; end
8
+ end
9
+ end
@@ -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.get(id_or_key)
8
+ def self.create(&block)
9
9
  entity = Entity.build do
10
- path "issue/#{id_or_key}"
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.del(id_or_key)
17
+ def self.get(id_or_key, &block)
16
18
  entity = Entity.build do
17
19
  path "issue/#{id_or_key}"
18
- method :DELETE
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.create(**data)
25
+ def self.del(id_or_key, &block)
24
26
  entity = Entity.build do
25
- path 'issue'
26
- method :POST
27
- data data if data
27
+ path "issue/#{id_or_key}"
28
+ method :DELETE
29
+ instance_eval(&block) if block_given?
28
30
  end
29
- new(entity.commit)
31
+ entity.commit
30
32
  end
31
33
 
32
- def self.edit(id_or_key, **data)
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
- data data
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, **data)
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
- data data if data
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, data)
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
- data data
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
@@ -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
@@ -5,11 +5,11 @@ 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(**data)
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
14
  new(entity.commit)
15
15
  end
@@ -13,6 +13,7 @@ module Rujira
13
13
  def run
14
14
  Faraday.new(@options) do |builder|
15
15
  builder.request :authorization, 'Bearer', -> { @token }
16
+ builder.request :multipart, flat_encode: true
16
17
  builder.request :json
17
18
  builder.response :json
18
19
  builder.response :raise_error
data/lib/rujira/entity.rb CHANGED
@@ -6,6 +6,7 @@ module Rujira
6
6
  def initialize
7
7
  @method = :GET
8
8
  @params = {}
9
+ @headers = {}
9
10
  @rest_api = 'rest/api/2'
10
11
  end
11
12
 
@@ -22,6 +23,10 @@ module Rujira
22
23
  @params = params
23
24
  end
24
25
 
26
+ def headers(headers)
27
+ @headers = headers
28
+ end
29
+
25
30
  def method(method)
26
31
  @method = method
27
32
  end
@@ -65,21 +70,26 @@ module Rujira
65
70
 
66
71
  def get
67
72
  request do
68
- client.get path
73
+ client.get path do |req|
74
+ req.params = @params
75
+ end
69
76
  end
70
77
  end
71
78
 
72
79
  def delete
73
80
  request do
74
- client.delete path
81
+ client.delete path do |req|
82
+ req.params = @params
83
+ end
75
84
  end
76
85
  end
77
86
 
78
87
  def post
79
88
  request do
80
89
  client.post path do |req|
90
+ req.headers = @headers
81
91
  req.params = @params
82
- req.body = data.to_json
92
+ req.body = data
83
93
  end
84
94
  end
85
95
  end
@@ -87,7 +97,8 @@ module Rujira
87
97
  def put
88
98
  request do
89
99
  client.put path do |req|
90
- req.body = data.to_json
100
+ req.params = @params
101
+ req.body = data
91
102
  end
92
103
  end
93
104
  end
@@ -69,6 +69,16 @@ module Rujira
69
69
  result = Rujira::Api::Search.get jql: @options[:jql]
70
70
  result.iter.each { |i| puts JSON.pretty_generate(i.data) }
71
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 }
77
+ end
78
+
79
+ result = Rujira::Api::Issue.attachments @options[:id], @options[:file]
80
+ JSON.pretty_generate(result)
81
+ end
72
82
  end
73
83
  # rubocop:enable Metrics/AbcSize
74
84
  # rubocop:enable Metrics/MethodLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rujira
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
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.5
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-04-20 00:00:00.000000000 Z
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