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


Python GitHub.from_settings方法代码示例

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


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

示例1: after_register

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def after_register(self, node, registration, user, save=True):
        """

        :param Node node: Original node
        :param Node registration: Registered node
        :param User user: User creating registration
        :param bool save: Save settings after callback
        :return tuple: Tuple of cloned settings and alert message

        """
        clone, message = super(AddonGitHubNodeSettings, self).after_register(
            node, registration, user, save=False
        )

        # Copy foreign fields from current add-on
        clone.user_settings = self.user_settings

        # Store current branch data
        if self.user and self.repo:
            connect = GitHub.from_settings(self.user_settings)
            try:
                branches = [
                    branch.to_json()
                    for branch in connect.branches(self.user, self.repo)
                ]
                clone.registration_data['branches'] = branches
            except ApiError:
                pass

        if save:
            clone.save()

        return clone, message
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:35,代码来源:model.py

示例2: add_hook

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def add_hook(self, save=True):

        if self.user_settings:
            connect = GitHub.from_settings(self.user_settings)
            secret = utils.make_hook_secret()
            hook = connect.add_hook(
                self.user, self.repo,
                'web',
                {
                    'url': urlparse.urljoin(
                        hook_domain,
                        os.path.join(
                            self.owner.api_url, 'github', 'hook/'
                        )
                    ),
                    'content_type': github_settings.HOOK_CONTENT_TYPE,
                    'secret': secret,
                }
            )

            if hook:
                self.hook_id = hook.id
                self.hook_secret = secret
                if save:
                    self.save()
开发者ID:hmoco,项目名称:osf.io,代码行数:27,代码来源:model.py

示例3: after_set_privacy

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def after_set_privacy(self, node, permissions):
        """

        :param Node node:
        :param str permissions:
        :return str: Alert message

        """
        if not github_settings.SET_PRIVACY:
            return

        connect = GitHub.from_settings(self.user_settings)

        data = connect.set_privacy(self.user, self.repo, permissions == "private")
        if data is None or "errors" in data:
            repo = connect.repo(self.user, self.repo)
            if repo is not None:
                current_privacy = "private" if repo.private else "public"
            else:
                current_privacy = "unknown"
            return "Could not set privacy for repo {user}::{repo}. " "Current privacy status is {perm}.".format(
                user=self.user, repo=self.repo, perm=current_privacy
            )

        return "GitHub repo {user}::{repo} made {perm}.".format(user=self.user, repo=self.repo, perm=permissions)
开发者ID:cldershem,项目名称:osf.io,代码行数:27,代码来源:model.py

示例4: update_hook

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
def update_hook(node_settings):
    """Discard the existing webhook for a GitHub node add-on and create a new
    one.

    """
    logger.warn(
        'Updating GitHub hook on node {0}'.format(
            node_settings.owner._id
        )
    )

    connection = GitHub.from_settings(node_settings.user_settings)
    repo = connection.repo(node_settings.user, node_settings.repo)
    hook = repo.hook(node_settings.hook_id)

    if hook is None:
        logger.warn('Hook {0} not found'.format(node_settings.hook_id))
        return

    secret = utils.make_hook_secret()

    config = hook.config
    config['content_type'] = github_settings.HOOK_CONTENT_TYPE
    config['secret'] = secret

    hook.edit(config=config)

    node_settings.hook_secret = secret
    node_settings.save()
开发者ID:545zhou,项目名称:osf.io,代码行数:31,代码来源:update_hooks.py

