{"action":"created","comment":{"url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/comments/26210129","id":26210129,"diff_hunk":"@@ -0,0 +1,90 @@\n+from git import * \n+from github import Github\n+from core.models import FAQ\n+import glob, os\n+from markdown import Markdown\n+from django.conf import settings\n+from django.utils.translation import ugettext as _\n+\n+# TODO: Handle git errors\n+class FAQManagement:\n+\tdef update_faq():\n+\t\t# Update FAQ repository\n+\t\tfaq_repo = Repo('content/faq')\n+\t\tfaq_repo.remote().pull()\n+\n+\t\t# Reset consistency status of all FAQ questions.\n+\t\t# If no question exists for an question entry, the question will \n+\t\t# remain inconsistent and is not shown in the FAQ. \n+\t\t# It could be aded later again, the author information will remain.\n+\t\tfor question in FAQ.objects.all():\n+\t\t\tquestion.consistent = False\n+\t\t\tquestion.save()\n+\t\t\n+\t\tsource_files = glob.glob('content/faq/*.md')\n+\t\tmd = Markdown()\n+\t\tfor source_path in source_files:\n+\t\t\t# Get filename without extension (.md)\n+\t\t\tfile_name = os.path.basename(source_path)[:-3]\n+\n+\t\t\t# Check for database consistency\n+\t\t\ttry:\n+\t\t\t\tquestion = FAQ.objects.get(slug=file_name)\n+\t\t\t\tquestion.consistent = True\n+\t\t\t\tquestion.save()\n+\t\t\texcept FAQ.DoesNotExist:\n+\t\t\t\t# Question was added directly in the repository\n+\t\t\t\t# Assume, that this question was authored by ZUKS\n+\t\t\t\tFAQ.objects.create( text=file_name,\n+\t\t\t\t\t\t\t\t\tslug=file_name,\n+\t\t\t\t\t\t\t\t\tauthor=_(\"ZUKS\"),\n+\t\t\t\t\t\t\t\t\temail=_(\"@zuks-mail\"),\n+\t\t\t\t\t\t\t\t\ttwitter_handle=_(\"@zuks-twitter\"),\n+\t\t\t\t\t\t\t\t\tconsistent=True)\n+\n+\t\t\t# Convert markdown to html files\n+\t\t\ttarget_path = 'templates/core/faq/%s.html' % (file_name,)\n+\t\t\twith open(source_path, 'r') as source, open(target_path, 'w') as target:\n+\t\t\t\thtml = md.convert(source.read())\n+\t\t\t\ttarget.write(html)\n+\n+\tdef push_question(question):\n+\t\t# Create a new branch for the question\n+\t\tlocalRepo = Repo('content/faq')\n+\n+\t\tquestionBranch = Head.create(localRepo, question.slug)\n+\t\tquestionBranch.checkout()\n+\n+\t\t# Write the markdown file\n+\t\ttarget_path = 'content/faq/%s.md' % (question.slug,)\n+\t\twith open(target_path, 'w') as target:\n+\t\t\ttarget.write('## %s' % (question.text,))\n+\n+\t\t# Commit the markdown file\n+\t\tlocalRepo.index.add(['%s.md' % (question.slug,)])\n+\t\tcommit_message = 'Added question'\n+\t\tif question.author:\n+\t\t\tcommit_message += ' by %s' % (question.author,)\n+\t\tlocalRepo.index.commit(commit_message)\n+\t\t\n+\t\t# Push new branch\n+\t\tlocalRepo.remote().push(questionBranch)\n+\n+\t\t# Create a pull request for the new branch\n+\t\tgitHub = Github(settings.GITHUB_TOKEN)\n+\n+\t\tif settings.GITHUB_ORGANISATION:\n+\t\t\tuser = gitHub.get_organization(settings.GITHUB_ORGANISATION)\n+\t\telse:\n+\t\t\tuser = gitHub.get_organization(settings.GITHUB_USER)\n+\t\trepo = user.get_repo(settings.GITHUB_REPOSITORY)\n+\n+\t\tpull_text = 'New question authered'","path":"core/faq_management.py","position":82,"original_position":82,"commit_id":"6ff0c0be8c829dafbc741a55d46bec4b22edc22b","original_commit_id":"6ff0c0be8c829dafbc741a55d46bec4b22edc22b","user":{"login":"monofox","id":765309,"avatar_url":"https://avatars.githubusercontent.com/u/765309?v=3","gravatar_id":"","url":"https://api.github.com/users/monofox","html_url":"https://github.com/monofox","followers_url":"https://api.github.com/users/monofox/followers","following_url":"https://api.github.com/users/monofox/following{/other_user}","gists_url":"https://api.github.com/users/monofox/gists{/gist_id}","starred_url":"https://api.github.com/users/monofox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monofox/subscriptions","organizations_url":"https://api.github.com/users/monofox/orgs","repos_url":"https://api.github.com/users/monofox/repos","events_url":"https://api.github.com/users/monofox/events{/privacy}","received_events_url":"https://api.github.com/users/monofox/received_events","type":"User","site_admin":false},"body":"authered? ","created_at":"2015-03-11T13:13:50Z","updated_at":"2015-03-11T13:13:50Z","html_url":"https://github.com/ZUKSev/ZUKS-Website/pull/35#discussion_r26210129","pull_request_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/comments/26210129"},"html":{"href":"https://github.com/ZUKSev/ZUKS-Website/pull/35#discussion_r26210129"},"pull_request":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35","id":30728203,"html_url":"https://github.com/ZUKSev/ZUKS-Website/pull/35","diff_url":"https://github.com/ZUKSev/ZUKS-Website/pull/35.diff","patch_url":"https://github.com/ZUKSev/ZUKS-Website/pull/35.patch","issue_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/35","number":35,"state":"open","locked":false,"title":"WIP: FAQ","user":{"login":"Eldorado234","id":571090,"avatar_url":"https://avatars.githubusercontent.com/u/571090?v=3","gravatar_id":"","url":"https://api.github.com/users/Eldorado234","html_url":"https://github.com/Eldorado234","followers_url":"https://api.github.com/users/Eldorado234/followers","following_url":"https://api.github.com/users/Eldorado234/following{/other_user}","gists_url":"https://api.github.com/users/Eldorado234/gists{/gist_id}","starred_url":"https://api.github.com/users/Eldorado234/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eldorado234/subscriptions","organizations_url":"https://api.github.com/users/Eldorado234/orgs","repos_url":"https://api.github.com/users/Eldorado234/repos","events_url":"https://api.github.com/users/Eldorado234/events{/privacy}","received_events_url":"https://api.github.com/users/Eldorado234/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-08T22:37:37Z","updated_at":"2015-03-11T13:13:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b134714454693eedc362bb5024f4e6e07ed859d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35/commits","review_comments_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35/comments","review_comment_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/35/comments","statuses_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/statuses/6ff0c0be8c829dafbc741a55d46bec4b22edc22b","head":{"label":"ZUKSev:31_faq","ref":"31_faq","sha":"6ff0c0be8c829dafbc741a55d46bec4b22edc22b","user":{"login":"ZUKSev","id":9297037,"avatar_url":"https://avatars.githubusercontent.com/u/9297037?v=3","gravatar_id":"","url":"https://api.github.com/users/ZUKSev","html_url":"https://github.com/ZUKSev","followers_url":"https://api.github.com/users/ZUKSev/followers","following_url":"https://api.github.com/users/ZUKSev/following{/other_user}","gists_url":"https://api.github.com/users/ZUKSev/gists{/gist_id}","starred_url":"https://api.github.com/users/ZUKSev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZUKSev/subscriptions","organizations_url":"https://api.github.com/users/ZUKSev/orgs","repos_url":"https://api.github.com/users/ZUKSev/repos","events_url":"https://api.github.com/users/ZUKSev/events{/privacy}","received_events_url":"https://api.github.com/users/ZUKSev/received_events","type":"Organization","site_admin":false},"repo":{"id":24676697,"name":"ZUKS-Website","full_name":"ZUKSev/ZUKS-Website","owner":{"login":"ZUKSev","id":9297037,"avatar_url":"https://avatars.githubusercontent.com/u/9297037?v=3","gravatar_id":"","url":"https://api.github.com/users/ZUKSev","html_url":"https://github.com/ZUKSev","followers_url":"https://api.github.com/users/ZUKSev/followers","following_url":"https://api.github.com/users/ZUKSev/following{/other_user}","gists_url":"https://api.github.com/users/ZUKSev/gists{/gist_id}","starred_url":"https://api.github.com/users/ZUKSev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZUKSev/subscriptions","organizations_url":"https://api.github.com/users/ZUKSev/orgs","repos_url":"https://api.github.com/users/ZUKSev/repos","events_url":"https://api.github.com/users/ZUKSev/events{/privacy}","received_events_url":"https://api.github.com/users/ZUKSev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ZUKSev/ZUKS-Website","description":"The official ZUKS Website","fork":false,"url":"https://api.github.com/repos/ZUKSev/ZUKS-Website","forks_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/forks","keys_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/teams","hooks_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/hooks","issue_events_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/events{/number}","events_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/events","assignees_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/assignees{/user}","branches_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/branches{/branch}","tags_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/tags","blobs_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/refs{/sha}","trees_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/statuses/{sha}","languages_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/languages","stargazers_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/stargazers","contributors_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/contributors","subscribers_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/subscribers","subscription_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/subscription","commits_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/commits{/sha}","git_commits_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/commits{/sha}","comments_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/comments{/number}","issue_comment_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/comments{/number}","contents_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/contents/{+path}","compare_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/merges","archive_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/downloads","issues_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues{/number}","pulls_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls{/number}","milestones_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/milestones{/number}","notifications_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/labels{/name}","releases_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/releases{/id}","created_at":"2014-10-01T11:57:58Z","updated_at":"2014-10-18T16:57:30Z","pushed_at":"2015-03-09T13:05:07Z","git_url":"git://github.com/ZUKSev/ZUKS-Website.git","ssh_url":"git@github.com:ZUKSev/ZUKS-Website.git","clone_url":"https://github.com/ZUKSev/ZUKS-Website.git","svn_url":"https://github.com/ZUKSev/ZUKS-Website","homepage":"http://www.zuks.org","size":1898,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":0,"default_branch":"master"}},"base":{"label":"ZUKSev:master","ref":"master","sha":"15ab809b56cd532d9763bc4dfbb5b7083733bd9c","user":{"login":"ZUKSev","id":9297037,"avatar_url":"https://avatars.githubusercontent.com/u/9297037?v=3","gravatar_id":"","url":"https://api.github.com/users/ZUKSev","html_url":"https://github.com/ZUKSev","followers_url":"https://api.github.com/users/ZUKSev/followers","following_url":"https://api.github.com/users/ZUKSev/following{/other_user}","gists_url":"https://api.github.com/users/ZUKSev/gists{/gist_id}","starred_url":"https://api.github.com/users/ZUKSev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZUKSev/subscriptions","organizations_url":"https://api.github.com/users/ZUKSev/orgs","repos_url":"https://api.github.com/users/ZUKSev/repos","events_url":"https://api.github.com/users/ZUKSev/events{/privacy}","received_events_url":"https://api.github.com/users/ZUKSev/received_events","type":"Organization","site_admin":false},"repo":{"id":24676697,"name":"ZUKS-Website","full_name":"ZUKSev/ZUKS-Website","owner":{"login":"ZUKSev","id":9297037,"avatar_url":"https://avatars.githubusercontent.com/u/9297037?v=3","gravatar_id":"","url":"https://api.github.com/users/ZUKSev","html_url":"https://github.com/ZUKSev","followers_url":"https://api.github.com/users/ZUKSev/followers","following_url":"https://api.github.com/users/ZUKSev/following{/other_user}","gists_url":"https://api.github.com/users/ZUKSev/gists{/gist_id}","starred_url":"https://api.github.com/users/ZUKSev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZUKSev/subscriptions","organizations_url":"https://api.github.com/users/ZUKSev/orgs","repos_url":"https://api.github.com/users/ZUKSev/repos","events_url":"https://api.github.com/users/ZUKSev/events{/privacy}","received_events_url":"https://api.github.com/users/ZUKSev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ZUKSev/ZUKS-Website","description":"The official ZUKS Website","fork":false,"url":"https://api.github.com/repos/ZUKSev/ZUKS-Website","forks_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/forks","keys_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/teams","hooks_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/hooks","issue_events_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/events{/number}","events_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/events","assignees_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/assignees{/user}","branches_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/branches{/branch}","tags_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/tags","blobs_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/refs{/sha}","trees_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/statuses/{sha}","languages_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/languages","stargazers_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/stargazers","contributors_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/contributors","subscribers_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/subscribers","subscription_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/subscription","commits_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/commits{/sha}","git_commits_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/git/commits{/sha}","comments_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/comments{/number}","issue_comment_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/comments{/number}","contents_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/contents/{+path}","compare_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/merges","archive_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/downloads","issues_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues{/number}","pulls_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls{/number}","milestones_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/milestones{/number}","notifications_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/labels{/name}","releases_url":"https://api.github.com/repos/ZUKSev/ZUKS-Website/releases{/id}","created_at":"2014-10-01T11:57:58Z","updated_at":"2014-10-18T16:57:30Z","pushed_at":"2015-03-09T13:05:07Z","git_url":"git://github.com/ZUKSev/ZUKS-Website.git","ssh_url":"git@github.com:ZUKSev/ZUKS-Website.git","clone_url":"https://github.com/ZUKSev/ZUKS-Website.git","svn_url":"https://github.com/ZUKSev/ZUKS-Website","homepage":"http://www.zuks.org","size":1898,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35"},"html":{"href":"https://github.com/ZUKSev/ZUKS-Website/pull/35"},"issue":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/35"},"comments":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/ZUKSev/ZUKS-Website/statuses/6ff0c0be8c829dafbc741a55d46bec4b22edc22b"}}}}