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


Python exceptions.NotFoundError方法代码示例

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


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

示例1: retrieve_pr_template_text

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def retrieve_pr_template_text(self):
        '''Return the content for the PR template file looking in predefined directories.
        If no template is found None is returned.
        '''
        pattern = re.compile(r"(pull_request_template)(\..{1,3})?$")
        directories = ['.github', '.', 'docs']
        for directory in directories:
            try:
                for filename, content in self.repository.directory_contents(directory):
                    if pattern.match(filename):
                        content.refresh()
                        return content.decoded.decode('utf-8')
            except github3.exceptions.NotFoundError:
                pass  # directory does not exists

        return None 
开发者ID:gardener,项目名称:cc-utils,代码行数:18,代码来源:util.py

示例2: retrieve_asset_contents

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def retrieve_asset_contents(self, release_tag: str, asset_label: str):
        ci.util.not_none(release_tag)
        ci.util.not_none(asset_label)

        release = self.repository.release_from_tag(release_tag)
        for asset in release.assets():
            if asset.label == asset_label or asset.name == asset_label:
                break
        else:
            response = requests.Response()
            response.status_code = 404
            response.json = lambda: {'message':'no asset with label {} found'.format(asset_label)}
            raise NotFoundError(resp=response)

        buffer = io.BytesIO()
        asset.download(buffer)
        return buffer.getvalue().decode() 
开发者ID:gardener,项目名称:cc-utils,代码行数:19,代码来源:util.py

示例3: revert

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def revert(self):
        # Fetch release
        try:
            release = self.github_helper.repository.release_from_tag(self.release_version)
        except NotFoundError:
            release = None
        if release:
            info(f"Deleting Release {self.release_version}")
            if not release.delete():
                raise RuntimeError("Release could not be deleted")
        try:
            tag = self.github_helper.repository.ref(f"tags/{self.release_version}")
        except NotFoundError:
            # Ref wasn't created
            return
        if not tag.delete():
            raise RuntimeError("Tag could not be deleted") 
开发者ID:gardener,项目名称:cc-utils,代码行数:19,代码来源:release.py

示例4: upload_fw

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def upload_fw(file, version, codename, today, variant):
    """
    Upload files to GitHub release
    """
    print("uploading: " + file)
    codename = codename.split('-')[0]
    folder = set_folder(file)
    subprocess.call(['rclone', 'copy', file, 'osdn:/storage/groups/x/xi/xiaomifirmwareupdater/'
                     + folder + '/' + version + '/' + codename + '/', '-v'])
    repository = GIT.repository('XiaomiFirmwareUpdater', f'firmware_xiaomi_{codename}')
    tag = f'{variant}-{today}'
    try:
        release = repository.release_from_tag(tag)  # release exist already
    except exceptions.NotFoundError:
        # create new release
        release = repository.create_release(tag, name=tag,
                                            body=
                                            f"Extracted Firmware from MIUI {file.split('_')[4]}",
                                            draft=False, prerelease=False)
    try:
        asset = release.upload_asset(content_type='application/binary',
                                     name=file, asset=open(file, 'rb'))
        print(f'Uploaded {asset.name} Successfully to release {release.name}')
    except exceptions.UnprocessableEntity:
        print(f'{file} is already uploaded') 
开发者ID:XiaomiFirmwareUpdater,项目名称:mi-firmware-updater,代码行数:27,代码来源:xfu.py

示例5: get_protection

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def get_protection(access_token, branch_name, owner, repo_name):
    gh = login(token=access_token)
    if gh is None:
        print(f"Could not login. Have you provided credentials?")
        raise exit(1)

    try:
        repo = gh.repository(owner, repo_name)
    except NotFoundError:
        print(f"Could not find repo https://github.com/{owner}/{repo_name}")
        raise
    branch = repo.branch(branch_name)
    protection = branch.protection()
    return protection 
开发者ID:benjefferies,项目名称:branch-protection-bot,代码行数:16,代码来源:run.py

示例6: _migrate_project

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def _migrate_project(self, project):
        print("Migrating project %s/%s" % (self.gh_org, project))
        # Create new branch
        repo = self.github.repository(self.gh_org, project)
        try:
            repo.branch(self.gh_source_branch)
        except NotFoundError:
            print("Source branch non existing. Skipping...")
            return
        try:
            repo.branch(self.gh_target_branch)
        except NotFoundError:
            pass
        else:
            print("Branch already exists. Skipping...")
            return
        root_contents = repo.directory_contents(
            '', self.gh_source_branch, return_as=dict,
        )
        modules = self._get_modules_list(repo, root_contents)
        commit = self._create_metafiles(repo, root_contents)
        repo.create_ref(
            'refs/heads/%s' % self.gh_target_branch, commit.sha,
        )
        # TODO: GitHub is returning 404
        # self._make_default_branch(repo)
        milestone = self._create_branch_milestone(repo)
        self._create_migration_issue(repo, sorted(modules), milestone) 
开发者ID:OCA,项目名称:maintainer-tools,代码行数:30,代码来源:migrate_branch_empty.py

