{"action":"created","comment":{"url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/comments/89505185","pull_request_review_id":10050348,"id":89505185,"diff_hunk":"@@ -0,0 +1,285 @@\n+from JumpScale import j\n+from .utils import chunks\n+import telegram\n+import re\n+\n+AYS_REPO_DIR = j.sal.fs.joinPaths(j.dirs.codeDir, 'cockpit')\n+\n+\n+class RepoMgmt:\n+\n+    def __init__(self, bot):\n+        self.bot = bot\n+        self.rootpath = bot.rootpath\n+        self.callbacks = bot.question_callbacks\n+        self._cuisine = j.tools.cuisine.local\n+        self.reg_repo = re.compile(r'^[a-zA-Z0-9-_]+$')\n+\n+    def init_repo(self, update, bot, name, git_url):\n+        chat_id = update.message.chat_id\n+        bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)\n+\n+        repopath = '%s/%s' % (self.rootpath, name)\n+        self.bot.logger.debug('initializing repository: %s' % repopath)\n+\n+        j.atyourservice.repoCreate(repopath)\n+\n+        if self._cuisine.core.run(\"cd %s && git remote -v\" % repopath)[1]:\n+            self._cuisine.core.run(\"cd %s && git remote set-url origin  %s \" % (repopath, git_url))\n+        else:\n+            self._cuisine.core.run(\"cd %s && git remote add origin  %s \" % (repopath, git_url))\n+        evt = j.data.models.cockpit_event.Telegram()\n+        evt.io = 'input'\n+        evt.action = 'repo.create'\n+        evt.args = {\n+            'repo_path': repopath\n+        }\n+        self.bot.send_event(evt.to_json())\n+\n+    # Helpers\n+    def _userCheck(self, bot, update):\n+        chat_id = update.message.chat_id\n+        valid = True\n+        if self.bot._rediscl.hexists('cockpit.telegram.users', update.message.from_user.username):\n+            data = self.bot._rediscl.hget('cockpit.telegram.users', update.message.from_user.username).decode()\n+            data = j.data.serializer.json.loads(data)\n+            if not data.get('access_token', None):\n+                valid = False\n+        else:\n+            valid = False\n+\n+        if not valid:\n+            self.bot.sendMessage(chat_id=chat_id,\n+                                 text=\"Hello buddy, I don't know you yet, please use /start so we can meet\")\n+\n+        return valid\n+\n+    def _setCurrentRepo(self, username, name):\n+        data = self.bot._rediscl.hget('cockpit.telegram.users', username).decode()\n+        data = j.data.serializer.json.loads(data)\n+        data['current_repo'] = name\n+        self.bot._rediscl.hset('cockpit.telegram.users', username, j.data.serializer.json.dumps(data))\n+\n+    def _currentRepoName(self, username):\n+        data = self.bot._rediscl.hget('cockpit.telegram.users', username).decode()\n+        data = j.data.serializer.json.loads(data)\n+        return data['current_repo']\n+\n+    # Management of repos\n+    def checkout(self, bot, update, repo_name, git_url=''):\n+        self.bot.logger.debug('checking out repo: %s' % repo_name)\n+\n+        chat_id = update.message.chat_id\n+        username = update.message.from_user.username\n+        bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)\n+\n+        # check repo name validity\n+        if not re.search(self.reg_repo, repo_name):\n+            message = \"Sorry, I don't support this repo name, please name it without any special characters or spaces.\"\n+            return self.bot.sendMessage(chat_id=chat_id, text=message)\n+\n+        # repo already exists\n+        path = j.sal.fs.joinPaths(j.dirs.codeDir, 'cockpit', repo_name)","path":"ays_bot/telegrambot/Repo.py","position":null,"original_position":82,"commit_id":"fbe9de890a39412a4421b8806f3f0b8e7ab7f1fa","original_commit_id":"d510c0dfcf6ab7726282bb46061e0ef00830ae1a","user":{"login":"abdulrahmantkhalifa","id":15012414,"avatar_url":"https://avatars.githubusercontent.com/u/15012414?v=3","gravatar_id":"","url":"https://api.github.com/users/abdulrahmantkhalifa","html_url":"https://github.com/abdulrahmantkhalifa","followers_url":"https://api.github.com/users/abdulrahmantkhalifa/followers","following_url":"https://api.github.com/users/abdulrahmantkhalifa/following{/other_user}","gists_url":"https://api.github.com/users/abdulrahmantkhalifa/gists{/gist_id}","starred_url":"https://api.github.com/users/abdulrahmantkhalifa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abdulrahmantkhalifa/subscriptions","organizations_url":"https://api.github.com/users/abdulrahmantkhalifa/orgs","repos_url":"https://api.github.com/users/abdulrahmantkhalifa/repos","events_url":"https://api.github.com/users/abdulrahmantkhalifa/events{/privacy}","received_events_url":"https://api.github.com/users/abdulrahmantkhalifa/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-11-24T14:21:01Z","updated_at":"2016-11-24T14:21:01Z","html_url":"https://github.com/Jumpscale/jscockpit/pull/252#discussion_r89505185","pull_request_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252","_links":{"self":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/comments/89505185"},"html":{"href":"https://github.com/Jumpscale/jscockpit/pull/252#discussion_r89505185"},"pull_request":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252"}}},"pull_request":{"url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252","id":94617005,"html_url":"https://github.com/Jumpscale/jscockpit/pull/252","diff_url":"https://github.com/Jumpscale/jscockpit/pull/252.diff","patch_url":"https://github.com/Jumpscale/jscockpit/pull/252.patch","issue_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/252","number":252,"state":"open","locked":false,"title":"Cockpit chatbot","user":{"login":"abdulrahmantkhalifa","id":15012414,"avatar_url":"https://avatars.githubusercontent.com/u/15012414?v=3","gravatar_id":"","url":"https://api.github.com/users/abdulrahmantkhalifa","html_url":"https://github.com/abdulrahmantkhalifa","followers_url":"https://api.github.com/users/abdulrahmantkhalifa/followers","following_url":"https://api.github.com/users/abdulrahmantkhalifa/following{/other_user}","gists_url":"https://api.github.com/users/abdulrahmantkhalifa/gists{/gist_id}","starred_url":"https://api.github.com/users/abdulrahmantkhalifa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abdulrahmantkhalifa/subscriptions","organizations_url":"https://api.github.com/users/abdulrahmantkhalifa/orgs","repos_url":"https://api.github.com/users/abdulrahmantkhalifa/repos","events_url":"https://api.github.com/users/abdulrahmantkhalifa/events{/privacy}","received_events_url":"https://api.github.com/users/abdulrahmantkhalifa/received_events","type":"User","site_admin":false},"body":" relates to #245","created_at":"2016-11-21T13:41:22Z","updated_at":"2016-11-24T14:21:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1a32109df919a6b0e5a4101f20b4c1c9560b746","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252/commits","review_comments_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252/comments","review_comment_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/252/comments","statuses_url":"https://api.github.com/repos/Jumpscale/jscockpit/statuses/fbe9de890a39412a4421b8806f3f0b8e7ab7f1fa","head":{"label":"Jumpscale:cockpit_chatbot","ref":"cockpit_chatbot","sha":"fbe9de890a39412a4421b8806f3f0b8e7ab7f1fa","user":{"login":"Jumpscale","id":8423908,"avatar_url":"https://avatars.githubusercontent.com/u/8423908?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumpscale","html_url":"https://github.com/Jumpscale","followers_url":"https://api.github.com/users/Jumpscale/followers","following_url":"https://api.github.com/users/Jumpscale/following{/other_user}","gists_url":"https://api.github.com/users/Jumpscale/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumpscale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumpscale/subscriptions","organizations_url":"https://api.github.com/users/Jumpscale/orgs","repos_url":"https://api.github.com/users/Jumpscale/repos","events_url":"https://api.github.com/users/Jumpscale/events{/privacy}","received_events_url":"https://api.github.com/users/Jumpscale/received_events","type":"Organization","site_admin":false},"repo":{"id":52870696,"name":"jscockpit","full_name":"Jumpscale/jscockpit","owner":{"login":"Jumpscale","id":8423908,"avatar_url":"https://avatars.githubusercontent.com/u/8423908?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumpscale","html_url":"https://github.com/Jumpscale","followers_url":"https://api.github.com/users/Jumpscale/followers","following_url":"https://api.github.com/users/Jumpscale/following{/other_user}","gists_url":"https://api.github.com/users/Jumpscale/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumpscale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumpscale/subscriptions","organizations_url":"https://api.github.com/users/Jumpscale/orgs","repos_url":"https://api.github.com/users/Jumpscale/repos","events_url":"https://api.github.com/users/Jumpscale/events{/privacy}","received_events_url":"https://api.github.com/users/Jumpscale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Jumpscale/jscockpit","description":"private neutral management environment for g8 based clouds","fork":false,"url":"https://api.github.com/repos/Jumpscale/jscockpit","forks_url":"https://api.github.com/repos/Jumpscale/jscockpit/forks","keys_url":"https://api.github.com/repos/Jumpscale/jscockpit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jumpscale/jscockpit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jumpscale/jscockpit/teams","hooks_url":"https://api.github.com/repos/Jumpscale/jscockpit/hooks","issue_events_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/events{/number}","events_url":"https://api.github.com/repos/Jumpscale/jscockpit/events","assignees_url":"https://api.github.com/repos/Jumpscale/jscockpit/assignees{/user}","branches_url":"https://api.github.com/repos/Jumpscale/jscockpit/branches{/branch}","tags_url":"https://api.github.com/repos/Jumpscale/jscockpit/tags","blobs_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jumpscale/jscockpit/statuses/{sha}","languages_url":"https://api.github.com/repos/Jumpscale/jscockpit/languages","stargazers_url":"https://api.github.com/repos/Jumpscale/jscockpit/stargazers","contributors_url":"https://api.github.com/repos/Jumpscale/jscockpit/contributors","subscribers_url":"https://api.github.com/repos/Jumpscale/jscockpit/subscribers","subscription_url":"https://api.github.com/repos/Jumpscale/jscockpit/subscription","commits_url":"https://api.github.com/repos/Jumpscale/jscockpit/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jumpscale/jscockpit/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jumpscale/jscockpit/contents/{+path}","compare_url":"https://api.github.com/repos/Jumpscale/jscockpit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jumpscale/jscockpit/merges","archive_url":"https://api.github.com/repos/Jumpscale/jscockpit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jumpscale/jscockpit/downloads","issues_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues{/number}","pulls_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls{/number}","milestones_url":"https://api.github.com/repos/Jumpscale/jscockpit/milestones{/number}","notifications_url":"https://api.github.com/repos/Jumpscale/jscockpit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jumpscale/jscockpit/labels{/name}","releases_url":"https://api.github.com/repos/Jumpscale/jscockpit/releases{/id}","deployments_url":"https://api.github.com/repos/Jumpscale/jscockpit/deployments","created_at":"2016-03-01T11:06:33Z","updated_at":"2016-10-23T11:59:26Z","pushed_at":"2016-11-24T14:17:12Z","git_url":"git://github.com/Jumpscale/jscockpit.git","ssh_url":"git@github.com:Jumpscale/jscockpit.git","clone_url":"https://github.com/Jumpscale/jscockpit.git","svn_url":"https://github.com/Jumpscale/jscockpit","homepage":null,"size":16998,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":34,"forks":1,"open_issues":34,"watchers":0,"default_branch":"master"}},"base":{"label":"Jumpscale:master","ref":"master","sha":"63f012bf9e9502524f631082e8ddd2a92a936d65","user":{"login":"Jumpscale","id":8423908,"avatar_url":"https://avatars.githubusercontent.com/u/8423908?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumpscale","html_url":"https://github.com/Jumpscale","followers_url":"https://api.github.com/users/Jumpscale/followers","following_url":"https://api.github.com/users/Jumpscale/following{/other_user}","gists_url":"https://api.github.com/users/Jumpscale/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumpscale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumpscale/subscriptions","organizations_url":"https://api.github.com/users/Jumpscale/orgs","repos_url":"https://api.github.com/users/Jumpscale/repos","events_url":"https://api.github.com/users/Jumpscale/events{/privacy}","received_events_url":"https://api.github.com/users/Jumpscale/received_events","type":"Organization","site_admin":false},"repo":{"id":52870696,"name":"jscockpit","full_name":"Jumpscale/jscockpit","owner":{"login":"Jumpscale","id":8423908,"avatar_url":"https://avatars.githubusercontent.com/u/8423908?v=3","gravatar_id":"","url":"https://api.github.com/users/Jumpscale","html_url":"https://github.com/Jumpscale","followers_url":"https://api.github.com/users/Jumpscale/followers","following_url":"https://api.github.com/users/Jumpscale/following{/other_user}","gists_url":"https://api.github.com/users/Jumpscale/gists{/gist_id}","starred_url":"https://api.github.com/users/Jumpscale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jumpscale/subscriptions","organizations_url":"https://api.github.com/users/Jumpscale/orgs","repos_url":"https://api.github.com/users/Jumpscale/repos","events_url":"https://api.github.com/users/Jumpscale/events{/privacy}","received_events_url":"https://api.github.com/users/Jumpscale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Jumpscale/jscockpit","description":"private neutral management environment for g8 based clouds","fork":false,"url":"https://api.github.com/repos/Jumpscale/jscockpit","forks_url":"https://api.github.com/repos/Jumpscale/jscockpit/forks","keys_url":"https://api.github.com/repos/Jumpscale/jscockpit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jumpscale/jscockpit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jumpscale/jscockpit/teams","hooks_url":"https://api.github.com/repos/Jumpscale/jscockpit/hooks","issue_events_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/events{/number}","events_url":"https://api.github.com/repos/Jumpscale/jscockpit/events","assignees_url":"https://api.github.com/repos/Jumpscale/jscockpit/assignees{/user}","branches_url":"https://api.github.com/repos/Jumpscale/jscockpit/branches{/branch}","tags_url":"https://api.github.com/repos/Jumpscale/jscockpit/tags","blobs_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jumpscale/jscockpit/statuses/{sha}","languages_url":"https://api.github.com/repos/Jumpscale/jscockpit/languages","stargazers_url":"https://api.github.com/repos/Jumpscale/jscockpit/stargazers","contributors_url":"https://api.github.com/repos/Jumpscale/jscockpit/contributors","subscribers_url":"https://api.github.com/repos/Jumpscale/jscockpit/subscribers","subscription_url":"https://api.github.com/repos/Jumpscale/jscockpit/subscription","commits_url":"https://api.github.com/repos/Jumpscale/jscockpit/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jumpscale/jscockpit/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jumpscale/jscockpit/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jumpscale/jscockpit/contents/{+path}","compare_url":"https://api.github.com/repos/Jumpscale/jscockpit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jumpscale/jscockpit/merges","archive_url":"https://api.github.com/repos/Jumpscale/jscockpit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jumpscale/jscockpit/downloads","issues_url":"https://api.github.com/repos/Jumpscale/jscockpit/issues{/number}","pulls_url":"https://api.github.com/repos/Jumpscale/jscockpit/pulls{/number}","milestones_url":"https://api.github.com/repos/Jumpscale/jscockpit/milestones{/number}","notifications_url":"https://api.github.com/repos/Jumpscale/jscockpit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jumpscale/jscockpit/labels{/name}","releases_url":"https://api.github.com/repos/Jumpscale/jscockpit/releases{/id}","deployments_url":"https://api.github.com/repos/Jumpscale/jscockpit/deployments","created_at":"2016-03-01T11:06:33Z","updated_at":"2016-10-23T11:59:26Z","pushed_at":"2016-11-24T14:17:12Z","git_url":"git://github.com/Jumpscale/jscockpit.git","ssh_url":"git@github.com:Jumpscale/jscockpit.git","clone_url":"https://github.com/Jumpscale/jscockpit.git","svn_url":"https://github.com/Jumpscale/jscockpit","homepage":null,"size":16998,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":34,"forks":1,"open_issues":34,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252"},"html":{"href":"https://github.com/Jumpscale/jscockpit/pull/252"},"issue":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/issues/252"},"comments":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/issues/252/comments"},"review_comments":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252/comments"},"review_comment":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/pulls/252/commits"},"statuses":{"href":"https://api.github.com/repos/Jumpscale/jscockpit/statuses/fbe9de890a39412a4421b8806f3f0b8e7ab7f1fa"}}}}
{"actor":{"display_login":"abdulrahmantkhalifa"}}