def getUpdates(self, last_updates): current_version = Version(self.current_version) current_updates_r = self.filterPossibleVersions( current_version=current_version, last_updates=last_updates) url = "{}{}/tags/list".format(Repository.API_BASE, self.repository) data = self._requestData(url, self.token) for tag in data['tags']: version = Version.parseVersionString(tag, self.pattern) if version is None: continue self.updateCurrentUpdates(version=version, current_updates_r=current_updates_r, tag=tag) if self.isNewUpdate(version=version, current_updates_r=current_updates_r, current_version=current_version): update_time = self._getCreationDate(tag) self.registerNewUpdate(current_updates_r=current_updates_r, version=version, date=update_time, tag=tag) new_updates_r = self.convertUpdates( current_updates_r=current_updates_r, project=self.repository) return new_updates_r
def filterPossibleVersions(self,current_version,last_updates): current_updates_r = {} if last_updates is not None: for last_update in last_updates: version = Version(last_update['version']) if current_version.compare(version) < 1: continue current_updates_r[version.getBranchString()] = [ version, last_update['date'], None ] return current_updates_r
def getCurrentVersion(self): branch = Version(self.current_version).getBranchString() creationDate = self._getCreationDate(self.current_tag) return self.createUpdate(version=self.current_version, branch=branch, date=creationDate, url=self._getUpdateUrl(self.current_tag))
def getCurrentVersion(self): branch = Version(self.current_version).getBranchString( ) if self.tag != None else 'master' commit_url = "{}{}/commits/{}".format( Repository.API_BASE, self.project, self.current_version if self.tag is None else self.tag) commit_data = self._requestData(commit_url) return self.createUpdate(version=self.current_version, branch=branch, date=commit_data['commit']['author']['date'], url=self._getUpdateUrl(self.tag))
def __init__(self, plugin_config, global_config): self.repository = plugin_config['repository'] if self.repository.find("/") == -1: self.repository = "library/{}".format(self.repository) self.pattern = plugin_config['pattern'] if Repository.repositories is None: Repository.repositories = {} result = subprocess.run(["/usr/bin/docker image list"], shell=True, check=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=None) lines = result.stdout.decode("utf-8").split("\n") for line in lines: columns = line.split() if len(columns) == 0: continue if columns[0] not in Repository.repositories: Repository.repositories[columns[0]] = [] Repository.repositories[columns[0]].append({ 'tag': columns[1], 'image': columns[2] }) data_r = Repository.repositories[plugin_config['repository']] version = None tag = None tag_r = [] for data in data_r: _version = Version.parseVersionString(data['tag'], self.pattern) if _version is not None and (version is None or version.compare(_version) == 1): version = _version tag = data['tag'] tag_r.append(data['tag']) if version: self.current_version = version.getVersionString() self.current_tag = tag else: raise Exception( 'Can\'t find current version with pattern \'{}\'. Available versions are {}' .format(self.pattern, tag_r)) url = "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{}:pull".format( self.repository) token_result = self._requestData(url) self.token = token_result['token']
def __init__(self, plugin_config, global_config): self.access_token = global_config['github_access_token'] self.project = plugin_config['project'] self.pattern = plugin_config[ 'pattern'] if 'pattern' in plugin_config else None if self.pattern != None: version = Version.parseVersionString(plugin_config['version'], self.pattern) if version != None: self.tag = plugin_config['version'] self.current_version = version.getVersionString() else: raise Exception( 'Can\'t parse version \'{}\' with pattern \'{}\''.format( plugin_config['version'], self.pattern)) else: self.tag = None self.current_version = plugin_config['version']
def getUpdates(self, last_updates): new_updates_r = {} if self.pattern != None: current_version = Version(self.current_version) current_updates_r = self.filterPossibleVersions( current_version=current_version, last_updates=last_updates) url = "{}{}/tags".format(Repository.API_BASE, self.project) data = self._requestData(url) for tag in data: version = Version.parseVersionString(tag['name'], self.pattern) if version is None: continue self.updateCurrentUpdates(version=version, current_updates_r=current_updates_r, tag=tag['name']) if self.isNewUpdate(version=version, current_updates_r=current_updates_r, current_version=current_version): commit_data = self._requestData(tag['commit']['url']) self.registerNewUpdate( current_updates_r=current_updates_r, version=version, date=commit_data['commit']['author']['date'], tag=tag['name']) new_updates_r = self.convertUpdates( current_updates_r=current_updates_r, project=self.project) else: current_update = last_updates[ 0] if last_updates is not None and len( last_updates) > 0 else None total_commits = 0 url = '{}{}/compare/{}...master'.format(Repository.API_BASE, self.project, self.current_version) data = self._requestData(url) total_commits = data['total_commits'] if total_commits > 0: version = "{} commits".format(total_commits) if current_update != None and current_update[ 'version'] == version: new_updates_r['master'] = current_update else: commit_url = '{}{}/commits/master'.format( Repository.API_BASE, self.project) commit_data = self._requestData(commit_url) new_updates_r['master'] = self.createUpdate( version=version, branch='master', date=commit_data['commit']['author']['date'], url=self._getUpdateUrl()) return new_updates_r