當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。