当前位置: 首页>>代码示例>>Python>>正文


Python GitHub.notifications方法代码示例

本文整理汇总了Python中github.GitHub.notifications方法的典型用法代码示例。如果您正苦于以下问题:Python GitHub.notifications方法的具体用法?Python GitHub.notifications怎么用?Python GitHub.notifications使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.GitHub的用法示例。


在下文中一共展示了GitHub.notifications方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ones

# 需要导入模块: from github import GitHub [as 别名]
# 或者: from github.GitHub import notifications [as 别名]
class Processor:
    """
    This class holds all the logic to process GitHub notifications and
    comment on previous ones (to report a status, ...).
    """

    _conn = None

    def __init__(self, debug=False):
        """
        Constructor for the Processor class.

        :param debug: If set to True, the console will also log debug
        messages.
        :return:
        """
        # Init GitHub with the configured access token
        self.g = GitHub(access_token=Configuration.token)

        self.debug = debug
        loggers = LogConfiguration(self.debug)
        self.logger = loggers.create_logger("Processor")

    @staticmethod
    def generate_random_string(
            length=32, chars=string.ascii_uppercase + string.digits):
        """
        Generates a random string with a given length and character set
        :param length: The length of the random string. 32 by default.
        :param chars: The characters that should be used. Uppercase + digits
        by default.
        :return: A randomly generated string of given length.
        """
        return ''.join(
            random.SystemRandom().choice(chars) for _ in range(length))

    def run(self):
        """
        Runs the script by fetching new notifications and running through
        it, as well as reporting back for all the messages in the database
        queue.
        :return:
        """

        self.logger.info("Start of bot")
        # Create connection to the DB
        self._conn = pymysql.connect(
            host=Configuration.database_host,
            user=Configuration.database_user,
            passwd=Configuration.database_password,
            db=Configuration.database_name,
            charset='latin1',
            cursorclass=pymysql.cursors.DictCursor)

        self.logger.debug("Fetching notifications")
        notifications = self.g.notifications.get()
        if len(notifications) > 0:
            self.logger.debug("We got {0} new notifications".format(
                len(notifications)))
            # Get valid forks
            open_forks = self.get_forks()
            # Run through notifications
            for notification in notifications:
                repo_name = notification.repository.full_name
                self.logger.info("Got a notification in {0}".format(repo_name))
                if repo_name in open_forks:
                    url = notification.subject.url
                    parts = url.split('/')
                    not_id = parts[-1]
                    not_type = notification.subject.type
                    repo_owner = notification.repository.owner.login
                    self.logger.info("Valid notification: {0} #{1}".format(
                        not_type, not_id))
                    self.logger.debug("Repository owned by: {0}".format(
                        repo_owner))
                    if not_type == "Issue":
                        self.logger.debug("Fetching issue")
                        issue = self.g.repos(repo_owner)(
                            Configuration.repo_name).issues(not_id).get()
                        comments = self.g.repos(repo_owner)(
                            Configuration.repo_name).issues(not_id).comments.get()
                        self.run_through_comments(
                            issue, comments, not_type, not_id, repo_owner,
                            open_forks[repo_name])
                    elif not_type == "PullRequest":
                        self.logger.debug("Fetching PR")
                        request = self.g.repos(repo_owner)(
                            Configuration.repo_name).pulls(not_id).get()
                        # For some reason, the comments for the PR are issues...
                        comments = self.g.repos(repo_owner)(
                            Configuration.repo_name).issues(not_id).comments.get()
                        self.run_through_comments(
                            request, comments, not_type, not_id, repo_owner,
                            open_forks[repo_name])
                    elif not_type == "Commit":
                        self.logger.debug("Fetching Commit")
                        commit = self.g.repos(repo_owner)(
                            Configuration.repo_name).commits(not_id).get()
                        comments = self.g.repos(repo_owner)(
                            Configuration.repo_name).commits(
#.........这里部分代码省略.........
开发者ID:canihavesomecoffee,项目名称:ccx_gitbot,代码行数:103,代码来源:processor.py


注:本文中的github.GitHub.notifications方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。