示例#1
0
文件: github.py 项目: sebastiken/tsrc
def request_reviewers(repo: Repository, pr_number: int,
                      reviewers: List[str]) -> None:
    owner_name = repo.owner.login
    repo_name = repo.name
    # github3.py does not provide any way to request reviewers, so
    # we have to use private members here
    url = repo._build_url("repos", owner_name, repo_name, "pulls", pr_number,
                          "requested_reviewers")
    ret = repo._post(url, data={"reviewers": reviewers})
    if not 200 <= ret.status_code < 300:
        raise GitHubAPIError(url, ret.status_code, ret.json().get("message"))
示例#2
0
def loadRepos():
    index = 0
    while True:
        fileName = os.path.join(DOWNLOAD_FOLDER, 'repos' + str(index) + '.pkl')
        if not os.path.isfile(fileName):
            break
        print("Loading file: %s..." % fileName)
        for pickled in pickle.load(open(fileName, 'rb')):
            repo = Repository.from_dict(pickled["repo"])
            repos.append(repo)
            meta = pickled["meta"]
            repo.forks = [
                fork["full_name"] for fork in pickled["meta"]["forks"]
            ]

            # reduce the meta dicts by only using the value of the metaDictKey
            for key in metaKeys:
                metaDictKey = metaDictKeys[key]
                valueList = meta.get(key) or []
                meta[key] = [value[metaDictKey] for value in valueList]
            meta["README"] = ""
            for FILE in FILES:
                if FILE in meta["files"]:
                    meta["README"] = meta["files"][FILE].decode(
                        encoding='UTF-8')
                    meta["files"] = None
                    break

            repoMeta.append(meta)
            #for fork in repo.forks:
            #print(fork, pickled["repo"]["full_name"], Repository.from_dict(pickled["repo"]).full_name)

        index += 1
        #break
    return repos, repoMeta
示例#3
0
def project(_project: Repository, template: Repository) -> Repository:
    """Create a GitHub repository for a Cookiecutter template project."""
    _project.create_file(
        path=".cookiecutter.json",
        message="Create .cookiecutter.json",
        content=json.dumps({
            "_template": f"gh:{template.full_name}",
            "project": "example"
        }).encode(),
    )
    _project.create_file(
        path="README.md",
        message="Create README",
        content=b"# example",
    )
    return _project
def find_commits(github: RepoVerifier, repo: Repository,
                 package_name: str) -> Iterator[Tuple[Repository, RepoCommit]]:
    """Find commits in repository.

    Only commits which include changes under a path of an Android manifest file
    for package_name are included.

    :param RepoVerifier github:
        API instance to contact Github.
    :param Repository repo:
        Repository to get commits from.
    :param str package_name:
        Package name to restrict commits for. Only paths with a fitting
        manifest file are considered.
    :returns Iterator[Tuple[Repository, RepoCommit]]:
        Iterator of tuples identifying a commit by repository and commit.
    """
    query = MANIFEST_SEARCH.format(repo.full_name, package_name)
    for manifest in github.search_code(query):
        path = os.path.dirname(manifest.path)
        if repo != manifest.repository:
            __log__.warning(
                'Repository in search result does not match: %s != %s', repo,
                manifest.repository)
        for commit in repo.iter_commits(path=path):
            yield repo, commit
示例#5
0
    def _create_hook(
        self,
        repository:Repository,
        callback_url:str,
        hook_name:str=DEFAULT_HOOK_NAME,
        content_type:str=DEFAULT_HOOK_CONTENT_TYPE,
        events:list=DEFAULT_HOOK_EVENTS,
        active:bool=True
    ):
        # see https://developer.github.com/v3/repos/hooks/
        config = {
            'url': callback_url,
            'content_type': content_type,
        }

        hook = repository.create_hook(
            name=hook_name,
            config=config,
            active=active
        )

        if not hook:
            raise RuntimeError('failed to create webhook {n} for repo {r}'.format(
                n=hook_name,
                r=str(repository)
                )
            )
        return hook
示例#6
0
文件: jobs.py 项目: akacrm/Metecho
def get_branch_prefix(user, repository: Repository):
    if settings.BRANCH_PREFIX:
        return settings.BRANCH_PREFIX
    with local_github_checkout(user, repository.id) as repo_root:
        return get_cumulus_prefix(
            repo_root=repo_root,
            repo_name=repository.name,
            repo_url=repository.html_url,
            repo_owner=repository.owner.login,
            repo_branch=repository.default_branch,
            repo_commit=repository.branch(
                repository.default_branch).latest_sha(),
        )
示例#7
0
 def _retrieve_existing_hook_or_none(self, repository: Repository,
                                     hook_name: str, callback_url: str):
     '''
     @raises github3.exceptions.NotFoundError in case of missing privileges to enumerate webhooks
     '''
     hooks = filter(lambda h: h.name == hook_name, repository.hooks())
     hooks = filter(lambda h: self._has_similar_url(h, callback_url), hooks)
     hooks = list(hooks)
     if len(hooks) == 1:
         return hooks[0]
     elif len(hooks) == 0:
         return None
     raise RuntimeError('found two similar webhooks - what to do now?')
示例#8
0
def test_rewrite(
    create_project_pull_request: CreatePullRequest,
    invoke_main: InvokeMain,
    template: Repository,
) -> None:
    """It rewrites the commits associated with the pull request."""
    project_pull = create_project_pull_request(
        Path("README.md"),
        "# Welcome to example",
    )

    invoke_main([str(project_pull.number)])

    template_file = template.file_contents(
        "{{cookiecutter.project}}/README.md",
        ref=f"refs/heads/{appname}/{project_pull.head.ref}",
    )
    assert "# Welcome to {{cookiecutter.project}}" == template_file.decoded.decode(
    )
示例#9
0
def template(_template: Repository) -> Repository:
    """Create a GitHub repository for a Cookiecutter template."""
    _template.create_file(
        path="cookiecutter.json",
        message="Create cookiecutter.json",
        content=json.dumps({
            "project": "example"
        }).encode(),
    )
    _template.create_file(
        path="{{cookiecutter.project}}/.cookiecutter.json",
        message="Create .cookiecutter.json in project",
        content=b"{{cookiecutter | jsonify}}",
    )
    _template.create_file(
        path="{{cookiecutter.project}}/README.md",
        message="Create README.md in project",
        content=b"# {{cookiecutter.project}}",
    )
    return _template
示例#10
0
 def setUp(self):
     fixture = load_fixture('pull_request.json')
     self.repo_model = Repository(json.loads(fixture))
示例#11
0
 def generator(self, gh_api):
     repo_json = GithubApiTestMixin()._get_expected_repo(
         "TestOwner", "TestRepo")
     repo = Repository(repo_json, gh_api)
     return ParentPullRequestNotesGenerator(gh_api, repo,
                                            create_project_config())
示例#12
0
 def repo(self, gh_api):
     repo_json = self._get_expected_repo("TestOwner", "TestRepo")
     return Repository(repo_json, gh_api)
示例#13
0
 def setUp(self):
     fixture = load_fixture('repository.json')
     self.repo_model = Repository(json.loads(fixture))
示例#14
0
 def setUp(self):
     fixture = load_fixture('repository.json')
     self.session = GitHubSession()
     self.repo_model = Repository.from_json(fixture, self.session)
示例#15
0
 def setUp(self):
     fixture = load_fixture('repository.json')
     self.session = GitHubSession()
     self.repo_model = Repository.from_json(fixture, self.session)