Class: Issuesrc::Issuers::GithubIssuer

Inherits:
Object
  • Object
show all
Defined in:
lib/issuers/github_issuer.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, config, event_loop) ⇒ GithubIssuer

Returns a new instance of GithubIssuer.



40
41
42
43
44
45
46
# File 'lib/issuers/github_issuer.rb', line 40

def initialize(args, config, event_loop)
  @user, @repo = find_repo(args, config)
  @token = try_find_token(args, config)
  @event_loop = event_loop

  @issuesrc_label = try_find_issuesrc_label(args, config)
end

Instance Method Details

#async_close_issue(issue_id) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/issuers/github_issuer.rb', line 63

def async_close_issue(issue_id)
  ghreq(:patch, "/repos/#{@user}/#{@repo}/issues/#{issue_id}", {
    'state' => 'closed'
  }) do |req|
    yield if block_given?
  end
end

#async_create_issue(tag, &block) ⇒ Object



54
55
56
# File 'lib/issuers/github_issuer.rb', line 54

def async_create_issue(tag, &block)
  save_tag(tag, :post, "/repos/#{@user}/#{@repo}/issues", &block)
end

#async_load_issuesObject



48
49
50
51
52
# File 'lib/issuers/github_issuer.rb', line 48

def async_load_issues()
  queue = EM::Queue.new
  async_load_issues_pages(queue, 1)
  Issues.new(queue)
end

#async_update_issue(issue_id, tag, &block) ⇒ Object



58
59
60
61
# File 'lib/issuers/github_issuer.rb', line 58

def async_update_issue(issue_id, tag, &block)
  save_tag(tag, :patch, "/repos/#{@user}/#{@repo}/issues/#{issue_id}",
           &block)
end

#async_update_or_close_issues(prev_issues, tags_by_issue_id, &block) ⇒ Object



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
# File 'lib/issuers/github_issuer.rb', line 71

def async_update_or_close_issues(prev_issues, tags_by_issue_id, &block)
  updated = Set.new

  prev_issues.each do |issue|
    issue_id = issue['number'].to_s

    if tags_by_issue_id.include? issue_id
      updated.add issue_id
      tag = tags_by_issue_id[issue_id]
      make_sure_issue_exists_and_then do |exists|
        if exists
          async_update_issue(issue_id, tag) do |tag|
            if !block.nil?
              yield issue_id, tag, :updated
            end
          end
        end
      end
    else
      async_close_issue(issue_id) do
        yield issue_id, nil, :closed
      end
    end
  end

  tags_by_issue_id.each do |issue_id, tag|
    if updated.include? issue_id
      next
    end
    make_sure_issue_exists_and_then do |exists|
      if exists
        async_update_issue(issue_id, tag) do |tag|
          if !block.nil?
            yield issue_id, tag, :updated
          end
        end
      end
    end
  end
end

#make_sure_issue_exists_and_then {|true| ... } ⇒ Object

Yields:

  • (true)


112
113
114
115
# File 'lib/issuers/github_issuer.rb', line 112

def make_sure_issue_exists_and_then
  # TODO(#21)
  yield true
end