Class: VCSConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/vcseif/connection.rb

Direct Known Subclasses

RallyVCSConnection

Constant Summary collapse

REVNUM_TOKEN =
"{revnumber}"
REVFILE_TOKEN =
"{filepath}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ VCSConnection

Returns a new instance of VCSConnection.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vcseif/connection.rb', line 56

def initialize(logger)
    @log      = logger
    @config   = nil
    @username = nil
    @password = nil
    @username_required = true
    @password_required = true
    @changeset_selectors   = []
    @connected = false
    @log.info("Initializing %s connection version %s" % [name(), version()])
end

Instance Attribute Details

#changeset_selectorsObject

Returns the value of attribute changeset_selectors.



51
52
53
# File 'lib/vcseif/connection.rb', line 51

def changeset_selectors
  @changeset_selectors
end

#configObject

Returns the value of attribute config.



48
49
50
# File 'lib/vcseif/connection.rb', line 48

def config
  @config
end

#connectedObject (readonly)

Returns the value of attribute connected.



50
51
52
# File 'lib/vcseif/connection.rb', line 50

def connected
  @connected
end

#file_uriObject (readonly)

Returns the value of attribute file_uri.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def file_uri
  @file_uri
end

#logObject

Returns the value of attribute log.



48
49
50
# File 'lib/vcseif/connection.rb', line 48

def log
  @log
end

#passwordObject (readonly)

Returns the value of attribute password.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def password
  @password
end

#password_requiredObject (readonly)

Returns the value of attribute password_required.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def password_required
  @password_required
end

#rev_uriObject (readonly)

Returns the value of attribute rev_uri.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def rev_uri
  @rev_uri
end

#sshkey_pathObject

Returns the value of attribute sshkey_path.



51
52
53
# File 'lib/vcseif/connection.rb', line 51

def sshkey_path
  @sshkey_path
end

#usernameObject (readonly)

Returns the value of attribute username.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def username
  @username
end

#username_requiredObject (readonly)

Returns the value of attribute username_required.



49
50
51
# File 'lib/vcseif/connection.rb', line 49

def username_required
  @username_required
end

Instance Method Details

#connectObject

Raises:

  • (NotImplementedError)


90
91
92
93
94
95
96
97
98
99
# File 'lib/vcseif/connection.rb', line 90

def connect()
    %{
        Returns true or false depending on whether a connection was "established".
        As many connectors are stateless, the "establishment of a connection" might
        just mean that the target and credentials are adequate to post a request and
        receive a non-error response.
     }
    problem = "All descendants of the VCSConnection class need to implement connect()"
    raise NotImplementedError, problem 
end

#disconnectObject

Raises:

  • (NotImplementedError)


101
102
103
104
105
106
107
108
109
110
# File 'lib/vcseif/connection.rb', line 101

def disconnect()
    """
        Returns true or false depending on whether an existing connection was disconnected
        successfully.
        As many connectors are stateless, the disconnection may be as easy as 
        resetting an instance variable to None
    """
    problem = "All descendants of the VCSConnection class need to implement disconnect()"
    raise NotImplementedError, problem
end

#get_file_rev_uri(revision_number, filepath, operation = nil) ⇒ Object



170
171
172
173
174
# File 'lib/vcseif/connection.rb', line 170

def get_file_rev_uri(revision_number, filepath, operation = nil)
  return nil if @file_uri.nil?
  file_uri = @file_uri.gsub(REVNUM_TOKEN, revision_number)
  file_uri.gsub(REVFILE_TOKEN, URI::encode(filepath))
end

#get_rev_uri(revision_number) ⇒ Object

look for tokens revnumber and filepath and put in the correct values cgit here: commit: git.company.com/cgit/reponame.git/commit/?id=revnumber file: git.company.com/cgit/reponame.git/diff/filepath?id=revnumber github: commit: github.com/reponame/commit/revnumber file: github.com/reponame/blob/revnumber/filepath Mercurial (Hg): commit: hgweb:8000/rev/revnumber file: hgweb:8000/file/revnumber/filepath



165
166
167
168
# File 'lib/vcseif/connection.rb', line 165

def get_rev_uri(revision_number)
  return nil if @rev_uri.nil?
  @rev_uri.gsub(REVNUM_TOKEN, revision_number)
end

#getBackendVersionObject

Raises:

  • (NotImplementedError)


85
86
87
88
# File 'lib/vcseif/connection.rb', line 85

def getBackendVersion()
    problem = "All descendants of the VCSConnection class need to implement getBackendVersion()"
    raise NotImplementedError, problem
end

#getRecentChangesets(ref_time) ⇒ Object

Raises:

  • (NotImplementedError)


140
141
142
143
144
145
146
147
148
149
# File 'lib/vcseif/connection.rb', line 140

def getRecentChangesets(ref_time)
    """
        Finds items that have been created since a reference time (ref_time is in UTC) 
        and applying all specified ChangesetSelector conditions.

        Concrete subclasses must implement this method and return a list of qualified items.
    """
    problem = "All descendants of the VCSConnection class need to implement getRecentChangesets(ref_time)"
    raise NotImplementedError, problem
end

#is_windows?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/vcseif/connection.rb', line 151

def is_windows?
  RUBY_PLATFORM.downcase.include?("mswin") || RUBY_PLATFORM.downcase.include?("mingw")
end

#nameObject

Raises:

  • (NotImplementedError)


68
69
70
71
72
73
# File 'lib/vcseif/connection.rb', line 68

def name()
    """
        abstract, provider should return a non-empty string with name of the specific connector
    """
    raise NotImplementedError, problem
end

#validateObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vcseif/connection.rb', line 113

def validate()
    satisfactory = true

    if @username_required == true
        if !username || @username.empty?
            @log.error("<Username> is required in the config file")
            satisfactory = false
        else
            @log.debug('%s - user entry "%s" detected in config file' % [self.class.name, @username])
        end
    end

    if @password_required == true
        if !password || @password.empty?
            @log.error("<Password> is required in the config file")
            satisfactory = false
        else
            @log.debug('%s - password entry detected in config file' % self.class.name)
        end
    end

    satisfactory = hasValidChangesetSelectors() if satisfactory

    return satisfactory
end

#versionObject

Placeholder to put the version of the connector

Raises:

  • (NotImplementedError)


76
77
78
79
80
81
82
83
# File 'lib/vcseif/connection.rb', line 76

def version()
    """
        abstract, provider should return a non-empty string with version 
        identification of the specific connector
    """
    problem = "All descendants of the VCSConnection class need to implement version()"
    raise NotImplementedError, problem
end