Class: Ruboty::GithubAssignor::RepoWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/github_assignor/repo_watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(robot:, repo:, octokit:, assignor:, to:, messages:) ⇒ RepoWatcher

Returns a new instance of RepoWatcher.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ruboty/github_assignor/repo_watcher.rb', line 6

def initialize(robot:, repo:, octokit:, assignor:, to:, messages:)
  @robot = robot
  @repo = repo
  @octokit = octokit
  @assignor = assignor
  @to = to
  @messages = messages

  @checked_issue_ids = []

  check_issues(false)
end

Instance Method Details

#check_issues(assign = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ruboty/github_assignor/repo_watcher.rb', line 19

def check_issues(assign = true)
  log "Checking new issues..."

  @octokit.issues(@repo).each do |issue|
    unless @checked_issue_ids.include?(issue[:id])
      log "New issue found (#{issue[:id]} / #{issue[:title]})"
      message = find_message(issue)
      if message && assign && !issue[:assignee]
        # assign this issue
        assignee = @assignor.next
        log "Assigning this issue to #{assignee}..."

        log "Updating assignee of GitHub issue..."
        @octokit.update_issue(@repo, issue[:number], assignee: assignee.github_name)

        log "Reminding the user of the issue..."
        say(<<-EOC)
@#{assignee.chat_name} さん、#{message['message']}お願いします!

#{issue[:title]}
<#{issue[:html_url]}>
        EOC

        log "Done."
      end
      @checked_issue_ids << issue[:id]
    end
  end
end

#start(interval) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruboty/github_assignor/repo_watcher.rb', line 49

def start(interval)
  Thread.start do
    log "Start watching issues"
    loop do
      sleep(interval)
      begin
        check_issues
      rescue => err
        log err.inspect
      end
    end
  end
end