示例5: before_page_load

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def before_page_load(self, node, user):
        """

        :param Node node:
        :param User user:
        :return str: Alert message

        """
        messages = []

        # Quit if not contributor
        if not node.is_contributor(user):
            return messages

        # Quit if not configured
        if self.user is None or self.repo is None:
            return messages

        # Quit if no user authorization
        if self.user_settings is None:
            return messages

        connect = GitHub.from_settings(self.user_settings)

        try:
            repo = connect.repo(self.user, self.repo)
        except ApiError:
            return

        node_permissions = 'public' if node.is_public else 'private'
        repo_permissions = 'private' if repo.private else 'public'
        if repo_permissions != node_permissions:
            message = (
                'Warnings: This OSF {category} is {node_perm}, but the GitHub '
                'repo {user} / {repo} is {repo_perm}.'.format(
                    category=node.project_or_component,
                    node_perm=node_permissions,
                    repo_perm=repo_permissions,
                    user=self.user,
                    repo=self.repo,
                )
            )
            if repo_permissions == 'private':
                message += (
                    ' Users can view the contents of this private GitHub '
                    'repository through this public project.'
                )
            else:
                message += (
                    ' The files in this GitHub repo can be viewed on GitHub '
                    '<a href="https://github.com/{user}/{repo}/">here</a>.'
                ).format(
                    user=self.user,
                    repo=self.repo,
                )
            messages.append(message)
            return messages
开发者ID:lbanner,项目名称:osf.io,代码行数:59,代码来源:model.py

示例6: revoke_token

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
 def revoke_token(self):
     connection = GitHub.from_settings(self)
     try:
         connection.revoke_token()
     except GitHubError as error:
         if error.code == http.UNAUTHORIZED:
             return (
                 'Your GitHub credentials were removed from the OSF, but we '
                 'were unable to revoke your access token from GitHub. Your '
                 'GitHub credentials may no longer be valid.'
             )
         raise
开发者ID:hmoco,项目名称:osf.io,代码行数:14,代码来源:model.py

示例7: github_download_starball

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
def github_download_starball(node_addon, **kwargs):

    archive = kwargs.get('archive', 'tar')
    ref = request.args.get('sha', 'master')

    connection = GitHub.from_settings(node_addon.user_settings)
    headers, data = connection.starball(
        node_addon.user, node_addon.repo, archive, ref
    )

    resp = make_response(data)
    for key, value in headers.iteritems():
        resp.headers[key] = value

    return resp
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:17,代码来源:crud.py

示例8: delete_hook

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
 def delete_hook(self, save=True):
     """
     :return bool: Hook was deleted
     """
     if self.user_settings and self.hook_id:
         connection = GitHub.from_settings(self.user_settings)
         try:
             response = connection.delete_hook(self.user, self.repo, self.hook_id)
         except (GitHubError, NotFoundError):
             return False
         if response:
             self.hook_id = None
             if save:
                 self.save()
             return True
     return False
开发者ID:hmoco,项目名称:osf.io,代码行数:18,代码来源:model.py

示例9: github_delete_file

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
def github_delete_file(auth, node_addon, **kwargs):

    node = kwargs['node'] or kwargs['project']

    now = datetime.datetime.utcnow()

    # Must remove trailing slash, else GitHub fails silently on delete
    path = get_path(kwargs).rstrip('/')

    sha = request.args.get('sha')
    if sha is None:
        raise HTTPError(http.BAD_REQUEST)

    branch = request.args.get('branch')

    author = {
        'name': auth.user.fullname,
        'email': '{0}@osf.io'.format(auth.user._id),
    }

    connection = GitHub.from_settings(node_addon.user_settings)

    data = connection.delete_file(
        node_addon.user, node_addon.repo, path, MESSAGES['delete'],
        sha=sha, branch=branch, author=author,
    )

    if data is None:
        raise HTTPError(http.BAD_REQUEST)

    node.add_log(
        action='github_' + models.NodeLog.FILE_REMOVED,
        params={
            'project': node.parent_id,
            'node': node._primary_key,
            'path': path,
            'github': {
                'user': node_addon.user,
                'repo': node_addon.repo,
            },
        },
        auth=auth,
        log_date=now,
    )

    return {}
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:48,代码来源:crud.py

