 #   hubot redmine (みんな|<nickname[,nickname]>) の実績[詳細] - 前営業日の実績を教えてもらおう！
 #   hubot redmine 実績チェック - 前営業日の実績をチェックするよ！
 #   hubot redmine <nickname> 実績チェック(する|しない) - 実績チェックの対象、または対象外にするよ！
+#   hubot redmine [yyyy-mm-dd] <#9999> 99[.99](h|時間) <活動> [コメント]- 実績を登録しよう！(日付省略時は前営業日になるよ) 例) hubot redmine #41 1.25h 製造 働いたよ!
 #
 # URLS:
 #   None.

    if method in ["POST", "PUT"]
      if typeof(body) isnt "string"
        body = JSON.stringify body

      options.headers["Content-Length"] = body.length

    # console.log options.url
    request options, (err, response, data) ->
      if !err and response?.statusCode is 200
        try
          if opt.type is 'json'
            callback null, JSON.parse(data), response
          else if opt.type is 'atom'
            rssparser.parseString data, {}, (error, feed) ->
              # console.log feed
              callback error, feed, response
        catch err2
          callback null, (data or { }), response
      else
        console.log 'error: ' + response?.statusCode + ', url =>' + options.url
        console.log err ||= response?.statusCode
        #@send "Redmine がなんかエラーやわ"
        callback err, null, response
  # /private request }}}
# /Redmine }}}


      msg.send reply
  # }}}

  robot.respond /redmine[\s]+(\d{2,4}(?:-|\/)\d{1,2}(?:-|\/)\d{1,2}[\s]+)?#(\d+)[\s]+(\d{1,2}(\.00?|\.25|\.50?|.75)?)[\s]*(?:h|時間)[\s]+([\S]+)(?:[\s]+"?([^"]+)"?)?/i, (msg) -> # {{{
    userName = msg.message.user.name
    user = whoIsThis robot, userName
    return msg.send "誰？" unless user

    [date, id, hours, hoursshosu, activity, userComments] = msg.match[1..6]
    if date
      date = new Date date
      return msg.send "#{date} は日付じゃない" unless Date.validateDay(date.getDate(), date.getFullYear(), date.getMonth())
    else
      date = getPrevKadobi robot, Date.yesterday()
    dateYMD = date.toYMD()
    console.log dateYMD

    if userComments?
      comments = "#{msg.message.user.name}: #{userComments}"
    else
      comments = "Time logged by: #{msg.message.user.name}"
    activityId = getActivityId activity
    unless activityId
      msg.reply "こんな\"活動\"はない > #{activity}\n"
      msg.send " Usage: #{robot.name} redmine ##{id} #{hours}h 製造 #{activity}"
      return

    redmine.Users name:user, (err, data) =>
      # console.log 'count:' + userName + ' ' + data.total_count
      unless data.total_count > 0
        msg.send "\"#{user}\" が redmine で見つけられない"
        return false
      redmineUser = resolveUsers(user, data.users)[0]

      attributes =
        issue_id: id
        spent_on: dateYMD
        hours: hours
        comments: comments
        user_id: redmineUser.id
        activity_id: activityId

      redmine.TimeEntry().create attributes, (error, data, response) ->
        if response?.statusCode == 201
          msg.reply "よく頑張りました！(#{dateYMD} で登録)"
        else
          msg.reply "なんか失敗"
# }}}

