Module: GitMaintain

Defined in:
lib/ci.rb,
lib/repo.rb,
lib/azure.rb,
lib/branch.rb,
lib/common.rb,
lib/travis.rb,
lib/addons/RDMACore.rb,
lib/addons/git-maintain.rb

Defined Under Namespace

Classes: AzureCI, Branch, CI, CherryPickErrorException, Common, GitMaintainBranch, GitMaintainRepo, RDMACoreBranch, RDMACoreCI, RDMACoreRepo, Repo, TravisCI

Constant Summary collapse

ACTION_CLASS =
[ Common, Branch, Repo ]
@@custom_classes =
{}
@@load_class =
[]
@@verbose_log =
false

Class Method Summary collapse

Class Method Details

._log(lvl, str, out = STDOUT) ⇒ Object



180
181
182
# File 'lib/common.rb', line 180

def _log(lvl, str, out=STDOUT)
    puts("# " + lvl.to_s() + ": " + str)
end

.checkDirectConstructor(theClass) ⇒ Object

Check that the constructor was called through loadClass



85
86
87
88
89
90
91
92
93
# File 'lib/common.rb', line 85

def checkDirectConstructor(theClass)
    curLoad= @@load_class.last()
    cl = theClass
    while cl != Object
        return if cl == curLoad
        cl = cl.superclass
    end
    raise("Use GitMaintain::loadClass to construct a #{theClass} class")
end

.checkLog(opts, br1, br2, action_msg) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/common.rb', line 164

def checkLog(opts, br1, br2, action_msg)
    puts "Diff between #{br1} and #{br2}"
    puts `git log --format=oneline #{br1} ^#{br2}`
    return "n" if action_msg.to_s() == ""
    rep = confirm(opts, "#{action_msg} this branch")
    return rep
end

.checkOpts(opts) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/common.rb', line 121

def checkOpts(opts)
    ACTION_CLASS.each(){|x|
        next if x::ACTION_LIST.index(opts[:action]) == nil
        next if x.singleton_methods().index(:check_opts) == nil
        x.check_opts(opts)

        # Try to add repo specific opts
        y = getClass(x)
        if x != y && y.singleton_methods().index(:check_opts) != nil then
            y.check_opts(opts)
        end
    }
end

.confirm(opts, msg, ignore_default = false) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/common.rb', line 145

def confirm(opts, msg, ignore_default=false)
    rep = 't'
    while rep != "y" && rep != "n" && rep != '' do
        puts "Do you wish to #{msg} ? (y/N): "
        case (ignore_default == true ? nil : opts[:yn_default])
        when :no
            puts "Auto-replying no due to --no option"
            rep = 'n'
        when :yes
            puts "Auto-replying yes due to --yes option"
            rep = 'y'
        else
            rep = STDIN.gets.chomp()
        end
    end
    return rep
end

.execAction(opts, action) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/common.rb', line 136

def execAction(opts, action)
    ACTION_CLASS.each(){|x|
        next if x::ACTION_LIST.index(action) == nil
        x.execAction(opts, action)
        break
    }
end

.getActionAttr(attr) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/common.rb', line 96

def getActionAttr(attr)
    if Common.const_get(attr).class == Hash
        return ACTION_CLASS.inject({}){|h, x| h.merge(x.const_get(attr))}
    else
        return ACTION_CLASS.map(){|x| x.const_get(attr)}.flatten()
    end
end

.getClass(default_class, repo_name = File.basename(Dir.pwd())) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/common.rb', line 64

def getClass(default_class, repo_name = File.basename(Dir.pwd()))
    custom = @@custom_classes[repo_name]
    if custom != nil && custom[default_class] != nil then
        log(:DEBUG,"Detected custom #{default_class} class for repo '#{repo_name}'")
        return custom[default_class]
    else
        log(:DEBUG,"Detected NO custom #{default_class} classes for repo '#{repo_name}'")
        return default_class
    end
end

.loadClass(default_class, repo_name, *more) ⇒ Object



76
77
78
79
80
81
# File 'lib/common.rb', line 76

def loadClass(default_class, repo_name, *more)
    @@load_class.push(default_class)
    obj = GitMaintain::getClass(default_class, repo_name).new(*more)
    @@load_class.pop()
    return obj
end

.log(lvl, str) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/common.rb', line 185

def log(lvl, str)
    case lvl
    when :DEBUG
        _log("DEBUG".magenta(), str) if ENV["DEBUG"].to_s() != ""
    when :DEBUG_CI
        _log("DEBUG_CI".magenta(), str) if ENV["DEBUG_CI"].to_s() != ""
    when :VERBOSE
        _log("INFO".blue(), str) if @@verbose_log == true
    when :INFO
        _log("INFO".green(), str)
    when :WARNING
        _log("WARNING".brown(), str)
    when :ERROR
        _log("ERROR".red(), str, STDERR)
    else
        _log(lvl, str)
    end
end

.registerCustom(repo_name, classes) ⇒ Object



58
59
60
61
# File 'lib/common.rb', line 58

def registerCustom(repo_name, classes)
    raise("Multiple class for repo #{repo_name}") if @@custom_classes[repo_name] != nil
    @@custom_classes[repo_name] = classes
end

.setOpts(action, optsParser, opts) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/common.rb', line 105

def setOpts(action, optsParser, opts)
     ACTION_CLASS.each(){|x|
        next if x::ACTION_LIST.index(action) == nil
        if x.singleton_methods().index(:set_opts) != nil then
            x.set_opts(action, optsParser, opts)
        end
        # Try to add repo specific opts
        y = getClass(x)
        if x != y && y.singleton_methods().index(:set_opts) != nil then
            y.set_opts(action, optsParser, opts)
        end
        break
    }
end

.setVerbose(val) ⇒ Object



205
206
207
# File 'lib/common.rb', line 205

def setVerbose(val)
    @@verbose_log = val
end

.showLog(opts, br1, br2) ⇒ Object



173
174
175
176
177
# File 'lib/common.rb', line 173

def showLog(opts, br1, br2)
    log(:INFO, "Diff between #{br1} and #{br2}")
    puts `git log --format=oneline #{br1} ^#{br2}`
    return "n"
end