delete_file: Delete a file in a new commit

Description Usage Arguments Details Value Examples

Description

This function deletes a file in a repository in GitHub by creating a new commit on the specified branch. If the branch does not already exist a parent commit must be specified and a new branch is created from it. If the file does not exist delete_file() throws as error.

Usage

1
delete_file(path, branch, message, repo, parent, author, committer, ...)

Arguments

path

(string) The path of the file to delete, within the repository.

branch

(string) The name of the branch to make the new commit on.

message

(string) The commit message.

repo

(string) The repository specified in the format: owner/repo.

parent

(string, optional) If creating a new branch the the parent commit must be specified as either a SHA, branch or tag.

author

(list, optional) A the name and email address of the user who wrote the changes in the commit.

committer

(list, optional) A the name and email address of the user who created the commit.

...

Parameters passed to gh_request().

Details

The author and committer arguments are optional and if not supplied the current authenticated user is used. However, if you want to set them explicitly you must specify a named list with name and email as the elements (see examples).

Note: The GitHub API imposes a file size limit of 1MB for this request. For larger files use the upload_files() function.

For more details see the GitHub API documentation:

Value

delete_file()returns a list of the commit properties.

Commit Properties:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 

  # Delete a file on the main branch
  delete_file(
    path    = "file-to-delete.md",
    branch  = "main",
    message = "Deleted a file with delete_file()",
    repo    = "ChadGoymer/githapi"
  )

  # Delete a file on a new branch
  create_file(
    path    = "file-to-delete.md",
    branch  = "new-branch",
    message = "Deleted a file with delete_file()",
    repo    = "ChadGoymer/githapi",
    parent  = "main"
  )

  # Delete a file on the main branch specifying an author and committer
  delete_file(
    path      = "file-to-delete.md",
    branch    = "main",
    message   = "Deleted a file with delete_file()",
    repo      = "ChadGoymer/githapi",
    author    = list(name = "Bob",  email = "bob@acme.com"),
    committer = list(name = "Jane", email = "jane@acme.com")
  )


## End(Not run)

ChadGoymer/githapi documentation built on Oct. 22, 2021, 10:56 a.m.