lib/lhj/command/yapi.rb in lhj-tools-0.1.74 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.75
- old
+ new
@@ -73,11 +73,11 @@
# 5.save to file
file_map = save_to_file(service_code) if @save
# 6.push to git
push_to_git if @sync
# 7.notify robot
- notify_robot(file_map) if @notify
+ notify_robot(file_map, res_body, project_info) if @notify
end
def puts_h(str)
puts str.magenta
@h_file_array ||= []
@@ -115,23 +115,27 @@
service_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Service.m")
File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive?
File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
File.write(service_file, service_code) if service_code
puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green
- { h_file: h_file, m_file: m_file, s_file: service_file, api_id: api_id }
+ { h_file: h_file, m_file: m_file, s_file: service_file }
end
def push_to_git
Actions.sh('git checkout master')
Actions.sh('git add .')
Actions.sh("git commit -m 'generate yapi code'")
Actions.sh('git push')
end
- def notify_robot(template_vars)
+ def notify_robot(file_info, interface_info, project_info)
+ temp_vars = file_info.merge({
+ api_id: api_id,
+ interface_url: "#{project_info['data']['basepath']}#{interface_info['data']['path']}"
+ })
robot_url = 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
template = Lhj::ErbTemplateHelper.load('oc_code_notify')
- output = Lhj::ErbTemplateHelper.render(template, template_vars, '-')
+ output = Lhj::ErbTemplateHelper.render(template, temp_vars, '-')
Lhj::Dingtalk.post_message_robot(robot_url, '生成代码', output)
end
def interface_url_str
"#{@base_url}/#{API_INTERFACE_URL}#{api_id}"