Module: GitMaintain

Defined in:
lib/repo.rb,
lib/branch.rb,
lib/common.rb,
lib/travis.rb,
lib/addons/RDMACore.rb

Defined Under Namespace

Classes: Branch, CherryPickErrorException, Common, RDMACoreBranch, Repo, TravisChecker

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.checkDirectConstructor(theClass) ⇒ Object

Check that the constructor was called through loadClass



45
46
47
48
49
50
51
52
53
54
# File 'lib/common.rb', line 45

def checkDirectConstructor(theClass)
    # Look for the "new" in the calling tree
    depth = 1
    while caller_locations(depth, 1)[0].label != "new"
        depth +=1
    end
    # The function that called the constructer is just one step below
    raise("Use GitMaintain::loadClass to construct a #{theClass} class") if
            caller_locations(depth + 1, 1)[0].label != "loadClass"
end

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



104
105
106
107
108
109
110
# File 'lib/common.rb', line 104

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

.checkOpts(opts) ⇒ Object



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

def checkOpts(opts)
    ACTION_CLASS.each(){|x|
        next if x.singleton_methods().index(:check_opts) == nil
        x.check_opts(opts)
    }
end

.confirm(opts, msg) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/common.rb', line 89

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

.execAction(opts, action) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/common.rb', line 80

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



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

def getActionAttr(attr)
    return ACTION_CLASS.map(){|x| x.const_get(attr)}.flatten()
end

.getCustom(repo_name) ⇒ Object



27
28
29
# File 'lib/common.rb', line 27

def getCustom(repo_name)
    return @@custom_classes[repo_name]
end

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



32
33
34
35
36
37
38
39
40
41
# File 'lib/common.rb', line 32

def loadClass(default_class, repo_name, *more)
    custom = @@custom_classes[repo_name]
    if custom != nil && custom[default_class] != nil then
        puts "# Detected custom #{default_class} class for repo '#{repo_name}'" if ENV['DEBUG'] == "1"
        return custom[default_class].new(*more)
    else
        puts "# Detected NO custom #{default_class} classes for repo '#{repo_name}'" if ENV['DEBUG'] == "1"
        return default_class.new(*more)
    end
end

.registerCustom(repo_name, classes) ⇒ Object



21
22
23
24
# File 'lib/common.rb', line 21

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



62
63
64
65
66
67
68
69
# File 'lib/common.rb', line 62

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