def ProcessRepo(request, full_name):
user = request.user
g = get_github(request.user)
grepo = g.get_repo(full_name)
if not grepo.full_name:
raise Http404('Repo not found')
guser = g.get_user(user.username)
is_collab = grepo.has_in_collaborators(guser)
if not is_collab and grepo.private:
raise Http404('You are not a collaborator of this repo')
try:
repo = Repo.objects.get(full_name=grepo.full_name)
repo.disabled = False
repo.is_private = grepo.private
repo.save()
except Repo.DoesNotExist:
repo = Repo.objects.create(
full_name=grepo.full_name,
user=user,
default_branch=grepo.default_branch,
is_private=grepo.private
)
if not repo.webhook_id:
try:
repo.add_webhook(request)
except UnknownObjectException:
raise Http404('Github failed to create a hook')
# Lint all open branches
auth = request.user.get_auth()
for branch in grepo.get_branches():
build, created = Build.objects.get_or_create(
repo=repo,
ref=branch.name,
sha=branch.commit.sha
)
if created:
build.enqueue(auth)
url = reverse('repo_detail', kwargs={'full_name': repo.full_name})
return redirect(url)
评论列表
文章目录