lhj-tools 0.2.24 → 0.2.26

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
  SHA256:
3
- metadata.gz: 253e532b62ca8fd6c1b10281d9dfc87cb2f1a40abbd185f66066abc72b7cd72d
4
- data.tar.gz: 3b67e5cfb736805d1b078b72efe4cab2d8f28848c77e8b3d049fbf6dfc227648
3
+ metadata.gz: 16224374a128ff4316f5553b1d5baa614e23d4e13bc1deadbbf3ca2e2e891dd8
4
+ data.tar.gz: d312a877fc8e1e32964b985aa9d302ff903a36aad3da75cc20796000582771cb
5
5
  SHA512:
6
- metadata.gz: f23ae53bdd2047b055f1baec787b67a21684b42f23f1004c503ebcfc157670fd6d09c58f774a7a3fad374371ae474b534cc616835da73ea53595a40047fa321f
7
- data.tar.gz: 7ddab83f382970b112d558ec7b410def3530281cc321dc3f77af73d5c342ade9f600779870e9ced7bfe78c6d3c6c15c58d205e4b1ef3a5f0c34f2f013258f5f3
6
+ metadata.gz: f69613a09746ac7ab39733e3a1fc657ddbc463a7bcc0efaf6954fb32edff46120b6d819d354e641b450ad45a57630a50d1944c6f8091cf3a589d6e16faeb0544
7
+ data.tar.gz: 3e4c95527e71b21d3612aa31ea8dd549f268c7a6e6e0d8076a91a57163deed8f5658c8043bc6321b47674939927f1e91019f7f22b34c40113b4139805a8248b4
@@ -1,4 +1,5 @@
1
1
  require 'jenkins_api_client'
2
+ require 'nokogiri'
2
3
 
3
4
  module Lhj
4
5
  class Command
@@ -30,34 +31,99 @@ module Lhj
30
31
  end
31
32
 
32
33
  def handle
