def travisci_webhook(request): """ Respond to travis-ci webhooks from Project GITenberg repositories. If the webhook is successfully parsed, the metdata.yaml for the repository is loaded using load_from_yaml. https://docs.travis-ci.com/user/notifications/#Webhook-notification """ if request.method == "POST": try: data = json_module.loads(request.POST.get('payload')) # example of URL to feed to yaml loader: # https://github.com/GITenberg/Adventures-of-Huckleberry-Finn_76/raw/master/metadata.yaml if data['status_message'] == 'Passed' and data['type'] == 'push': # another way to get owner_name / name would be request.META.get('HTTP_TRAVIS_REPO_SLUG', '') repo_url = "https://github.com/{}/{}/raw/master/metadata.yaml".format(data['repository']['owner_name'], data['repository']['name']) work_id = load_from_yaml(repo_url) return HttpResponse('Successful. work_id: {}'.format(work_id)) except Exception as e: return HttpResponseBadRequest('Unsuccessful. Exception: {}'.format(unicode(e))) else: return HttpResponse('No action') else: return HttpResponse('No action')
def handle(self, **options): problem_ebooks = calc_problem_ebooks() self.stdout.write("number of problem ebooks", len(problem_ebooks)) # deactivate problem ebooks for (i, result) in enumerate(problem_ebooks): ebook = Ebook.objects.get(id=result['id']) self.stdout.write("\r", "deactivating ", i, ebook.id, end="") ebook.deactivate() # reload repos for (i, repo_name) in enumerate( set([ repo_name_from_url(ebook['url']) for ebook in problem_ebooks ])): self.stdout.write("reloading ", repo_name) load_from_yaml(yaml_url(repo_name))
def load_yaml(request): if request.method == "GET": return render(request, 'load_yaml.html', {}) repo_url = request.POST.get('repo_url', None) if not repo_url: return HttpResponse('needs repo_url') (allowed, reason) = repo_allowed(repo_url) if not allowed: return HttpResponse('repo_url not allowed: ' + reason) try: work_id = load_from_yaml(repo_url) return HttpResponseRedirect(reverse('work', args=[work_id])) except: return HttpResponse('unsuccessful')