MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / create_file

Method create_file

github/Repository.py:2738–2793  ·  view source on GitHub ↗

Create a file in this repository. :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ :param path: string, (required), path of the file in the repository :param message: strin

(
        self,
        path: str,
        message: str,
        content: str | bytes,
        branch: Opt[str] = NotSet,
        committer: Opt[InputGitAuthor] = NotSet,
        author: Opt[InputGitAuthor] = NotSet,
    )

Source from the content-addressed store, hash-verified

2736 return PaginatedList(github.Autolink.Autolink, self._requester, f"{self.url}/autolinks", None)
2737
2738 def create_file(
2739 self,
2740 path: str,
2741 message: str,
2742 content: str | bytes,
2743 branch: Opt[str] = NotSet,
2744 committer: Opt[InputGitAuthor] = NotSet,
2745 author: Opt[InputGitAuthor] = NotSet,
2746 ) -> dict[str, ContentFile | Commit]:
2747 """
2748 Create a file in this repository.
2749
2750 :calls: `PUT /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#create-or-
2751 update-file-contents>`_
2752 :param path: string, (required), path of the file in the repository
2753 :param message: string, (required), commit message
2754 :param content: string, (required), the actual data in the file
2755 :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the
2756 repository
2757 :param committer: InputGitAuthor, (optional), if no information is given the authenticated user&#x27;s information
2758 will be used. You must specify both a name and email.
2759 :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If
2760 passed, you must specify both a name and email.
2761 :rtype: { 'content': :class:`ContentFile <github.ContentFile.ContentFile>`:, 'commit': :class:`Commit
2762 <github.Commit.Commit>`}
2763
2764 """
2765 assert isinstance(path, str)
2766 assert isinstance(message, str)
2767 assert isinstance(content, (str, bytes))
2768 assert is_optional(branch, str)
2769 assert is_optional(author, github.InputGitAuthor)
2770 assert is_optional(committer, github.InputGitAuthor)
2771
2772 if not isinstance(content, bytes):
2773 content = content.encode("utf-8")
2774 content = b64encode(content).decode("utf-8")
2775 put_parameters: dict[str, Any] = {"message": message, "content": content}
2776
2777 if is_defined(branch):
2778 put_parameters["branch"] = branch
2779 if is_defined(author):
2780 put_parameters["author"] = author._identity
2781 if is_defined(committer):
2782 put_parameters["committer"] = committer._identity
2783
2784 headers, data = self._requester.requestJsonAndCheck(
2785 "PUT",
2786 f"{self.url}/contents/{urllib.parse.quote(path)}",
2787 input=put_parameters,
2788 )
2789
2790 return {
2791 "content": github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False),
2792 "commit": github.Commit.Commit(self._requester, headers, data["commit"], completed=True),
2793 }
2794
2795 def get_repository_advisories(

Callers 1

testCreateFileMethod · 0.80

Calls 4

is_optionalFunction · 0.90
is_definedFunction · 0.90
encodeMethod · 0.80
requestJsonAndCheckMethod · 0.80

Tested by

no test coverage detected