33
- d = {
34
- "data": {
35
- "attributes": {
36
- "email": "878943972@qq.com",
37
- "firstName": "li",
38
- "lastName": "haijian"
34
+ job_name = 'aom_uat_haijian'
35
+ # job_name = 'aom_uat_haijian'
36
+ server_ip = Lhj::JenkinsConfig.server_ip
37
+ server_port = Lhj::JenkinsConfig.server_port
38
+ username = Lhj::JenkinsConfig.username
39
+ password = Lhj::JenkinsConfig.password
40
+ client = JenkinsApi::Client.new(server_ip: server_ip, server_port: server_port, username: username, password: password)
41
+
42
+ client.job.list_all.each do |a|
43
+ add_property(client, a, 'WEBHOOK', 'https://oapi.dingtalk.com/robot/sendBySession?session=bd640dea6cd28b6c880c4f3cc0945c8f', 'Webhook url')
44
+ end
45
+ # puts client.job.get_config('aomi_uat')
46
+ #
47
+ end
48
+
49
+ def update_job(client, job_name, param_key, param_value, param_desc)
50
+ xml = client.job.get_config(job_name)
51
+ n_xml = Nokogiri::XML(xml)
52
+ params = n_xml.xpath('//parameterDefinitions').first
53
+ string_params = params.children.select { |p| p.name.eql?('hudson.model.StringParameterDefinition') }
54
+ param = string_params.find { |p| p.children.find { |c| c.name.eql?('name') && c.content.eql?(param_key) } }
55
+ has_desc = false
56
+ param.children.each do |p|
57
+ has_desc = true if p.name.eql?('description')
58
+ p.content = param_value if p.name.eql?('defaultValue')
59
+ p.content = param_desc if p.name.eql?('description')
60
+ p.content = 'true' if p.name.eql?('trim')
61
+ end
62
+ param.add_child("<description>#{param_desc}</description>") unless has_desc
63
+ xml_modified = n_xml.to_xml
64
+ client.job.post_config(job_name, xml_modified)
65
+ end
66
+
67
+ def add_property(client, job_name, param_key, param_value, param_desc)
68
+ xml = client.job.get_config(job_name)
69
+ n_xml = Nokogiri::XML(xml)
70
+ params = n_xml.xpath('//parameterDefinitions').first
71
+ return if params
72
+
73
+ pro = n_xml.xpath('//properties').first
74
+ c_xml = <<~DESC
75
+ <hudson.model.ParametersDefinitionProperty>
76
+ <parameterDefinitions>
77
+ <hudson.model.StringParameterDefinition>
78
+ <name>WEBHOOK</name>
79
+ <description>webhook url</description>
80
+ <defaultValue>https://oapi.dingtalk.com/robot/sendBySession?session=cd8539f8472e2f5d39a6beef94ffc569</defaultValue>
81
+ <trim>true</trim>
82
+ </hudson.model.StringParameterDefinition>
83
+ </parameterDefinitions>
84
+ </hudson.model.ParametersDefinitionProperty>
85
+ DESC
86
+ pro.add_child(c_xml)
87
+ xml_modified = n_xml.to_xml
88
+ client.job.post_config(job_name, xml_modified)
89
+ end
90
+
91
+ def create_tester(email, id)
92
+ names = email.split('@') if email =~ /@/
93
+ first_name = names[1] if names && names.length > 1
94
+ last_name = names[0] if names&.length&.positive?
95
+ first_name ||= 'first'
96
+ last_name ||= 'last'
97
+ post_data = {
98
+ 'data' => {
99
+ 'attributes' => {
100
+ 'email' => email,
101
+ 'firstName' => first_name,
102
+ 'lastName' => last_name
39
103
  },
40
- "relationships": {
41
- "builds": {
42
- "data": [
104
+ 'relationships' => {
105
+ 'betaGroups' => {
106
+ 'data' => [
43
107
  {
44
- "id": "0cd7ac82-b2d9-4772-bfa1-0ff6e8037f7d",
45
- "type": "builds"
108
+ 'id' => id,
109
+ 'type' => 'betaGroups'
46
110
  }
47
111
  ]
48
112
  }
49
113
  },
50
- "type": "betaTesters"
114
+ 'type' => 'betaTesters'
51
115
  }
52
116
  }
53
- res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/betaTesters', d)
54
- puts res.read_body
117
+ res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/betaTesters', post_data)
118
+ res_body = JSON.parse(res.body)
119
+ puts 'success' if res_body['data']
120
+ end
55
121
 
56
- # client = JenkinsApi::Client.new(server_ip: 'ip', server_port: 0, username: 'xx', password: 'xx')
57
- # puts client.user.get('aomi')
58
- # puts client.job.list_all
59
- # client.job.build('aomi_uat')
60
- # puts client.job.get_console_output('aomi_uat', 253)
122
+ def all_group
123
+ res = Lhj::ConnectAPI.get('https://api.appstoreconnect.apple.com/v1/betaGroups')
124
+ res_body = JSON.parse(res.body)
125
+ names = res_body['data'].map { |item| { id: item['id'], name: item['attributes']['name'] } }
126
+ names.each { |a| puts a[:name] + '---' + a[:id] }
61
127
  end
62
128
  end
63
129
  end
@@ -30,6 +30,7 @@ module Lhj
30
30
  @id = argv.option('id')
31
31
  @model_pre_name = argv.option('model-pre')
32
32
  @model_result_name = argv.option('model-name')
33
+ @webhook = argv.option('webhook')
33
34
  @language = argv.option('lan', 'oc')
34
35
  @save = argv.flag?('save', false)
35
36
  @sync = argv.flag?('sync', false)
@@ -241,7 +242,7 @@ module Lhj
241
242
  end
242
243
 
243
244
  def robot_url
244
- @config_robot_url || 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
245
+ @webhook || @config_robot_url || 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
245
246
  end
246
247
 
247
248
  def property_mapper
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.24'
4
+ VERSION = '0.2.26'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -252,16 +252,16 @@ dependencies:
252
252
  name: json
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - '='
255
+ - - "<"
256
256
  - !ruby/object:Gem::Version
257
- version: 2.3.0
257
+ version: 3.0.0
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - '='
262
+ - - "<"
263
263
  - !ruby/object:Gem::Version
264
- version: 2.3.0
264
+ version: 3.0.0
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: bundler
267
267
  requirement: !ruby/object:Gem::Requirement