Class: Fbup::GitHubSync

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

Constant Summary collapse

REPOS =
GitHubConfig.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repos) ⇒ GitHubSync

Returns a new instance of GitHubSync.



55
56
57
# File 'lib/fbup/github.rb', line 55

def initialize( repos )
    @repos = repos
end

Class Method Details

.find_repos(datasets) ⇒ Object

note: datasets of format

DATASETS = [

 ['it.1',    %w[2020/21 2019/20]],
['it.2',    %w[2019/20]],
['es.1',    %w[2019/20]],
['es.2',    %w[2019/20]],

]



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fbup/github.rb', line 36

def self.find_repos( datasets )
repos = []
datasets.each do |league_key, seasons|
  repo  = REPOS[ league_key ]
  ## pp repo

  if repo.nil?
     puts "!! ERROR - no repo config/path found for league >#{league_key}<; sorry"
     exit 1
  end

  repos <<  "#{repo['owner']}/#{repo['name']}"
end

pp repos
repos.uniq   ## note: remove duplicates (e.g. europe or world or such)

end

.rootObject

(auto)default to Writer.config.out_dir - why? why not?

note - is monotree (that is, requires openfootball/england etc.
              for repo pathspecs)


18
# File 'lib/fbup/github.rb', line 18

def self.root()  @root || "/sports"; end

.root=(dir) ⇒ Object



19
# File 'lib/fbup/github.rb', line 19

def self.root=( dir ) @root = dir; end

Instance Method Details

#_git_fast_forward_if_clean(pathspec) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fbup/github.rb', line 100

def _git_fast_forward_if_clean( pathspec )
    path = "#{self.class.root}/#{pathspec}"

    Gitti::GitProject.open( path ) do |proj|
      output = proj.changes
      unless  output.empty?
        puts "FAIL - cannot git pull (fast-forward) - working tree has changes:"
        puts output
        exit 1
      end

      proj.fast_forward
    end
end

#_git_push_if_changes(pathspec, message:) ⇒ Object

todo/fix: rename to something like

git_(auto_)commit_and_push_if_changes/if_dirty()


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fbup/github.rb', line 80

def _git_push_if_changes( pathspec, message: )
    path = "#{self.class.root}/#{pathspec}"

    Gitti::GitProject.open( path ) do |proj|
      puts ''
      puts "###########################################"
      puts "## trying to commit & push repo in path >#{path}<"
      puts "Dir.getwd: #{Dir.getwd}"
      output = proj.changes
      if output.empty?
        puts "no changes found; skipping commit & push"
      else
        proj.add( '.' )
        proj.commit( message )
        proj.push
      end
    end
end

#git_fast_forward_if_cleanObject



69
70
71
72
73
# File 'lib/fbup/github.rb', line 69

def git_fast_forward_if_clean
    @repos.each do |pathspec|
      _git_fast_forward_if_clean( pathspec )
    end
end

#git_push_if_changesObject



60
61
62
63
64
65
66
67
# File 'lib/fbup/github.rb', line 60

def git_push_if_changes
   message = "auto-update week #{Date.today.cweek}"  ## add /#{Date.today.cday - why? why not?

   puts message

   @repos.each do |pathspec|
       _git_push_if_changes( pathspec, message: message )
   end
end