Skip to contents

Creates an actions data row ready to be fed to commit_files().

Usage

file_commit_action(
  path,
  action = c("create", "delete", "move", "update", "chmod"),
  content = NULL,
  from_file = FALSE,
  previous_path = NULL,
  execute_filemode = NULL,
  last_commit_id = NULL
)

Arguments

path

character(1)
Path to the file being acted on, relative to the repository root. For action = "move", this is the destination path to move the file to.

action

character(1)
Action to take on the file. One of "create", "delete", "move", "update" or "chmod".

content

character(1) or raw()
File content, as a character scalar for text files, or a raw vector for binary files. Or the path to a local file as a character scalar if from_file = TRUE. Only considered for "create" and "update" actions.

from_file

logical(1)
Whether or not content indicates the path to a local file instead of the actual file content.

previous_path

character(1)
Original path to the file being moved. Only considered for action = "move".

execute_filemode

logical(1)
Whether or not to mark the uploaded file as executable.

last_commit_id

character(1)
Last known file commit identifier. If provided (and valid), GitLab will only proceed if no commit made after last_commit_id has modified the file. Intended to avoid concurrency issues (e.g. from CI pipelines). NULL means to skip the check. Only considered for "delete", "move" and "update" actions.

Value

A tibble row with the columns action, file_path, previous_path, content, encoding, last_commit_id and execute_filemode.

See also

Other functions to manage commits on GitLab: commit_files()

Other functions to manage files on GitLab: commit_files(), file_content(), file_create(), file_delete(), file_exists(), file_full(), file_meta(), file_req(), file_update(), file_write(), files_delete()

Examples

# totally silly sequence of file actions to commit
list(gitlab::file_commit_action(path = "test.txt",
                                action = "create",
                                content = "anyone there?"),
     gitlab::file_commit_action(path = "test.txt",
                                action = "update",
                                content = "#!/bin/sh\n\necho 'anyone there?'\n"),
     gitlab::file_commit_action(path = "test.sh",
                                action = "move",
                                previous_path = "test.txt"),
     gitlab::file_commit_action(path = "test.sh",
                                action = "chmod",
                                execute_filemode = TRUE),
     gitlab::file_commit_action(path = "test.sh",
                                action = "delete")) |>
  purrr::list_rbind()
#> # A tibble: 5 × 6
#>   file_path action content                               encoding previous_path execute_filemode
#>   <chr>     <chr>  <chr>                                 <chr>    <chr>         <lgl>           
#> 1 test.txt  create "anyone there?"                       text     NA            NA              
#> 2 test.txt  update "#!/bin/sh\n\necho 'anyone there?'\n" text     NA            NA              
#> 3 test.sh   move    NA                                   NA       test.txt      NA              
#> 4 test.sh   chmod   NA                                   NA       NA            TRUE            
#> 5 test.sh   delete  NA                                   NA       NA            NA              

# to create/update a file on GitLab with a local file's content
if (FALSE) { # \dontrun{
gitlab::file_commit_action(path = "test.txt",
                           action = "create",
                           content = "/PATH/TO/LOCAL/FILE",
                           from_file = TRUE)} # }