LoginSignup
2
2

More than 5 years have passed since last update.

BacklogAPIとHubotでSlackに課題通知を送る (続き)

Last updated at Posted at 2015-12-27

前回

Coffee script 参考

CoffeeScript 言語リファレンス
基本操作逆引きリファレンス(CoffeeScript)

Backlog API

朝に期限が迫っている課題を通知させたい

Backlog API とは

ここを参照しながら

できたソースコードは以下

backlog2.coffee

# Description:#   Backlog to Slack## Commands:#   None

cron = require('cron').CronJob

backlogUrl = '****'
apiKey = '****'
username = '***'

module.exports = (robot) ->
    new cron "0 0 9,15 * * *", () =>
        console.log "BacklogAPI 2 start..."

        now_raw = new Date
        console.log "#{now_raw}"
        now = "#{now_raw.getFullYear()}#{now_raw.getMonth()+1}#{now_raw.getDate()}"
        console.log now

        # APIアクセス
        robot.http("#{backlogUrl}api/v2/issues?apiKey=#{apiKey}")
        .get() (err, res, body) ->

            # console.log body

            for feed in JSON.parse body
                if feed.dueDate is null
                    continue

                due = "#{feed.dueDate[0..3]}#{feed.dueDate[5..6]}#{feed.dueDate[8..9]}"

                if now > due and feed.status.id > 2 # 過去の課題で処理済みのものは表示しない。 status id 1:未処理 2:処理中 3:処理済み 4:完了
                    continue
                if feed.assignee.name isnt username # 自分の課題以外はスルー
                    continue
                if parseInt(due,10) - parseInt(now,10) > 14 #2週間より先の課題は表示しない
                    continue
                console.log due
                console.log feed.issueKey
                console.log feed.assignee.name
                console.log "due : #{feed.dueDate}"
                console.log "*"

                # 投稿メッセージを整形
                url = "#{backlogUrl}view/#{feed.issueKey}"
                message = "[#{feed.issueKey}] #{feed.summary} #{url}"

                # Slack に投稿
                robot.send {room: '#backlog'}, message
                # console.log message

    , null, true, "Asia/Tokyo"

2
2
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
2
2