def pull(self): """Pull all branches from the repository this instance is assigned to. """ os.chdir('repos/{}'.format(self.repo['title'])) command = 'git pull --all' res = subprocess.run(command, capture_output=True, shell=True) db_log.insert_one({ 'text': command, 'time': datetime.datetime.now(), 'data': { 'repo': self.repo['_id'], 'error': b2s(res.stderr), 'output': b2s(res.stdout) } }) os.chdir(workdir)
def clone(self): """Clone the repository this instance is assigned to. """ os.chdir('repos') command = 'git clone {}'.format(self.repo['url']) res = subprocess.run(command, capture_output=True, shell=True) db_log.insert_one({ 'text': command, 'time': datetime.datetime.now(), 'data': { 'repo': self.repo['_id'], 'error': b2s(res.stderr), 'output': b2s(res.stdout) } }) os.chdir(workdir)
def diff(commit_id, parameters=[]): """Performs a diff operation on two versions of the repository """ os.chdir('repos/{}'.format(REPO['title'])) parameters = ' '.join(parameters) command = 'git diff {}^ {} {}'.format(commit_id, commit_id, parameters) res = subprocess.run(command, capture_output=True, shell=shell) os.chdir(WORKDIR) return b2s(res.stdout).splitlines()
def get_stat(self, file, content): """Run a CLOC analysis on a file, return data as JSON. """ command = 'cloc --json {}'.format(file.name) res = subprocess.run(command, capture_output=True) if res.returncode == 0: string = b2s(res.stdout) if string: return json.loads(string) return {'SUM': {'blank': 0, 'comment': 0, 'code': 0, 'nFiles': 1}}
def log(self): """Return the logs of the repository. """ os.chdir('repos/{}'.format(self.repo['title'])) command = 'git log --numstat --no-merges --date=unix --after={}'.format( self.repo['end']) print(command) res = subprocess.run(command, capture_output=True, shell=True) os.chdir(workdir) return b2s(res.stdout).splitlines()
def log(): """Return the logs of the repository. """ os.chdir('repos/{}'.format(REPO['title'])) command = 'git log --numstat --no-merges --date=unix --after={} --before={}'.format( REPO['after'], REPO['before']) print(command) res = subprocess.run(command, capture_output=True, shell=shell) os.chdir(WORKDIR) return b2s(res.stdout).splitlines()
def show(self, commit_id, path): """Return the contents of a version of a file as a string. """ os.chdir('repos/{}'.format(self.repo['title'])) command = 'git show {}:{}'.format(commit_id, path) res = subprocess.run(command, capture_output=True, shell=True) os.chdir(workdir) if res.returncode == 0: return b2s(res.stdout) else: return ''