Class: Pindo::Command::Dev::Feishu

Inherits:
Pindo::Command::Dev show all
Defined in:
lib/pindo/command/dev/feishu.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

run

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Feishu

Returns a new instance of Feishu.



32
33
34
35
36
37
38
39
# File 'lib/pindo/command/dev/feishu.rb', line 32

def initialize(argv)
  super
  @webhook_url = argv.option('webhook')
  # @webhook_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/dbffda6e-a809-4e79-9652-c427c93ffe62'
  # @secret = 'VoC4vVmhwWs676zK62NK8d'
  @secret = nil
  @message = argv.shift_argument || "测试消息"
end

Class Method Details

.optionsObject

命令的选项列表



26
27
28
29
30
# File 'lib/pindo/command/dev/feishu.rb', line 26

def self.options
  [
    ['--webhook',  '使用feishu 机器人的webhook url'],
  ].concat(super)
end

Instance Method Details

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pindo/command/dev/feishu.rb', line 46

def run

  pindo_project_dir = Dir.pwd
  if @webhook_url.nil? || @webhook_url.empty?
    if is_git_directory?(local_repo_dir: pindo_project_dir)
      current_git_root_path = git_root_directory(local_repo_dir: pindo_project_dir)
      if File.exist?(File.join(current_git_root_path, 'feishu.json'))
        feishu_config = JSON.parse(File.read(File.join(current_git_root_path, 'feishu.json')))
        @webhook_url = feishu_config['webhook_url']
        @secret = feishu_config['secret']
      end
    end

    if @webhook_url.nil? || @webhook_url.empty?
      @webhook_url = ask("请输入飞书webhook url:")
      if is_git_directory?(local_repo_dir: pindo_project_dir)
        current_git_root_path = git_root_directory(local_repo_dir: pindo_project_dir)
        feishu_config = {webhook_url: @webhook_url, secret: @secret}
        File.write(File.join(current_git_root_path, 'feishu.json'), JSON.pretty_generate(feishu_config))
        Dir.chdir(current_git_root_path)
        current_branch = git!(%W(-C #{current_git_root_path} rev-parse --abbrev-ref HEAD)).strip
        git!(%W(-C #{current_git_root_path} add feishu.json))
        commit_message = "docs: 添加飞书webhook url".encode('UTF-8')
        git!(%W(-C #{current_git_root_path} commit -m #{commit_message}))
        git!(%W(-C #{current_git_root_path} push origin #{current_branch}))
        puts "添加飞书webhook url成功"
      end
    end

  end
  puts "webhook_url: #{@webhook_url}"
  puts "secret: #{@secret}"
  puts
  puts "正在发送飞书消息..."


  build_helper = Pindo::BuildHelper.share_instance
  build_helper.check_check_and_install_cliff(pindo_project_dir)
  is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(pindo_project_dir)
  if is_need_add_tag
      Pindo::Command::Dev::Tag::run(tag_action_parms) 
  end

  unless @webhook_url.nil? || @webhook_url.empty?
    @client = Pindo::FeishuClient.new(@webhook_url, @secret)
  end

  markdown_content = PgyerHelper.share_instace.get_description_from_git(current_project_dir:pindo_project_dir)
  puts
  puts "#{markdown_content}"  
  puts
  if !markdown_content.nil? && !markdown_content.empty?
    @client.send_markdown(nil, markdown_content)
    # @client.send_rich_text("1111", markdown_content)
  end

end

#validate!Object



41
42
43
44
# File 'lib/pindo/command/dev/feishu.rb', line 41

def validate!
  super
  help! '请提供要发送的消息内容' unless @message
end