示例10: get_refs

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
def get_refs(addon, branch=None, sha=None, connection=None):
    """Get the appropriate branch name and sha given the addon settings object,
    and optionally the branch and sha from the request arguments.
    :param str branch: Branch name. If None, return the default branch from the
        repo settings.
    :param str sha: The SHA.
    :param GitHub connection: GitHub API object. If None, one will be created
        from the addon's user settings.
    """
    connection = connection or GitHub.from_settings(addon.user_settings)

    if sha and not branch:
        raise HTTPError(http.BAD_REQUEST)

    # Get default branch if not provided
    if not branch:
        repo = connection.repo(addon.user, addon.repo)
        if repo is None:
            return None, None, None
        branch = repo.default_branch
    # Get registered branches if provided
    registered_branches = (
        [Branch.from_json(b) for b in addon.registration_data.get('branches', [])]
        if addon.owner.is_registration
        else []
    )

    registered_branch_names = [
        each.name
        for each in registered_branches
    ]
    # Fail if registered and branch not in registration data
    if registered_branches and branch not in registered_branch_names:
        raise HTTPError(http.BAD_REQUEST)

    # Get data from GitHub API if not registered
    branches = registered_branches or connection.branches(addon.user, addon.repo)

    # Use registered SHA if provided
    for each in branches:
        if branch == each.name:
            sha = each.commit.sha
            break
    return branch, sha, branches
开发者ID:XTech2K,项目名称:osf.io,代码行数:46,代码来源:utils.py

示例11: to_json

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
 def to_json(self, user):
     ret = super(AddonGitHubNodeSettings, self).to_json(user)
     user_settings = user.get_addon('github')
     ret.update({
         'user_has_auth': user_settings and user_settings.has_auth,
         'is_registration': self.owner.is_registration,
     })
     if self.user_settings and self.user_settings.has_auth:
         valid_credentials = False
         owner = self.user_settings.owner
         if user_settings and user_settings.owner == owner:
             connection = GitHub.from_settings(user_settings)
             # TODO: Fetch repo list client-side
             # Since /user/repos excludes organization repos to which the
             # current user has push access, we have to make extra requests to
             # find them
             valid_credentials = True
             try:
                 repos = itertools.chain.from_iterable((connection.repos(), connection.my_org_repos()))
                 repo_names = [
                     '{0} / {1}'.format(repo.owner.login, repo.name)
                     for repo in repos
                 ]
             except GitHubError as error:
                 if error.code == http.UNAUTHORIZED:
                     repo_names = []
                     valid_credentials = False
             ret.update({'repo_names': repo_names})
         ret.update({
             'node_has_auth': True,
             'github_user': self.user or '',
             'github_repo': self.repo or '',
             'github_repo_full_name': '{0} / {1}'.format(self.user, self.repo),
             'auth_osf_name': owner.fullname,
             'auth_osf_url': owner.url,
             'auth_osf_id': owner._id,
             'github_user_name': self.user_settings.github_user_name,
             'github_user_url': 'https://github.com/{0}'.format(self.user_settings.github_user_name),
             'is_owner': owner == user,
             'valid_credentials': valid_credentials,
             'addons_url': web_url_for('user_addons'),
         })
     return ret
开发者ID:XTech2K,项目名称:osf.io,代码行数:45,代码来源:model.py

