lhj-tools 0.1.13 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/action/sh_helper.rb +3 -3
- data/lib/lhj/command/init.rb +1 -0
- data/lib/lhj/command/pgyer_upload.rb +20 -0
- data/lib/lhj/command/yapi/formatters/service.rb +13 -4
- data/lib/lhj/command/yapi/formatters/template/git.erb +1 -0
- data/lib/lhj/command/yapi/formatters/template/pgyer.erb +6 -0
- data/lib/lhj/command/yapi.rb +3 -3
- data/lib/lhj/command.rb +1 -2
- data/lib/lhj/config.rb +2 -0
- data/lib/lhj/helper/dingtalk_config.rb +23 -0
- data/lib/lhj/helper/dingtalk_helper.rb +14 -0
- data/lib/lhj/helper/git_helper.rb +140 -0
- data/lib/lhj/helper/log_helper.rb +66 -0
- data/lib/lhj/helper/pgyer_config.rb +31 -0
- data/lib/lhj/helper/pgyer_helper.rb +69 -0
- data/lib/lhj/helper/tb_config.rb +36 -0
- data/lib/lhj/helper/tb_helper.rb +54 -0
- data/lib/lhj/tools/version.rb +1 -1
- data/lib/lhj/tools.rb +8 -0
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 705ada7bc27d0f1e46aa928ae8693dce2954ddb140159aac417f95347a5df1ae
|
4
|
+
data.tar.gz: 8163156750c3e67b6b846d99438d0832ebddf8683849fff31a6ec91d42434ec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc564c14c9b145457d14bb439fd6fd5d7455e4d6fbc46bc27e9017f87b94a37a508452c0b46d3cb4600419a47f131b136cf62a97148a6549b406cae1a16af4c8
|
7
|
+
data.tar.gz: b4c03b76aaa34b4e1c6e01d058ccf59f2eb269705c05be7fc6b4fc4dbb7ffed0a148453b165092da58deeb4b0092c84488766fe9c71138110958179073b521ed
|
data/lib/lhj/action/sh_helper.rb
CHANGED
@@ -119,17 +119,17 @@ module Lhj
|
|
119
119
|
|
120
120
|
# Optional initial environment Hash
|
121
121
|
if args.first.kind_of?(Hash)
|
122
|
-
command = args.shift.map { |k, v| "#{k}=#{v.
|
122
|
+
command = args.shift.map { |k, v| "#{k}=#{v.to_s}" }.join(" ") + " "
|
123
123
|
end
|
124
124
|
|
125
125
|
# Support [ "/usr/local/bin/foo", "foo" ], "-x", ...
|
126
126
|
if args.first.kind_of?(Array)
|
127
|
-
command += args.shift.first.
|
127
|
+
command += args.shift.first.to_s + " " + args.join(' ')
|
128
128
|
command.chomp!(" ")
|
129
129
|
elsif args.count == 1 && args.first.kind_of?(String)
|
130
130
|
command += args.first
|
131
131
|
else
|
132
|
-
command += args.
|
132
|
+
command += args.join(' ')
|
133
133
|
end
|
134
134
|
|
135
135
|
command
|
data/lib/lhj/command/init.rb
CHANGED
@@ -39,6 +39,7 @@ module Lhj
|
|
39
39
|
FileUtils.mkdir_p(target_folder) unless File.exist?(target_folder)
|
40
40
|
if @url
|
41
41
|
file_path = file_name_from_url(@url)
|
42
|
+
File.delete(file_path) if File.exist?(file_path)
|
42
43
|
save_url_to_file(@url, file_path)
|
43
44
|
else
|
44
45
|
file_path = File.join(target_folder, 'config_file.yml')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'lhj/helper/pgyer_helper'
|
2
|
+
require 'lhj/helper/dingtalk_config'
|
3
|
+
require 'lhj/helper/pgyer_config'
|
4
|
+
require 'lhj/helper/tb_config'
|
5
|
+
|
6
|
+
|
7
|
+
module Lhj
|
8
|
+
class Command
|
9
|
+
class Pgyer < Command
|
10
|
+
|
11
|
+
def handle
|
12
|
+
client = Lhj::Pgyer.new
|
13
|
+
file = File.expand_path('/Users/lihaijian/**/*.ipa')
|
14
|
+
client.upload_file(file, 'test....')
|
15
|
+
output = client.render_template
|
16
|
+
puts output.blue
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -8,14 +8,23 @@ module Lhj
|
|
8
8
|
class Service < Base
|
9
9
|
# @param [String] name
|
10
10
|
def render(name = 'yapi')
|
11
|
-
|
11
|
+
temp_str = template_str(name)
|
12
|
+
render_template(temp_str)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def render_template(temp_str)
|
16
|
+
template(temp_str).result(Context.new(@runner).fetch_binding)
|
17
|
+
end
|
18
|
+
|
19
|
+
def template_str(name)
|
20
|
+
File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb"))
|
21
|
+
end
|
22
|
+
|
23
|
+
def template(template_str)
|
15
24
|
if RUBY_VERSION < '2.6'
|
16
|
-
ERB.new(
|
25
|
+
ERB.new(template_str, nil, '-')
|
17
26
|
else
|
18
|
-
ERB.new(
|
27
|
+
ERB.new(template_str, trim_mode: '-')
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
【代码分支:<%= @branch %>】【服务环境:<%= @env %>】-【最近更新日志】<%= @log %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#### 应用名称:<%= @result['data']['appName'] %>
|
2
|
+
#### 版本信息:<%= @result['data']['appVersion'] %>(Build <%= @result['data']['appBuildVersion'] %>)
|
3
|
+
#### 更新时间:<%= @result['data']['appCreated'] %>
|
4
|
+
#### 更新内容:<%= @result['data']['appUpdateDescription'] %>
|
5
|
+
> ![screenshot](<%= @result['data']['appQRCodeURL'] %>)
|
6
|
+
> [下载](https://www.pgyer.com/<%= @result['data']['appShortcutUrl'] %>)
|
data/lib/lhj/command/yapi.rb
CHANGED
@@ -279,7 +279,7 @@ module Lhj
|
|
279
279
|
models.each do |model|
|
280
280
|
model_name = model[:name] || ''
|
281
281
|
model_properties = model[:properties]
|
282
|
-
puts_h "public class #{model_name} extends BaseModel implements BusinessEvent.
|
282
|
+
puts_h "public class #{model_name} extends BaseModel implements BusinessEvent.ProductDataCollect {"
|
283
283
|
model_properties.each do |m|
|
284
284
|
print_model_for_java(m)
|
285
285
|
end
|
@@ -291,7 +291,7 @@ module Lhj
|
|
291
291
|
models.each do |model|
|
292
292
|
puts_m "@implementation #{model[:name]}"
|
293
293
|
str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map { |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
|
294
|
-
if str
|
294
|
+
if str&.length&.positive?
|
295
295
|
puts_m '+(NSDictionary *)modelContainerPropertyGenericClass {'
|
296
296
|
puts_m " return @{#{str}};"
|
297
297
|
puts_m '}'
|
@@ -364,7 +364,7 @@ module Lhj
|
|
364
364
|
when 'array'
|
365
365
|
puts_h "#{type_name}[] #{key};//#{des} #{default}"
|
366
366
|
else
|
367
|
-
puts_h "
|
367
|
+
puts_h "String #{key};//#{des} #{default}"
|
368
368
|
end
|
369
369
|
end
|
370
370
|
|
data/lib/lhj/command.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'claide'
|
2
2
|
require "tty-spinner"
|
3
|
-
require 'lhj/action/sh_helper'
|
4
|
-
require 'lhj/ui/ui'
|
5
3
|
|
6
4
|
module Lhj
|
7
5
|
# command plugin
|
@@ -26,6 +24,7 @@ module Lhj
|
|
26
24
|
require 'lhj/command/file_path'
|
27
25
|
require 'lhj/command/http'
|
28
26
|
require 'lhj/command/sync_pod_repo'
|
27
|
+
require 'lhj/command/pgyer_upload'
|
29
28
|
|
30
29
|
self.abstract_command = true
|
31
30
|
self.command = 'lhj'
|
data/lib/lhj/config.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'lhj/config'
|
4
|
+
|
5
|
+
module Lhj
|
6
|
+
# Ding Talk Config
|
7
|
+
class DingTalkConfig
|
8
|
+
|
9
|
+
CONFIG_NAME = 'dingtalk_config.yml'
|
10
|
+
|
11
|
+
def self.config_file
|
12
|
+
File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@yaml ||= YAML.load_file(config_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.dingtalk_robot
|
20
|
+
config['dingtalk_robot']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'lhj/helper/dingtalk_config'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Lhj
|
5
|
+
# pgyer upload
|
6
|
+
class Dingtalk
|
7
|
+
|
8
|
+
def self.post_message(title, message)
|
9
|
+
robot_url = Lhj::DingTalkConfig.dingtalk_robot
|
10
|
+
http_body = { 'msgtype' => 'markdown', 'markdown' => { 'title' => title, 'text' => message } }.to_json
|
11
|
+
Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module Lhj
|
2
|
+
module Actions
|
3
|
+
GIT_MERGE_COMMIT_FILTERING_OPTIONS = [:include_merges, :exclude_merges, :only_include_merges].freeze
|
4
|
+
|
5
|
+
module SharedValues
|
6
|
+
GIT_BRANCH_ENV_VARS = %w(GIT_BRANCH BRANCH_NAME TRAVIS_BRANCH BITRISE_GIT_BRANCH CI_BUILD_REF_NAME CI_COMMIT_REF_NAME WERCKER_GIT_BRANCH BUILDKITE_BRANCH APPCENTER_BRANCH).freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.git_log_between(pretty_format, from, to, merge_commit_filtering, date_format = nil, ancestry_path)
|
10
|
+
command = %w(git log)
|
11
|
+
command << "--pretty=#{pretty_format}"
|
12
|
+
command << "--date=#{date_format}" if date_format
|
13
|
+
command << '--ancestry-path' if ancestry_path
|
14
|
+
command << "#{from}...#{to}"
|
15
|
+
command << git_log_merge_commit_filtering_option(merge_commit_filtering)
|
16
|
+
# "*command" syntax expands "command" array into variable arguments, which
|
17
|
+
# will then be individually shell-escaped by Actions.sh.
|
18
|
+
Actions.sh(*command.compact, log: false).chomp
|
19
|
+
rescue
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.git_log_last_commits(pretty_format, commit_count, merge_commit_filtering, date_format = nil, ancestry_path)
|
24
|
+
command = %w(git log)
|
25
|
+
command << "--pretty=#{pretty_format}"
|
26
|
+
command << "--date=#{date_format}" if date_format
|
27
|
+
command << '--ancestry-path' if ancestry_path
|
28
|
+
command << '-n' << commit_count.to_s
|
29
|
+
command << git_log_merge_commit_filtering_option(merge_commit_filtering)
|
30
|
+
Actions.sh(*command.compact, log: false).chomp
|
31
|
+
rescue
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.last_git_tag_hash(tag_match_pattern = nil)
|
36
|
+
tag_pattern_param = tag_match_pattern ? "=#{tag_match_pattern}" : ''
|
37
|
+
Actions.sh('git', 'rev-list', "--tags#{tag_pattern_param}", '--max-count=1').chomp
|
38
|
+
rescue
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.last_git_tag_name(match_lightweight = true, tag_match_pattern = nil)
|
43
|
+
hash = last_git_tag_hash(tag_match_pattern)
|
44
|
+
# If hash is nil (command fails), "git describe" command below will still
|
45
|
+
# run and provide some output, although it's definitely not going to be
|
46
|
+
# anything reasonably expected. Bail out early.
|
47
|
+
return unless hash
|
48
|
+
|
49
|
+
command = %w(git describe)
|
50
|
+
command << '--tags' if match_lightweight
|
51
|
+
command << hash
|
52
|
+
command << '--match' if tag_match_pattern
|
53
|
+
command << tag_match_pattern if tag_match_pattern
|
54
|
+
Actions.sh(*command.compact, log: false).chomp
|
55
|
+
rescue
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.last_git_commit_dict
|
60
|
+
return nil if last_git_commit_formatted_with('%an').nil?
|
61
|
+
|
62
|
+
{
|
63
|
+
author: last_git_commit_formatted_with('%an'),
|
64
|
+
author_email: last_git_commit_formatted_with('%ae'),
|
65
|
+
message: last_git_commit_formatted_with('%B'),
|
66
|
+
commit_hash: last_git_commit_formatted_with('%H'),
|
67
|
+
abbreviated_commit_hash: last_git_commit_formatted_with('%h')
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the last git commit information formatted into a String by the provided
|
72
|
+
# pretty format String. See the git-log documentation for valid format placeholders
|
73
|
+
def self.last_git_commit_formatted_with(pretty_format, date_format = nil)
|
74
|
+
command = %w(git log -1)
|
75
|
+
command << "--pretty=#{pretty_format}"
|
76
|
+
command << "--date=#{date_format}" if date_format
|
77
|
+
Actions.sh(*command.compact, log: false).chomp
|
78
|
+
rescue
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
82
|
+
# @deprecated Use <tt>git_author_email</tt> instead
|
83
|
+
# Get the author email of the last git commit
|
84
|
+
# <b>DEPRECATED:</b> Use <tt>git_author_email</tt> instead.
|
85
|
+
def self.git_author
|
86
|
+
UI.deprecated('`git_author` is deprecated. Please use `git_author_email` instead.')
|
87
|
+
git_author_email
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get the author email of the last git commit
|
91
|
+
def self.git_author_email
|
92
|
+
s = last_git_commit_formatted_with('%ae')
|
93
|
+
return s if s.to_s.length > 0
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns the unwrapped subject and body of the last commit
|
98
|
+
# <b>DEPRECATED:</b> Use <tt>last_git_commit_message</tt> instead.
|
99
|
+
def self.last_git_commit
|
100
|
+
last_git_commit_message
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns the unwrapped subject and body of the last commit
|
104
|
+
def self.last_git_commit_message
|
105
|
+
s = (last_git_commit_formatted_with('%B') || "").strip
|
106
|
+
return s if s.to_s.length > 0
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
|
110
|
+
# Get the hash of the last commit
|
111
|
+
def self.last_git_commit_hash(short)
|
112
|
+
format_specifier = short ? '%h' : '%H'
|
113
|
+
string = last_git_commit_formatted_with(format_specifier).to_s
|
114
|
+
return string unless string.empty?
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the current git branch, or "HEAD" if it's not checked out to any branch
|
119
|
+
# Can be replaced using the environment variable `GIT_BRANCH`
|
120
|
+
def self.git_branch
|
121
|
+
begin
|
122
|
+
Actions.sh("git rev-parse --abbrev-ref HEAD", log: false).chomp
|
123
|
+
rescue => err
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private_class_method
|
129
|
+
def self.git_log_merge_commit_filtering_option(merge_commit_filtering)
|
130
|
+
case merge_commit_filtering
|
131
|
+
when :exclude_merges
|
132
|
+
"--no-merges"
|
133
|
+
when :only_include_merges
|
134
|
+
"--merges"
|
135
|
+
when :include_merges
|
136
|
+
nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Lhj
|
2
|
+
# log helper
|
3
|
+
class LogHelper
|
4
|
+
attr_reader :branch, :env, :log
|
5
|
+
|
6
|
+
def self.instance
|
7
|
+
@instance ||= new
|
8
|
+
end
|
9
|
+
|
10
|
+
def commit_log(env)
|
11
|
+
@branch = fetch_branch
|
12
|
+
@env = fetch_env(env)
|
13
|
+
@log = fetch_log
|
14
|
+
save_last_commit_hash
|
15
|
+
render_template
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch_branch
|
19
|
+
Lhj::Actions.git_branch || ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_env(env)
|
23
|
+
case env
|
24
|
+
when :release
|
25
|
+
'release'
|
26
|
+
when :gray
|
27
|
+
'release'
|
28
|
+
else
|
29
|
+
'uat'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_log
|
34
|
+
from = last_commit_hash
|
35
|
+
to = 'HEAD'
|
36
|
+
changelog = Lhj::Actions.git_log_between(' %an, %ar - %s;', from, to, :exclude_merges, 'short', false)
|
37
|
+
changelog ||= ''
|
38
|
+
changelog&.gsub("\n\n", "\n")
|
39
|
+
changelog.gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('days ', '天').gsub('ago ', '前')
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_last_commit_hash
|
43
|
+
last_commit_hash = Lhj::Actions.last_git_commit_hash(true)
|
44
|
+
File.delete(last_commit_file) if File.exist?(last_commit_file)
|
45
|
+
File.write(last_commit_file, last_commit_hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
def last_commit_hash
|
49
|
+
if File.exist?(last_commit_file)
|
50
|
+
File.read(last_commit_file)
|
51
|
+
else
|
52
|
+
'HEAD~3'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def last_commit_file
|
57
|
+
File.join(Lhj::Config.instance.home_dir, ".#{@branch}_last_commit")
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_template
|
61
|
+
temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'git.erb'))
|
62
|
+
Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'lhj/config'
|
4
|
+
|
5
|
+
module Lhj
|
6
|
+
# pgyer config
|
7
|
+
class PgyerConfig
|
8
|
+
|
9
|
+
CONFIG_NAME = 'pgyer_config.yml'
|
10
|
+
|
11
|
+
def self.config_file
|
12
|
+
File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@yaml ||= YAML.load_file(config_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.api_key
|
20
|
+
config['api_key']
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.user_key
|
24
|
+
config['user_key']
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.password
|
28
|
+
config['password']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'lhj/helper/pgyer_config'
|
4
|
+
require 'lhj/command/yapi/formatters/service'
|
5
|
+
require 'lhj/config'
|
6
|
+
require_relative 'tb_config'
|
7
|
+
|
8
|
+
module Lhj
|
9
|
+
# pgyer upload
|
10
|
+
class Pgyer
|
11
|
+
|
12
|
+
API_HOST = 'https://upload.pgyer.com/apiv1/app/upload'.freeze
|
13
|
+
|
14
|
+
attr_reader :api_key, :user_key, :password, :result
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@api_key = Lhj::PgyerConfig.api_key
|
18
|
+
@user_key = Lhj::PgyerConfig.user_key
|
19
|
+
@password = Lhj::PgyerConfig.password
|
20
|
+
@result = { 'data' => {} }
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Faraday::Connection]
|
24
|
+
def http_client
|
25
|
+
conn_options = {
|
26
|
+
request: {
|
27
|
+
timeout: 1000,
|
28
|
+
open_timeout: 300
|
29
|
+
}
|
30
|
+
}
|
31
|
+
Faraday.new(nil, conn_options) do |builder|
|
32
|
+
builder.request :multipart
|
33
|
+
builder.request :url_encoded
|
34
|
+
builder.response :json, content_type: /\bjson$/
|
35
|
+
builder.adapter :net_http
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def upload_file(file, des)
|
40
|
+
|
41
|
+
update_description = @result[:update_description]
|
42
|
+
update_description = "" if update_description.nil?
|
43
|
+
params = {
|
44
|
+
'_api_key' => @api_key,
|
45
|
+
'uKey' => @user_key,
|
46
|
+
'password' => @password,
|
47
|
+
'updateDescription' => des,
|
48
|
+
'installType' => 2,
|
49
|
+
'file' => Faraday::UploadIO.new(file, 'application/octet-stream')
|
50
|
+
}
|
51
|
+
begin
|
52
|
+
puts 'begin upload'
|
53
|
+
response = http_client.post API_HOST, params
|
54
|
+
@result = response.body
|
55
|
+
puts @result
|
56
|
+
if @result['data'] && @result['data']['appUpdateDescription']
|
57
|
+
@result['data']['appUpdateDescription'] = Lhj::TbHelper.trans_tb(@result['data']['appUpdateDescription'])
|
58
|
+
end
|
59
|
+
rescue Faraday::TimeoutError
|
60
|
+
puts 'upload fail'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_template
|
65
|
+
temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'pgyer.erb'))
|
66
|
+
Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'lhj/config'
|
4
|
+
|
5
|
+
module Lhj
|
6
|
+
# tb config
|
7
|
+
class TBConfig
|
8
|
+
|
9
|
+
CONFIG_NAME = 'tb_config.yml'
|
10
|
+
|
11
|
+
def self.config_file
|
12
|
+
File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@yaml ||= YAML.load_file(config_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tb_app_id
|
20
|
+
config['tb_app_id']
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.tb_app_key
|
24
|
+
config['tb_app_key']
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.tb_tenant_id
|
28
|
+
config['tb_tenant_id']
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.projectId
|
32
|
+
config['projectId']
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'lhj/helper/tb_config'
|
2
|
+
require 'jwt'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Lhj
|
8
|
+
# tb upload
|
9
|
+
class TbHelper
|
10
|
+
|
11
|
+
SEARCH_API_URL = 'https://open.teambition.com/api/task/tqlsearch'.freeze
|
12
|
+
|
13
|
+
def self.trans_tb(note)
|
14
|
+
str = note
|
15
|
+
if /#.+#/ =~ note
|
16
|
+
note.scan(/#[^#]+#/) do |m|
|
17
|
+
res_body = req_with_task(m.match(/\d+/)[0])
|
18
|
+
if res_body['code'].to_i == 200
|
19
|
+
url_str = "[#{res_body['result'][0]['content']}](https://www.teambition.com/task/#{res_body['result'][0]['taskId']})"
|
20
|
+
str = str.gsub(m, url_str)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
str
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.req_with_task(id)
|
28
|
+
now = Time.now.to_i
|
29
|
+
payload = {
|
30
|
+
_appId: Lhj::TBConfig.tb_app_id,
|
31
|
+
iat: now,
|
32
|
+
exp: now + 3600
|
33
|
+
}
|
34
|
+
token = JWT.encode(payload, Lhj::TBConfig.tb_app_key)
|
35
|
+
|
36
|
+
url = URI(SEARCH_API_URL)
|
37
|
+
https = Net::HTTP.new(url.host, url.port)
|
38
|
+
https.use_ssl = true
|
39
|
+
|
40
|
+
request = Net::HTTP::Post.new(url)
|
41
|
+
request['authorization'] = "Bearer #{token}"
|
42
|
+
request['x-tenant-id'] = Lhj::TBConfig.tb_tenant_id
|
43
|
+
request['x-tenant-type'] = 'organization'
|
44
|
+
request['Content-Type'] = 'application/json'
|
45
|
+
req_body = {
|
46
|
+
"tql": "projectId=#{Lhj::TBConfig.projectId} AND uniqueId=#{id}"
|
47
|
+
}
|
48
|
+
request.body = JSON.dump(req_body)
|
49
|
+
|
50
|
+
response = https.request(request)
|
51
|
+
JSON.parse(response.read_body)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/lhj/tools/version.rb
CHANGED
data/lib/lhj/tools.rb
CHANGED
@@ -3,7 +3,15 @@ require_relative "tools/version"
|
|
3
3
|
require 'colored'
|
4
4
|
|
5
5
|
module Lhj
|
6
|
+
require 'lhj/ui/ui'
|
6
7
|
require 'lhj/config'
|
8
|
+
require 'lhj/helper/pgyer_helper'
|
9
|
+
require 'lhj/helper/dingtalk_helper'
|
10
|
+
require 'lhj/helper/tb_helper'
|
11
|
+
require 'lhj/action/sh_helper'
|
12
|
+
require 'lhj/helper/git_helper'
|
13
|
+
require 'lhj/helper/log_helper'
|
14
|
+
|
7
15
|
class Error < StandardError; end
|
8
16
|
|
9
17
|
autoload :Command, 'lhj/command'
|
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.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: claide
|
@@ -262,6 +262,26 @@ dependencies:
|
|
262
262
|
- - "<"
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: 3.0.0
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: jwt
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - ">="
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 2.1.0
|
272
|
+
- - "<"
|
273
|
+
- !ruby/object:Gem::Version
|
274
|
+
version: '3'
|
275
|
+
type: :runtime
|
276
|
+
prerelease: false
|
277
|
+
version_requirements: !ruby/object:Gem::Requirement
|
278
|
+
requirements:
|
279
|
+
- - ">="
|
280
|
+
- !ruby/object:Gem::Version
|
281
|
+
version: 2.1.0
|
282
|
+
- - "<"
|
283
|
+
- !ruby/object:Gem::Version
|
284
|
+
version: '3'
|
265
285
|
description: lhj tools.
|
266
286
|
email:
|
267
287
|
- sanan.li@qq.com
|
@@ -289,6 +309,7 @@ files:
|
|
289
309
|
- lib/lhj/command/oss/del.rb
|
290
310
|
- lib/lhj/command/oss/list.rb
|
291
311
|
- lib/lhj/command/oss/upload.rb
|
312
|
+
- lib/lhj/command/pgyer_upload.rb
|
292
313
|
- lib/lhj/command/refactor_rename.rb
|
293
314
|
- lib/lhj/command/rename_image.rb
|
294
315
|
- lib/lhj/command/reverse_import.rb
|
@@ -300,12 +321,22 @@ files:
|
|
300
321
|
- lib/lhj/command/yapi/formatters/base.rb
|
301
322
|
- lib/lhj/command/yapi/formatters/command_context.rb
|
302
323
|
- lib/lhj/command/yapi/formatters/service.rb
|
324
|
+
- lib/lhj/command/yapi/formatters/template/git.erb
|
303
325
|
- lib/lhj/command/yapi/formatters/template/model.erb
|
326
|
+
- lib/lhj/command/yapi/formatters/template/pgyer.erb
|
304
327
|
- lib/lhj/command/yapi/formatters/template/yapi.erb
|
305
328
|
- lib/lhj/config.rb
|
329
|
+
- lib/lhj/helper/dingtalk_config.rb
|
330
|
+
- lib/lhj/helper/dingtalk_helper.rb
|
331
|
+
- lib/lhj/helper/git_helper.rb
|
306
332
|
- lib/lhj/helper/local_config.rb
|
333
|
+
- lib/lhj/helper/log_helper.rb
|
307
334
|
- lib/lhj/helper/oss_config.rb
|
308
335
|
- lib/lhj/helper/oss_helper.rb
|
336
|
+
- lib/lhj/helper/pgyer_config.rb
|
337
|
+
- lib/lhj/helper/pgyer_helper.rb
|
338
|
+
- lib/lhj/helper/tb_config.rb
|
339
|
+
- lib/lhj/helper/tb_helper.rb
|
309
340
|
- lib/lhj/helper/trans_helper.rb
|
310
341
|
- lib/lhj/tools.rb
|
311
342
|
- lib/lhj/tools/version.rb
|