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

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Feishu

Returns a new instance of Feishu.



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

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

命令的选项列表



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

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

Instance Method Details

#runObject



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/pindo/command/dev/feishu.rb', line 63

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



58
59
60
61
# File 'lib/pindo/command/dev/feishu.rb', line 58

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