Class: Repository

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/repository.rb

Instance Method Summary collapse

Constructor Details

#initializeRepository

Returns a new instance of Repository.



4
5
6
7
8
9
10
# File 'lib/repository.rb', line 4

def initialize
  @user = Config.user
  @token = Config.token
  @owner_and_repo = Config.get_owner_and_repo

  self.class.basic_auth @user, @token
end

Instance Method Details

#assign_issue(number) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/repository.rb', line 23

def assign_issue(number)
  url = github_url ['issues', number, 'assignees']
  response = self.class.post url, body: { assignees: [@user] }.to_json
  if response.success?
    puts "Successfully assigned issue ##{number} to #{@user}."
  else
    puts 'ERROR assigning user to issue'
    puts response.body
  end
end

#export_labels(issue) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/repository.rb', line 34

def export_labels issue
  url = github_url ['issues', issue.number, 'labels']
  response = self.class.put url, body: issue.labels.to_json
  if response.success?
    puts "Successfully assigned #{issue.labels.inspect} labels to  ##{issue.number}"
  else
    puts 'ERROR setting issue labels'
    puts response.body
  end
end

#get_issue(number) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/repository.rb', line 12

def get_issue(number)
  response = self.class.get github_url ['issues', number]

  if response.success?
    Issue.new(self, JSON.parse(response.body))
  else
    puts 'ERROR requesting issue'
    puts response.body
  end
end

#get_open_issues(label) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/repository.rb', line 45

def get_open_issues label
  response = self.class.get github_url(['issues']), query: { labels: label }

  if response.success?
    issues_data = JSON.parse response.body
    issues_data.reject! { |data| data['pull_request'] }
    issues_data.map { |data| Issue.new(self, data) }
  else
    puts 'ERROR requesting open issues'
    puts response.body
  end
end