Class: Pindo::Command::Utils::Feishu

Inherits:
Pindo::Command::Utils show all
Defined in:
lib/pindo/command/utils/feishu.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, 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, use_cache?

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.



50
51
52
53
54
55
56
57
# File 'lib/pindo/command/utils/feishu.rb', line 50

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

命令的选项列表



44
45
46
47
48
# File 'lib/pindo/command/utils/feishu.rb', line 44

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

Instance Method Details

#runObject



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/pindo/command/utils/feishu.rb', line 64

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 "正在发送飞书消息..."


  git_repo_helper = Pindo::GitRepoHelper.share_instance
  git_repo_helper.check_check_and_install_cliff(pindo_project_dir)
  is_need_add_tag, tag_action_parms = git_repo_helper.check_is_need_add_tag?(pindo_project_dir)
  if is_need_add_tag
    git_repo_helper.create_and_push_tag(
      project_dir: pindo_project_dir,
      mode: 'minor',
      force_retag: tag_action_parms&.include?('--retag') || false,
      custom_tag: nil,
      release_branch: 'master'
    )
  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



59
60
61
62
# File 'lib/pindo/command/utils/feishu.rb', line 59

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