Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mock.MagicMock(side_effect=pygit2.GitError),
)
def test_passing(self):
""" Test get_remote_repo_path in pagure. """
output = pagure.utils.get_remote_repo_path(
os.path.join(self.path, "repos", "test2.git"),
"master",
ignore_non_exist=True,
)
self.assertTrue(output.endswith("repos_test2.git_master"))
for line in reqs_response.text.split('\n'):
if line:
dependencies.append(str(line.split('==')[0]))
# Clone the repository
repo_dir = os.path.join(repos_dir, repo_name)
formula_name = repo_name.rsplit('-', 1)[0]
git_repo = None
try:
if os.path.exists(repo_dir):
git_repo = pygit2.Repository(repo_dir)
else:
print 'Cloning %s:' % repo['git_url'],
git_repo = pygit2.clone_repository(repo['git_url'], repo_dir)
print 'Done!'
except pygit2.GitError, e:
if 'Repository not found' in e.message:
print 'Repository not found or repository is private'
continue
# Create metadata branch unless it already exists.
if 'refs/remotes/origin/metadata' not in git_repo.listall_references():
try:
git_repo.create_branch('metadata', git_repo.head.get_object())
except ValueError, e:
pass
git_repo.checkout('refs/heads/metadata')
else:
git_repo.checkout('refs/remotes/origin/metadata')
with open('{0}/metadata.yml'.format(repo_dir), 'w') as formula_meta:
out = {'dependencies': dependencies}
def sync_remote_list(directory):
quoted_directory = shlex.quote(directory)
commands = []
try:
repo = pygit2.Repository(directory)
except pygit2.GitError:
commands.append("git init %s\n" % (quoted_directory,))
current_remotes = {}
else:
current_remotes = {remote.name : git_sort.RepoURL(remote.url)
for remote in repo.remotes}
commands.append("cd %s\n" % (quoted_directory,))
new_remotes = collections.OrderedDict(
((transform(str(head.repo_url)), head.repo_url,)
for head in git_sort.remotes))
# modify existing remotes whose url has changed
commands.extend(["git remote set-url %s %s\n" % (
shlex.quote(name), shlex.quote(repr(repo_url)),)
for name, repo_url in new_remotes.items()
GIT_CLONE_PATH = '/tmp/gitalizer'
GIT_USER_SCAN_THREADS = 4
GIT_COMMIT_SCAN_THREADS = 4
MAX_REPOSITORY_SIZE = 1024 * 1024 * 10
GITHUB_USER_SKIP_COUNT = 3000
REPOSITORY_RESCAN_TIMEOUT = timedelta(days=5)
CONTRIBUTER_RESCAN_TIMEOUT = timedelta(days=14)
SENTRY = False
SENTRY_CONFIG = {
'ignore_exceptions': [
KeyboardInterrupt,
GitError,
],
'exclude_paths': [
'plot',
],
}
PLOT_DIR = './plots'
LOG_DIR = './logs'
# SQLAlchemy options
SQLALCHEMY_DATABASE_URI = 'postgres://localhost/gitalizer'
SQLALCHEMY_ECHO = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
CORS_ALLOW_ORIGIN = '*'
CORS_ALLOW_METHODS = '*'
def push(self):
callbacks = GitRemoteCallbacks(self.github_token)
try:
self.origin.push(self._updated_refs, callbacks=callbacks)
except pygit2.GitError:
raise RuntimeError('Failed to push updated references, '
'potentially because of credential issues: {}'
.format(self._updated_refs))
else:
self.updated_refs = []
def get_authors(repo):
try:
target = repo.head.target
except GitError:
return ()
else:
return (commit.author for commit in repo.walk(target, GIT_SORT_NONE)) # pylint: disable=E1103
head = None
cnt = 0
last_commits = []
tree = []
if not repo_obj.is_empty:
try:
for commit in repo_obj.walk(
repo_obj.head.target, pygit2.GIT_SORT_NONE
):
last_commits.append(commit)
cnt += 1
if cnt == 3:
break
tree = sorted(last_commits[0].tree, key=lambda x: x.filemode)
except pygit2.GitError:
pass
readme = None
safe = False
if not repo_obj.is_empty and not repo_obj.head_is_unborn:
branchname = repo_obj.head.shorthand
else:
branchname = None
project = pagure.lib.query.get_authorized_project(
flask.g.session, repo, user=username, namespace=namespace
)
watch_users = set()
watch_users.add(project.user.username)
for access_type in project.access_users.keys():
for user in project.access_users[access_type]:
def __init__(self, config):
"""Construct new sentry wrapper."""
if config['develop']['sentry_token'] is not None \
and config['develop'].getboolean('sentry_enabled'):
self.initialized = True
self.sentry = Client(
config['develop']['sentry_token'],
ignore_exceptions=[
KeyboardInterrupt,
GitError,
],
def __init__(self, path, url, parent=None):
QtCore.QObject.__init__(self, parent)
assert url
assert path
self.path = path
self.url = url
logger.info("Opening repository at " + self.path)
if not os.path.exists(self.path):
self.repo = pygit2.init_repository(self.path)
else:
if not os.path.exists(os.path.join(self.path, ".git")):
raise pygit2.GitError(self.path + " doesn't seem to be a git repo. libgit2 might crash.")
self.repo = pygit2.Repository(self.path)
if not "faf" in self.remote_names:
logger.info("Adding remote 'faf' " + self.path)
self.repo.create_remote("faf", self.url)
def push(self, branch='master', remote_name='origin'):
repo = self.repo
try:
remote = repo.remotes[remote_name]
remote.push(['refs/heads/' + branch], callbacks=self.callback)
return True
except pygit2.GitError as err:
msg = 'Could not push: {0}'.format(err)
print(msg)
if self.logger:
logger.error(msg)
return False