Class: Xanthus::GitHub

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Repository

#prepare_readme_file, #prepare_xanthus_file

Constructor Details

#initializeGitHub

Returns a new instance of GitHub.



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

def initialize
  super
  @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



63
64
65
66
67
68
69
70
# File 'lib/xanthus/github.rb', line 63

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



86
87
88
# File 'lib/xanthus/github.rb', line 86

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

#init(config) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xanthus/github.rb', line 50

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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/xanthus/github.rb', line 37

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



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

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



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

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



30
31
32
33
34
35
# File 'lib/xanthus/github.rb', line 30

def readme_file config
  self.prepare_readme_file config
  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



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

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



23
24
25
26
27
28
# File 'lib/xanthus/github.rb', line 23

def xanthus_file
  self.prepare_xanthus_file
  system('git', 'add', '.xanthus')
  system('git', 'commit', '-m', "[Xanthus] :horse: pushed #{@folder}/.xanthus :horse:")
  system('git', 'push', "https://#{@token}@github.com/#{@repo}", 'master')
end