{"action":"created","comment":{"url":"https://api.github.com/repos/guykisel/inline-plz/pulls/comments/56435975","id":56435975,"diff_hunk":"@@ -0,0 +1,90 @@\n+# -*- coding: utf-8 -*-\n+from __future__ import absolute_import\n+\n+import stashy\n+import unidiff\n+\n+from inlineplz.interfaces.base import InterfaceBase\n+from inlineplz.util import git\n+\n+\n+class StashInterface(InterfaceBase):\n+    def __init__(self, project, repo, pr, username, password, url=None):\n+        # TODO: support non-PR runs\n+        try:\n+            pr = int(pr)\n+        except ValueError:\n+            return\n+        if not url:\n+            return\n+        else:\n+            self.stash = stashy.connect(url, username=username, password=password, verify=False)\n+        self.pull_request = self.stash.projects[project].repos[repo].pull_requests[pr]\n+        self.commits = [c for c in self.pull_request.commits()]\n+        self.last_sha = self.commits[0]['id']\n+        self.first_sha = self.commits[-1]['id']\n+        self.parent_sha = self.commits[-1]['parents'][0]['id']\n+        self.diff = git.diff(self.parent_sha, self.last_sha)\n+\n+    def post_messages(self, messages, max_comments):\n+        # TODO: support non-PR runs\n+        if not self.stash:\n+            return\n+        messages_to_post = 0\n+        messages_posted = 0\n+        for msg in messages:\n+            if not msg.comments:\n+                continue\n+            msg_position = self.position(msg)\n+            if msg_position:\n+                messages_to_post += 1\n+                if not self.is_duplicate(msg, msg_position):\n+                    self.pull_request.comment(\n+                        self.format_message(msg),\n+                        srcPath=msg.path,\n+                        fileLine=msg_position,\n+                        lineType='ADDED',\n+                        fileType='TO'\n+                    )\n+                    messages_posted += 1\n+                    if max_comments >= 0 and messages_posted > max_comments:\n+                        break\n+        return messages_to_post\n+\n+    def is_duplicate(self, message, position):\n+        for comment in self.pull_request.comments(message.path):\n+            if ('anchor' in comment and\n+                    'line' in comment['anchor'] and\n+                    comment['anchor']['line'] == position and\n+                    comment['text'].strip() == self.format_message(message).strip()):\n+                return True\n+        return False\n+\n+    @staticmethod\n+    def format_message(message):","path":"inlineplz/interfaces/stash.py","position":67,"original_position":64,"commit_id":"235eee4adf32a6c82a75ae5f8d511ed689572906","original_commit_id":"0a2d7e23beba53e7fb26a505d631bf57e79d7d46","user":{"login":"guykisel","id":6760519,"avatar_url":"https://avatars.githubusercontent.com/u/6760519?v=3","gravatar_id":"","url":"https://api.github.com/users/guykisel","html_url":"https://github.com/guykisel","followers_url":"https://api.github.com/users/guykisel/followers","following_url":"https://api.github.com/users/guykisel/following{/other_user}","gists_url":"https://api.github.com/users/guykisel/gists{/gist_id}","starred_url":"https://api.github.com/users/guykisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guykisel/subscriptions","organizations_url":"https://api.github.com/users/guykisel/orgs","repos_url":"https://api.github.com/users/guykisel/repos","events_url":"https://api.github.com/users/guykisel/events{/privacy}","received_events_url":"https://api.github.com/users/guykisel/received_events","type":"User","site_admin":false},"body":"ah i didn't notice the difference, nevermind","created_at":"2016-03-16T23:51:15Z","updated_at":"2016-03-16T23:51:15Z","html_url":"https://github.com/guykisel/inline-plz/pull/106#discussion_r56435975","pull_request_url":"https://api.github.com/repos/guykisel/inline-plz/pulls/106","_links":{"self":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/comments/56435975"},"html":{"href":"https://github.com/guykisel/inline-plz/pull/106#discussion_r56435975"},"pull_request":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/106"}}},"pull_request":{"url":"https://api.github.com/repos/guykisel/inline-plz/pulls/106","id":63119471,"html_url":"https://github.com/guykisel/inline-plz/pull/106","diff_url":"https://github.com/guykisel/inline-plz/pull/106.diff","patch_url":"https://github.com/guykisel/inline-plz/pull/106.patch","issue_url":"https://api.github.com/repos/guykisel/inline-plz/issues/106","number":106,"state":"open","locked":false,"title":"Stash interface","user":{"login":"raphaelcastaneda","id":8203485,"avatar_url":"https://avatars.githubusercontent.com/u/8203485?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelcastaneda","html_url":"https://github.com/raphaelcastaneda","followers_url":"https://api.github.com/users/raphaelcastaneda/followers","following_url":"https://api.github.com/users/raphaelcastaneda/following{/other_user}","gists_url":"https://api.github.com/users/raphaelcastaneda/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelcastaneda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelcastaneda/subscriptions","organizations_url":"https://api.github.com/users/raphaelcastaneda/orgs","repos_url":"https://api.github.com/users/raphaelcastaneda/repos","events_url":"https://api.github.com/users/raphaelcastaneda/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelcastaneda/received_events","type":"User","site_admin":false},"body":"Added interface for Atlassian Stash","created_at":"2016-03-16T19:10:08Z","updated_at":"2016-03-16T23:51:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"990e901bbd829720f6511cd229950722f19a3a1d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/guykisel/inline-plz/pulls/106/commits","review_comments_url":"https://api.github.com/repos/guykisel/inline-plz/pulls/106/comments","review_comment_url":"https://api.github.com/repos/guykisel/inline-plz/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guykisel/inline-plz/issues/106/comments","statuses_url":"https://api.github.com/repos/guykisel/inline-plz/statuses/235eee4adf32a6c82a75ae5f8d511ed689572906","head":{"label":"guykisel:stash-interface","ref":"stash-interface","sha":"235eee4adf32a6c82a75ae5f8d511ed689572906","user":{"login":"guykisel","id":6760519,"avatar_url":"https://avatars.githubusercontent.com/u/6760519?v=3","gravatar_id":"","url":"https://api.github.com/users/guykisel","html_url":"https://github.com/guykisel","followers_url":"https://api.github.com/users/guykisel/followers","following_url":"https://api.github.com/users/guykisel/following{/other_user}","gists_url":"https://api.github.com/users/guykisel/gists{/gist_id}","starred_url":"https://api.github.com/users/guykisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guykisel/subscriptions","organizations_url":"https://api.github.com/users/guykisel/orgs","repos_url":"https://api.github.com/users/guykisel/repos","events_url":"https://api.github.com/users/guykisel/events{/privacy}","received_events_url":"https://api.github.com/users/guykisel/received_events","type":"User","site_admin":false},"repo":{"id":49332088,"name":"inline-plz","full_name":"guykisel/inline-plz","owner":{"login":"guykisel","id":6760519,"avatar_url":"https://avatars.githubusercontent.com/u/6760519?v=3","gravatar_id":"","url":"https://api.github.com/users/guykisel","html_url":"https://github.com/guykisel","followers_url":"https://api.github.com/users/guykisel/followers","following_url":"https://api.github.com/users/guykisel/following{/other_user}","gists_url":"https://api.github.com/users/guykisel/gists{/gist_id}","starred_url":"https://api.github.com/users/guykisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guykisel/subscriptions","organizations_url":"https://api.github.com/users/guykisel/orgs","repos_url":"https://api.github.com/users/guykisel/repos","events_url":"https://api.github.com/users/guykisel/events{/privacy}","received_events_url":"https://api.github.com/users/guykisel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/guykisel/inline-plz","description":"Inline your lint messages","fork":false,"url":"https://api.github.com/repos/guykisel/inline-plz","forks_url":"https://api.github.com/repos/guykisel/inline-plz/forks","keys_url":"https://api.github.com/repos/guykisel/inline-plz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guykisel/inline-plz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guykisel/inline-plz/teams","hooks_url":"https://api.github.com/repos/guykisel/inline-plz/hooks","issue_events_url":"https://api.github.com/repos/guykisel/inline-plz/issues/events{/number}","events_url":"https://api.github.com/repos/guykisel/inline-plz/events","assignees_url":"https://api.github.com/repos/guykisel/inline-plz/assignees{/user}","branches_url":"https://api.github.com/repos/guykisel/inline-plz/branches{/branch}","tags_url":"https://api.github.com/repos/guykisel/inline-plz/tags","blobs_url":"https://api.github.com/repos/guykisel/inline-plz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guykisel/inline-plz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guykisel/inline-plz/git/refs{/sha}","trees_url":"https://api.github.com/repos/guykisel/inline-plz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guykisel/inline-plz/statuses/{sha}","languages_url":"https://api.github.com/repos/guykisel/inline-plz/languages","stargazers_url":"https://api.github.com/repos/guykisel/inline-plz/stargazers","contributors_url":"https://api.github.com/repos/guykisel/inline-plz/contributors","subscribers_url":"https://api.github.com/repos/guykisel/inline-plz/subscribers","subscription_url":"https://api.github.com/repos/guykisel/inline-plz/subscription","commits_url":"https://api.github.com/repos/guykisel/inline-plz/commits{/sha}","git_commits_url":"https://api.github.com/repos/guykisel/inline-plz/git/commits{/sha}","comments_url":"https://api.github.com/repos/guykisel/inline-plz/comments{/number}","issue_comment_url":"https://api.github.com/repos/guykisel/inline-plz/issues/comments{/number}","contents_url":"https://api.github.com/repos/guykisel/inline-plz/contents/{+path}","compare_url":"https://api.github.com/repos/guykisel/inline-plz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guykisel/inline-plz/merges","archive_url":"https://api.github.com/repos/guykisel/inline-plz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guykisel/inline-plz/downloads","issues_url":"https://api.github.com/repos/guykisel/inline-plz/issues{/number}","pulls_url":"https://api.github.com/repos/guykisel/inline-plz/pulls{/number}","milestones_url":"https://api.github.com/repos/guykisel/inline-plz/milestones{/number}","notifications_url":"https://api.github.com/repos/guykisel/inline-plz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guykisel/inline-plz/labels{/name}","releases_url":"https://api.github.com/repos/guykisel/inline-plz/releases{/id}","deployments_url":"https://api.github.com/repos/guykisel/inline-plz/deployments","created_at":"2016-01-09T16:37:10Z","updated_at":"2016-02-29T08:16:10Z","pushed_at":"2016-03-16T22:58:07Z","git_url":"git://github.com/guykisel/inline-plz.git","ssh_url":"git@github.com:guykisel/inline-plz.git","clone_url":"https://github.com/guykisel/inline-plz.git","svn_url":"https://github.com/guykisel/inline-plz","homepage":null,"size":343,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":27,"forks":2,"open_issues":27,"watchers":7,"default_branch":"master"}},"base":{"label":"guykisel:master","ref":"master","sha":"c9d935f1487efbfef4ea164d31a625d48ed422ae","user":{"login":"guykisel","id":6760519,"avatar_url":"https://avatars.githubusercontent.com/u/6760519?v=3","gravatar_id":"","url":"https://api.github.com/users/guykisel","html_url":"https://github.com/guykisel","followers_url":"https://api.github.com/users/guykisel/followers","following_url":"https://api.github.com/users/guykisel/following{/other_user}","gists_url":"https://api.github.com/users/guykisel/gists{/gist_id}","starred_url":"https://api.github.com/users/guykisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guykisel/subscriptions","organizations_url":"https://api.github.com/users/guykisel/orgs","repos_url":"https://api.github.com/users/guykisel/repos","events_url":"https://api.github.com/users/guykisel/events{/privacy}","received_events_url":"https://api.github.com/users/guykisel/received_events","type":"User","site_admin":false},"repo":{"id":49332088,"name":"inline-plz","full_name":"guykisel/inline-plz","owner":{"login":"guykisel","id":6760519,"avatar_url":"https://avatars.githubusercontent.com/u/6760519?v=3","gravatar_id":"","url":"https://api.github.com/users/guykisel","html_url":"https://github.com/guykisel","followers_url":"https://api.github.com/users/guykisel/followers","following_url":"https://api.github.com/users/guykisel/following{/other_user}","gists_url":"https://api.github.com/users/guykisel/gists{/gist_id}","starred_url":"https://api.github.com/users/guykisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guykisel/subscriptions","organizations_url":"https://api.github.com/users/guykisel/orgs","repos_url":"https://api.github.com/users/guykisel/repos","events_url":"https://api.github.com/users/guykisel/events{/privacy}","received_events_url":"https://api.github.com/users/guykisel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/guykisel/inline-plz","description":"Inline your lint messages","fork":false,"url":"https://api.github.com/repos/guykisel/inline-plz","forks_url":"https://api.github.com/repos/guykisel/inline-plz/forks","keys_url":"https://api.github.com/repos/guykisel/inline-plz/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guykisel/inline-plz/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guykisel/inline-plz/teams","hooks_url":"https://api.github.com/repos/guykisel/inline-plz/hooks","issue_events_url":"https://api.github.com/repos/guykisel/inline-plz/issues/events{/number}","events_url":"https://api.github.com/repos/guykisel/inline-plz/events","assignees_url":"https://api.github.com/repos/guykisel/inline-plz/assignees{/user}","branches_url":"https://api.github.com/repos/guykisel/inline-plz/branches{/branch}","tags_url":"https://api.github.com/repos/guykisel/inline-plz/tags","blobs_url":"https://api.github.com/repos/guykisel/inline-plz/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guykisel/inline-plz/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guykisel/inline-plz/git/refs{/sha}","trees_url":"https://api.github.com/repos/guykisel/inline-plz/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guykisel/inline-plz/statuses/{sha}","languages_url":"https://api.github.com/repos/guykisel/inline-plz/languages","stargazers_url":"https://api.github.com/repos/guykisel/inline-plz/stargazers","contributors_url":"https://api.github.com/repos/guykisel/inline-plz/contributors","subscribers_url":"https://api.github.com/repos/guykisel/inline-plz/subscribers","subscription_url":"https://api.github.com/repos/guykisel/inline-plz/subscription","commits_url":"https://api.github.com/repos/guykisel/inline-plz/commits{/sha}","git_commits_url":"https://api.github.com/repos/guykisel/inline-plz/git/commits{/sha}","comments_url":"https://api.github.com/repos/guykisel/inline-plz/comments{/number}","issue_comment_url":"https://api.github.com/repos/guykisel/inline-plz/issues/comments{/number}","contents_url":"https://api.github.com/repos/guykisel/inline-plz/contents/{+path}","compare_url":"https://api.github.com/repos/guykisel/inline-plz/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guykisel/inline-plz/merges","archive_url":"https://api.github.com/repos/guykisel/inline-plz/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guykisel/inline-plz/downloads","issues_url":"https://api.github.com/repos/guykisel/inline-plz/issues{/number}","pulls_url":"https://api.github.com/repos/guykisel/inline-plz/pulls{/number}","milestones_url":"https://api.github.com/repos/guykisel/inline-plz/milestones{/number}","notifications_url":"https://api.github.com/repos/guykisel/inline-plz/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guykisel/inline-plz/labels{/name}","releases_url":"https://api.github.com/repos/guykisel/inline-plz/releases{/id}","deployments_url":"https://api.github.com/repos/guykisel/inline-plz/deployments","created_at":"2016-01-09T16:37:10Z","updated_at":"2016-02-29T08:16:10Z","pushed_at":"2016-03-16T22:58:07Z","git_url":"git://github.com/guykisel/inline-plz.git","ssh_url":"git@github.com:guykisel/inline-plz.git","clone_url":"https://github.com/guykisel/inline-plz.git","svn_url":"https://github.com/guykisel/inline-plz","homepage":null,"size":343,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":27,"forks":2,"open_issues":27,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/106"},"html":{"href":"https://github.com/guykisel/inline-plz/pull/106"},"issue":{"href":"https://api.github.com/repos/guykisel/inline-plz/issues/106"},"comments":{"href":"https://api.github.com/repos/guykisel/inline-plz/issues/106/comments"},"review_comments":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/106/comments"},"review_comment":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guykisel/inline-plz/pulls/106/commits"},"statuses":{"href":"https://api.github.com/repos/guykisel/inline-plz/statuses/235eee4adf32a6c82a75ae5f8d511ed689572906"}}}}