示例7: _migrate_project

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def _migrate_project(self, project):
        print("Migrating project %s/%s" % (self.gh_org, project))
        # Create new branch
        repo = self.github.repository(self.gh_org, project)
        try:
            source_branch = repo.branch(self.gh_source_branch)
        except NotFoundError:
            print("Source branch non existing. Skipping...")
            return
        try:
            repo.branch(self.gh_target_branch)
        except NotFoundError:
            pass
        else:
            print("Branch already exists. Skipping...")
            return
        repo.create_ref(
            'refs/heads/%s' % self.gh_target_branch,
            source_branch.commit.sha)
        root_contents = repo.directory_contents(
            '', self.gh_target_branch, return_as=dict,
        )
        modules = self._mark_modules_uninstallable(repo, root_contents)
        if self.gh_target_branch == '10.0':
            self._rename_manifests(repo, root_contents)
        self._delete_unported_dir(repo, root_contents)
        # TODO: Is this really needed?
        # self._delete_setup_dirs(repo, root_contents, modules)
        self._update_metafiles(repo, root_contents)
        # TODO: GitHub is returning 404
        # self._make_default_branch(repo)
        milestone = self._create_branch_milestone(repo)
        self._create_migration_issue(repo, sorted(modules), milestone) 
开发者ID:OCA,项目名称:maintainer-tools,代码行数:35,代码来源:migrate_branch.py

示例8: directory_contents

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def directory_contents(self, path, **kw):
        try:
            return self._contents[path]
        except KeyError:
            raise NotFoundError(
                DummyResponse(f"Accessed unexpected directory: {path}", 404)
            ) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:9,代码来源:test_config.py

示例9: latest_release

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def latest_release(self):
        for release in self._releases:
            if release.tag_name.startswith("release/"):
                return release
        raise NotFoundError(DummyResponse("", 404)) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:7,代码来源:test_config.py

示例10: release_from_tag

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def release_from_tag(self, tag_name):
        for release in self._releases:
            if release.tag_name == tag_name:
                return release
        raise NotFoundError(DummyResponse("", 404)) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:7,代码来源:test_config.py

示例11: get_latest_tag

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def get_latest_tag(self, beta=False):
        """ Query Github Releases to find the latest production or beta tag """
        repo = self._get_repo()
        if not beta:
            try:
                release = repo.latest_release()
            except github3.exceptions.NotFoundError:
                raise GithubException(f"No release found for repo {self.repo_url}")
            prefix = self.project__git__prefix_release
            if not release.tag_name.startswith(prefix):
                return self._get_latest_tag_for_prefix(repo, prefix)
            return release.tag_name
        else:
            return self._get_latest_tag_for_prefix(repo, self.project__git__prefix_beta) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:16,代码来源:project_config.py

示例12: get_ref_for_dependency

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def get_ref_for_dependency(self, repo, dependency, include_beta=None):
        release = None
        if "ref" in dependency:
            ref = dependency["ref"]
        else:
            if "tag" in dependency:
                try:
                    # Find the github release corresponding to this tag.
                    release = repo.release_from_tag(dependency["tag"])
                except NotFoundError:
                    raise DependencyResolutionError(
                        f"No release found for tag {dependency['tag']}"
                    )
            else:
                release = find_latest_release(repo, include_beta)
            if release:
                ref = repo.tag(
                    repo.ref("tags/" + release.tag_name).object.sha
                ).object.sha
            else:
                self.logger.info(
                    f"No release found; using the latest commit from the {repo.default_branch} branch."
                )
                ref = repo.branch(repo.default_branch).commit.sha

        return (release, ref) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:28,代码来源:project_config.py

示例13: _create_repository

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def _create_repository(self, owner: str, name: str):
        try:
            repository = self.github.repository(
                    owner=owner,
                    repository=name
            )
            return repository
        except NotFoundError as nfe:
            raise RuntimeError(
                'failed to retrieve repository {o}/{r}'.format(
                    o=owner,
                    r=name,
                ),
                nfe
            ) 
开发者ID:gardener,项目名称:cc-utils,代码行数:17,代码来源:util.py

示例14: create_or_update_file

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def create_or_update_file(
        self,
        file_path: str,
        file_contents: str,
        commit_message: str,
        branch: str=None,
    ) -> str:
        if branch is None:
            branch = self.default_branch

        try:
            contents = self.retrieve_file_contents(file_path=file_path, branch=branch)
        except NotFoundError:
            contents = None # file did not yet exist

        if contents:
            decoded_contents = contents.decoded.decode('utf-8')
            if decoded_contents == file_contents:
                # Nothing to do
                return ci.util.info(
                    'Repository file contents are identical to passed file contents.'
                )
            else:
                response = contents.update(
                    message=commit_message,
                    content=file_contents.encode('utf-8'),
                    branch=branch,
                )
        else:
            response = self.repository.create_file(
                path=file_path,
                message=commit_message,
                content=file_contents.encode('utf-8'),
                branch=branch,
            )
        return response['commit'].sha 
开发者ID:gardener,项目名称:cc-utils,代码行数:38,代码来源:util.py

示例15: tag_exists

# 需要导入模块: from github3 import exceptions [as 别名]
# 或者: from github3.exceptions import NotFoundError [as 别名]
def tag_exists(
        self,
        tag_name: str,
    ):
        ci.util.not_empty(tag_name)
        try:
            self.repository.ref('tags/' + tag_name)
            return True
        except NotFoundError:
            return False 
开发者ID:gardener,项目名称:cc-utils,代码行数:12,代码来源:util.py


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