示例12: to_json

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
 def to_json(self, user):
     ret = super(AddonGitHubNodeSettings, self).to_json(user)
     user_settings = user.get_addon("github")
     ret.update(
         {"user_has_auth": user_settings and user_settings.has_auth, "is_registration": self.owner.is_registration}
     )
     if self.user_settings and self.user_settings.has_auth:
         valid_credentials = False
         owner = self.user_settings.owner
         if user_settings and user_settings.owner == owner:
             connection = GitHub.from_settings(user_settings)
             # TODO: Fetch repo list client-side
             # Since /user/repos excludes organization repos to which the
             # current user has push access, we have to make extra requests to
             # find them
             valid_credentials = True
             try:
                 repos = itertools.chain.from_iterable((connection.repos(), connection.my_org_repos()))
                 repo_names = ["{0} / {1}".format(repo.owner.login, repo.name) for repo in repos]
             except GitHubError as error:
                 if error.code == http.UNAUTHORIZED:
                     repo_names = []
                     valid_credentials = False
             ret.update({"repo_names": repo_names})
         ret.update(
             {
                 "node_has_auth": True,
                 "github_user": self.user or "",
                 "github_repo": self.repo or "",
                 "github_repo_full_name": "{0} / {1}".format(self.user, self.repo),
                 "auth_osf_name": owner.fullname,
                 "auth_osf_url": owner.url,
                 "auth_osf_id": owner._id,
                 "github_user_name": self.user_settings.github_user_name,
                 "github_user_url": "https://github.com/{0}".format(self.user_settings.github_user_name),
                 "is_owner": owner == user,
                 "valid_credentials": valid_credentials,
                 "addons_url": web_url_for("user_addons"),
             }
         )
     return ret
开发者ID:cldershem,项目名称:osf.io,代码行数:43,代码来源:model.py

示例13: add_hook

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def add_hook(self, save=True):

        if self.user_settings:
            connect = GitHub.from_settings(self.user_settings)
            secret = utils.make_hook_secret()
            hook = connect.add_hook(
                self.user,
                self.repo,
                "web",
                {
                    "url": urlparse.urljoin(hook_domain, os.path.join(self.owner.api_url, "github", "hook/")),
                    "content_type": github_settings.HOOK_CONTENT_TYPE,
                    "secret": secret,
                },
            )

            if hook:
                self.hook_id = hook.id
                self.hook_secret = secret
                if save:
                    self.save()
开发者ID:cldershem,项目名称:osf.io,代码行数:23,代码来源:model.py

示例14: after_set_privacy

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
    def after_set_privacy(self, node, permissions):
        """

        :param Node node:
        :param str permissions:
        :return str: Alert message

        """
        if not github_settings.SET_PRIVACY:
            return

        connect = GitHub.from_settings(self.user_settings)

        data = connect.set_privacy(
            self.user, self.repo, permissions == 'private'
        )
        if data is None or 'errors' in data:
            repo = connect.repo(self.user, self.repo)
            if repo is not None:
                current_privacy = 'private' if repo.private else 'public'
            else:
                current_privacy = 'unknown'
            return (
                'Could not set privacy for repo {user}::{repo}. '
                'Current privacy status is {perm}.'.format(
                    user=self.user,
                    repo=self.repo,
                    perm=current_privacy,
                )
            )

        return (
            'GitHub repo {user}::{repo} made {perm}.'.format(
                user=self.user,
                repo=self.repo,
                perm=permissions,
            )
        )
开发者ID:hmoco,项目名称:osf.io,代码行数:40,代码来源:model.py

示例15: github_download_file

# 需要导入模块: from website.addons.github.api import GitHub [as 别名]
# 或者: from website.addons.github.api.GitHub import from_settings [as 别名]
def github_download_file(**kwargs):

    node_settings = kwargs['node_addon']

    path = get_path(kwargs)

    ref = request.args.get('sha')
    connection = GitHub.from_settings(node_settings.user_settings)

    try:
        name, data, _ = connection.file(
            node_settings.user, node_settings.repo, path, ref=ref
        )
    except TooBigError:
        raise HTTPError(
            http.BAD_REQUEST,
            data={
                'message_short': 'File too large',
                'message_long': 'This file is too large to download through '
                'the GitHub API.',
            },
        )
    if data is None:
        raise HTTPError(http.NOT_FOUND)

    # Build response
    resp = make_response(data)
    mimetype = get_mimetype(path, data)
    # Add binary MIME type if mimetype not found
    if mimetype is None:
        resp.headers['Content-Type'] = 'application/octet-stream'
    else:
        resp.headers['Content-Type'] = mimetype

    resp.headers['Content-Disposition'] = 'attachment; filename={0}'.format(
        name)

    return resp
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:40,代码来源:crud.py


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