LoginSignup
7
6

More than 5 years have passed since last update.

BacklogのタスクをSlackに通知する その3

Last updated at Posted at 2014-07-16

参照

BacklogのタスクをSlackに通知する
BacklogのタスクをSlackに通知する その2

やりたいこと

その2までのやり方では、backlogの通知を全て取得していたので件数が多くなると重くなっていた。
取得条件にupdate時間を与えて、それ以降のissueを取るようにしてみる。

サンプルコード

前回までとの変更点のみを記載しています。

backlog.rb
require 'xmlrpc/client'

class BacklogClient

  def issuelist(project_id, last_update=nil)
    opt = {"projectId" => project_id}
    opt["updated_on_min"] = last_update if last_update
    @client.call('backlog.findIssue', opt)
  end

end
sample.rb
def main
  pass = ARGV[0]
  last_sent_date = Time.now.strftime("%Y%m%d%H%M%S").to_i
  issue_last_update_date = (last_sent_date / 1000000).to_i

  backlog = BacklogClient.new(BACKLOG_HOST, BACKLOG_USER, BACKLOG_PASS)
  slack = SlackClient.new(SLACK_TEAM, SLACK_TOKEN, SLACK_ROOM, SLACK_NAME)
  while true
    issue_update_on = 0
    begin
      backlog.projectlist.each{|project|
        backlog.issuelist(project["id"], issue_last_update_date).each{|issue|
          if last_sent_date < issue["updated_on"].to_i
            slack_send(slack, project, issue)
            issue_update_on = issue["updated_on"].to_i if issue["updated_on"].to_i > issue_update_on
          end
        }
      }
    rescue => e
      puts e.message
    end
    last_sent_date = issue_update_on if issue_update_on > 0
    issue_last_update_date = (last_sent_date / 1000000).to_i if issue_last_update_date != (last_sent_date / 1000000).to_i
    sleep(10.0)
  end
end
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6