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

Method update_file

github/Repository.py:2820–2878  ·  view source on GitHub ↗

This method updates a file in a repository. :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ :param path: string, Required. The content path. :param message: string, Requir

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

Source from the content-addressed store, hash-verified

2818 return github.RepositoryAdvisory.RepositoryAdvisory(self._requester, headers, data)
2819
2820 def update_file(
2821 self,
2822 path: str,
2823 message: str,
2824 content: bytes | str,
2825 sha: str,
2826 branch: Opt[str] = NotSet,
2827 committer: Opt[InputGitAuthor] = NotSet,
2828 author: Opt[InputGitAuthor] = NotSet,
2829 ) -> dict[str, ContentFile | Commit]:
2830 """
2831 This method updates a file in a repository.
2832
2833 :calls: `PUT /repos/{owner}/{repo}/contents/{path} <https://docs.github.com/en/rest/reference/repos#create-or-
2834 update-file-contents>`_
2835 :param path: string, Required. The content path.
2836 :param message: string, Required. The commit message.
2837 :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded.
2838 :param sha: string, Required. The blob SHA of the file being replaced.
2839 :param branch: string. The branch name. Default: the repository’s default branch (usually master)
2840 :param committer: InputGitAuthor, (optional), if no information is given the authenticated user&#x27;s information
2841 will be used. You must specify both a name and email.
2842 :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If
2843 passed, you must specify both a name and email.
2844 :rtype: { 'content': :class:`ContentFile <github.ContentFile.ContentFile>`:, 'commit': :class:`Commit
2845 <github.Commit.Commit>`}
2846
2847 """
2848 assert isinstance(path, str)
2849 assert isinstance(message, str)
2850 assert isinstance(content, (str, bytes))
2851 assert isinstance(sha, str)
2852 assert is_optional(branch, str)
2853 assert is_optional(author, github.InputGitAuthor)
2854 assert is_optional(committer, github.InputGitAuthor)
2855
2856 if not isinstance(content, bytes):
2857 content = content.encode("utf-8")
2858 content = b64encode(content).decode("utf-8")
2859
2860 put_parameters: dict[str, Any] = {"message": message, "content": content, "sha": sha}
2861
2862 if is_defined(branch):
2863 put_parameters["branch"] = branch
2864 if is_defined(author):
2865 put_parameters["author"] = author._identity
2866 if is_defined(committer):
2867 put_parameters["committer"] = committer._identity
2868
2869 headers, data = self._requester.requestJsonAndCheck(
2870 "PUT",
2871 f"{self.url}/contents/{urllib.parse.quote(path)}",
2872 input=put_parameters,
2873 )
2874
2875 return {
2876 "commit": github.Commit.Commit(self._requester, headers, data["commit"], completed=True),
2877 "content": github.ContentFile.ContentFile(self._requester, headers, data["content"], completed=False),

Callers 1

testUpdateFileMethod · 0.80

Calls 4

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

Tested by

no test coverage detected