Class: TeachersPet::Actions::OpenIssue

Inherits:
Base
  • Object
show all
Defined in:
lib/teachers_pet/actions/open_issue.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #options

Instance Method Summary collapse

Methods inherited from Base

#execute, #init_client, #initialize, #octokit_config, #read_file, #read_members_file, #read_students_file

Constructor Details

This class inherits a constructor from TeachersPet::Actions::Base

Instance Method Details

#createObject


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
48
# File 'lib/teachers_pet/actions/open_issue.rb', line 22

def create
  # confirm("Create issue '#{@issue[:title]}' in #{@students.keys.size} student repositories - '#{@repository}'?")
  self.init_client

  org_hash = self.client.organization(@organization)
  abort('Organization could not be found') if org_hash.nil?
  puts "Found organization at: #{org_hash[:login]}"

  org_teams = self.client.get_teams_by_name(@organization)

  puts "\nCreating issue in repositories..."
  @students.keys.sort.each do |student|
    unless org_teams.key?(student)
      puts("  ** ERROR ** - no team for #{student}")
      next
    end
    repo_name = "#{student}-#{@repository}"

    unless self.client.repository?(@organization, repo_name)
      puts " --> Repository not found, skipping '#{repo_name}'"
      next
    end

    # Create the issue with octokit
    self.client.create_issue("#{@organization}/#{repo_name}", @issue[:title], @issue[:body], @issue[:options])
  end
end

#load_filesObject


17
18
19
20
# File 'lib/teachers_pet/actions/open_issue.rb', line 17

def load_files
  @students = self.read_students_file
  @issue[:body] = File.open(@issue_file).read
end

#read_infoObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/teachers_pet/actions/open_issue.rb', line 4

def read_info
  @repository = self.options[:repository]
  @organization = self.options[:organization]

  @issue = {
    title: self.options[:title],
    options: {
      labels: self.options[:labels]
    }
  }
  @issue_file = self.options[:body]
end

#runObject


50
51
52
53
54
# File 'lib/teachers_pet/actions/open_issue.rb', line 50

def run
  self.read_info
  self.load_files
  self.create
end