Class: Xanthus::GitHub

Inherits:
Object
  • Object
show all
Defined in:
lib/xanthus/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitHub

Returns a new instance of GitHub.



9
10
11
12
13
# File 'lib/xanthus/github.rb', line 9

def initialize
  @repo = ''
  @token = ''
  @folder = Time.now.strftime("%Y-%m-%d_%H-%M")
end

Instance Attribute Details

#folderObject

Returns the value of attribute folder.



7
8
9
# File 'lib/xanthus/github.rb', line 7

def folder
  @folder
end

#repoObject

Returns the value of attribute repo.



5
6
7
# File 'lib/xanthus/github.rb', line 5

def repo
  @repo
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/xanthus/github.rb', line 6

def token
  @token
end

Instance Method Details

#add(content) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/xanthus/github.rb', line 71

def add content
  Dir.chdir 'repo' do
    FileUtils.mkdir_p @folder
    system('mv', "../#{content}", "#{@folder}/#{content}")
    system('git', 'add', "#{@folder}/#{content}")
    system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/#{content} :horse:")
  end
end

#cleanObject



94
95
96
# File 'lib/xanthus/github.rb', line 94

def clean
  system('rm', '-rf', 'repo')
end

#init(config) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xanthus/github.rb', line 58

def init config
  system('git', 'clone', "https://#{@token}@github.com/#{@repo}", 'repo')
  Dir.chdir 'repo' do
    self.lfs
    FileUtils.mkdir_p @folder
    Dir.chdir @folder do
      self.xanthus_file
      self.readme_file config
      self.inputs_file config
    end
  end
end

#inputs_file(config) ⇒ Object



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

def inputs_file config
  config.jobs.each do |name,job|
    job.inputs.each do |k, files|
      files.each do |file|
        system('cp', '-f', "../../#{file}", "#{file}")
        system('git', 'add', "#{file}")
        system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/#{file} :horse:")
        system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
      end
    end
  end
end

#lfsObject



15
16
17
18
19
20
# File 'lib/xanthus/github.rb', line 15

def lfs
  system('git', 'lfs', 'install')
  system('git', 'lfs', 'track', '*.tar.gz')
  system('git', 'add', '.gitattributes')
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
end

#pushObject



80
81
82
83
84
85
# File 'lib/xanthus/github.rb', line 80

def push
  Dir.chdir 'repo' do
    system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
    system('rm', '-rf', @folder)
  end
end

#readme_file(config) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/xanthus/github.rb', line 36

def readme_file config
  File.open('README.md', 'w+') do |f|
    f.write(config.to_readme_md)
  end
  system('git', 'add', 'README.md')
  system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/README.md :horse:")
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
end

#tagObject



87
88
89
90
91
92
# File 'lib/xanthus/github.rb', line 87

def tag
  Dir.chdir 'repo' do
    system('git', 'tag', '-a', "xanthus-#{@folder}", '-m', '"Xanthus automated dataset generation."')
    system('git', 'push', '--tags', "https://#{@token}@github.com/#{@repo}")
  end
end

#xanthus_fileObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xanthus/github.rb', line 22

def xanthus_file
  script = ''
  File.readlines('../../.xanthus').each do |line|
    script += line unless line.include? 'github.token'
    script += "\t\tgithub.token = 'REMOVED'\n" unless !line.include? 'github.token'
  end
  File.open('.xanthus', 'w+') do |f|
    f.write(script)
  end
  system('git', 'add', '.xanthus')
  system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/.xanthus :horse:")
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
end