コード例 #1
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def pull_request_review_comment(self, update, context):
        # Pull request diff comment created, edited, or deleted.
        if update.payload['action'] == 'created':
            pull_request = update.payload['pull_request']
            comment = update.payload['comment']
            author = comment['user']
            repo = update.payload['repository']

            diff_hunk = f'<pre>{comment["path"]}\n{comment["diff_hunk"]}</pre>'

            text = render_github_markdown(comment['body'], repo['full_name'])

            issue_link = link(
                comment['html_url'],
                f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}'
            )
            author_link = link(author['html_url'], '@' + author['login'])
            data_link = encode_data_link((
                'pull request review comment',
                repo['full_name'],
                pull_request['number'],
                comment['in_reply_to_id']
                if 'in_reply_to_id' in comment else comment['id'],
                author['login'],
            ))
            text = f'{data_link}💬 New pull request review comment {issue_link}\nby {author_link}\n{diff_hunk}\n\n{text}'

            self._send(repo, text, lambda r: r.pull_review_comments)
コード例 #2
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def issues(self, update, _):
        # Issue opened, edited, closed, reopened, assigned, unassigned, labeled,
        # unlabeled, milestoned, or demilestoned.
        # TODO: Possibly support editing, closing, reopening, etc. of issues
        if update.payload['action'] == 'opened':
            issue = update.payload['issue']
            author = issue['user']
            repo = update.payload['repository']

            text = render_github_markdown(issue['body'], repo['full_name'])

            issue_link = link(
                issue['html_url'],
                f'{repo["full_name"]}#{issue["number"]} {issue["title"]}')
            author_link = link(author['html_url'], '@' + author['login'])
            data_link = encode_data_link(
                ('issue', repo['full_name'], issue['number'], author['login']))
            text = f'{data_link}🐛 New issue {issue_link}\nby {author_link}\n\n{text}'

            self._send(repo, text, lambda r: r.issues)
コード例 #3
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def pull_request(self, update, context):
        # Pull request opened, closed, reopened, edited, assigned, unassigned, review requested,
        # review request removed, labeled, unlabeled, or synchronized.
        # TODO: Possibly support closed, reopened, edited, assigned etc.
        if update.payload['action'] == 'opened':
            pull_request = update.payload['pull_request']
            author = pull_request['user']
            repo = update.payload['repository']

            text = render_github_markdown(pull_request['body'],
                                          repo['full_name'])

            pull_request_link = link(
                pull_request['html_url'],
                f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}'
            )
            author_link = link(author['html_url'], '@' + author['login'])
            data_link = encode_data_link(
                ('pull request', repo['full_name'], pull_request['number'],
                 author['login']))
            text = f'{data_link}🔌 New pull request {pull_request_link}\nby {author_link}\n\n{text}'

            self._send(repo, text, lambda r: r.pulls)
コード例 #4
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def gollum(self, update, context):
        # Wiki page is created or updated.
        pages = update.payload['pages']
        repo = update.payload['repository']
        sender = update.payload['sender']

        text = f'🔨 {len(pages)} {repo["full_name"]} wiki page{"s" if len(pages) > 1 else ""} were updated '
        sender_link = link(sender['html_url'], '@' + sender['login'])
        text += f'by {sender_link}\n\n'

        for page in pages:
            compare_url = f'{page["html_url"]}/_compare/{page["sha"]}'
            text += f'<a href="{page["html_url"]}">{page["title"]}</a> (<a href="{compare_url}">compare</a>)\n'

        self._send(repo, text, lambda r: r.wiki_pages, suffix='')
コード例 #5
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def pull_request_review(self, update, context):
        # Pull request review submitted, edited, or dismissed.
        # TODO: Possibly support edited and dismissed?
        if update.payload['action'] == 'submitted':
            review = update.payload['review']
            pull_request = update.payload['pull_request']
            author = review['user']
            repo = update.payload['repository']

            if not review['body']:
                return

            text = render_github_markdown(review['body'], repo['full_name'])

            review_link = link(
                review['html_url'],
                f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}'
            )
            author_link = link(author['html_url'], '@' + author['login'])
            data_link = encode_data_link(
                ('pull request', repo['full_name'], pull_request['number'],
                 author['login']))

            if review['state'] in ('commented', 'approved', 'request_changes'):
                if review['state'] == 'commented':
                    state = 'Commented'
                    emoji = '💬'
                elif review['state'] == 'approved':
                    state = 'Approved'
                    emoji = '✅'
                elif review['state'] == 'request_changes':
                    state = 'Changes requested'
                    emoji = '‼️'

                text = f'{data_link}{emoji} New pull request review {review_link}\n{state} by {author_link}\n\n{text}'
                self._send(repo, text, lambda r: r.pull_reviews)
コード例 #6
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def issue_comment(self, update, context):
        # Any time a comment on an issue or pull request is created, edited, or deleted.
        # TODO: Possibly support editing and closing of comments?
        if update.payload['action'] == 'created':
            issue = update.payload['issue']
            comment = update.payload['comment']
            author = comment['user']
            repo = update.payload['repository']
            is_pull_request = 'pull_request' in issue

            text = render_github_markdown(comment['body'], repo['full_name'])

            issue_link = link(
                issue['html_url'],
                f'{repo["full_name"]}#{issue["number"]} {issue["title"]}')
            author_link = link(author['html_url'], '@' + author['login'])
            data_link = encode_data_link(
                ('pull request' if is_pull_request else 'issue',
                 repo['full_name'], issue['number'], author['login']))
            text = f'{data_link}💬 New comment on {issue_link}\nby {author_link}\n\n{text}'

            self._send(
                repo, text, lambda r: r.pull_comments
                if is_pull_request else r.issue_comments)
コード例 #7
0
ファイル: github.py プロジェクト: sivagurus/githubbotrevised
    def commit_comment(self, update, context):
        if update.payload['action'] == 'created':
            repo = update.payload['repository']
            comment = update.payload['comment']
            author = comment['user']

            author_link = link(author['html_url'], '@' + author['login'])
            text = f'💬 <a href="{comment["html_url"]}">New comment</a> on commit {comment["commit_id"][:7]} by {author_link}'
            position, line, path = comment['position'], comment[
                'line'], comment['path']
            if path:
                text += f'\nPath: {path}'
            if line:
                text += f'\nLine: {line}'
                if position == 1:
                    text += ' (before)'
                elif position == 2:
                    text += ' (after)'

            text += f'\n\n{comment["body"]}'

            self._send(repo, text, lambda r: r.commit_comments, suffix='')