Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An R client for the GitLab API

License

NotificationsYou must be signed in to change notification settings

ThinkR-open/gitlabr

CRAN_Status_BadgeCRAN Downloads BadgecodecovR-CMD-check

Never dreamt of creating and managing your GitLab projects from R?{gitlabr} is here to help you with that!
With {gitlabr}, you can interact with GitLab’s API to manage yourprojects, issues, merge requests, pipelines, wikis, and more.
Now, the automation of your regular tasks with GitLab is just a fewlines of R code away.

Installation

You can install the most recent stable version from CRAN using:

install.packages("gitlabr")

To install the development version usingdevtools, type:

install.packages("gitlabr",repos="https://thinkr-open.r-universe.dev")

See theCONTRIBUTING.mdfor instructions on how to run tests locally and contributorinformation.

Recommended GitLab versions

GitLab 11.6 or higher is generally recommended when using {gitlabr}version 2.0.0 or higher. This {gitlabr} version uses the GitLab API v4.

Quick Start Example

R code using {gitlabr} to perform some common GitLab actions can looklike this

  • Create a TOKEN on your GitLab instance with scopes:api
    • For instance on gitlab.com:https://gitlab.com/-/profile/personal_access_tokens
  • Store your token in .Renviron asGITLAB_COM_TOKEN withusethis::edit_r_environ() and restart your session
  • Set a connection to GitLab instance
library(gitlabr)# You can verify your token works# Sys.getenv("GITLAB_COM_TOKEN")# connect as a fixed user to a GitLab instance for the sessionset_gitlab_connection(gitlab_url="https://gitlab.com",private_token= Sys.getenv("GITLAB_COM_TOKEN"))
  • Find the list of projects available to you
    • Define a limit of pages of projects to search in withmax_page, otherwise the entire GitLab.com will be downloadedhere…
    • Find all parameters available in the API for projects on thispage:https://docs.gitlab.com/ee/api/projects.html
      • For instance, we can setowned = FALSE to retrieve allprojects except ours.
# a tibble is returned, as is always by {gitlabr} functionsgl_list_projects(max_page=2,owned=FALSE)#> # A tibble: 40 × 129#>    id       name        name_with_namespace path  path_with_namespace created_at#>    <chr>    <chr>       <chr>               <chr> <chr>               <chr>#>  1 57865685 nodejsappl… Arsalan Ahmed Zia … node… arsalanahmedzia_th… 2024-05-1…#>  2 57865684 Self-Hoste… Anand R / Self-Hos… self… anandr72/self-host… 2024-05-1…#>  3 57865661 cuda        handcat / cuda      cuda  handcat/cuda        2024-05-1…#>  4 57865656 TicTacToe   Debeleac Vincenzzi… tict… Andreidoo/tictactoe 2024-05-1…#>  5 57865597 Sparks Git… Nicolas Tatard / S… spar… tatardnicolas47/sp… 2024-05-1…#>  6 57865595 Sparks Git… Patrick Poncy / Sp… spar… PatSopra/sparks-gi… 2024-05-1…#>  7 57865594 Sparks Git… Emie Bourdeau / Sp… spar… Emie_Bourdeau/spar… 2024-05-1…#>  8 57865590 ComMan UI   ossama hassari / C… comm… ossamahassari98/co… 2024-05-1…#>  9 57865581 Sparks Git… Raphaël Mechali / … spar… RaphaelMechali/spa… 2024-05-1…#> 10 57865574 copy local… mvaskuri / copy lo… copy… mvaskuri1/copy-loc… 2024-05-1…#> # ℹ 30 more rows#> # ℹ 123 more variables: default_branch <chr>, ssh_url_to_repo <chr>,#> #   http_url_to_repo <chr>, web_url <chr>, readme_url <chr>, forks_count <chr>,#> #   star_count <chr>, last_activity_at <chr>, namespace.id <chr>,#> #   namespace.name <chr>, namespace.path <chr>, namespace.kind <chr>,#> #   namespace.full_path <chr>, namespace.avatar_url <chr>,#> #   namespace.web_url <chr>, container_registry_image_prefix <chr>, …

Work with a specific project

  • Explore one of your projects. You can set the name of the project orits ID. The ID is highly recommended, in particular if your projectdoes not appear in the first pages of projects above.
my_project<-20384533# repo.rtask",
  • If the default branch is not namedmain, you need to specify itwithgitlabr_options_set()
gitlabr_options_set("gitlabr.main","master")
  • List files of the project usinggl_list_files()
gl_list_files(project=my_project)#> # A tibble: 2 × 5#>   id                                       name        type  path        mode#>   <chr>                                    <chr>       <chr> <chr>       <chr>#> 1 9c66eff9a1f6f34b6d9108ef07d76f8ce4c4e47f NEWS.md     blob  NEWS.md     100644#> 2 c36b681bb31b80cbd090f07c95f09788c88629a6 example.txt blob  example.txt 100644
  • List issues withgl_list_issues()
gl_list_issues(project=my_project)#> # A tibble: 2 × 40#>   id    iid   project_id title description state created_at updated_at author.id#>   <chr> <chr> <chr>      <chr> <chr>       <chr> <chr>      <chr>      <chr>#> 1 6952… 2     20384533   A se… The blog p… open… 2020-08-0… 2020-08-0… 4809823#> 2 6952… 1     20384533   An e… No desc in… open… 2020-08-0… 2020-08-0… 4809823#> # ℹ 31 more variables: author.username <chr>, author.name <chr>,#> #   author.state <chr>, author.locked <chr>, author.avatar_url <chr>,#> #   author.web_url <chr>, type <chr>, user_notes_count <chr>,#> #   merge_requests_count <chr>, upvotes <chr>, downvotes <chr>,#> #   confidential <chr>, issue_type <chr>, web_url <chr>,#> #   time_stats.time_estimate <chr>, time_stats.total_time_spent <chr>,#> #   task_completion_status.count <chr>, …
  • Create an issue
# create a new issuenew_feature_issue<- gl_create_issue(project=my_project,title="Implement new feature")# Your user IDmy_id<-0000000# assign issue to megl_assign_issue(project=my_project,issue_id=new_feature_issue$iid,assignee_id=my_id)# Verify new issue is heregl_list_issues(project=my_project,state="opened")# close issuegl_close_issue(project=my_project,issue_id=new_feature_issue$iid)$state

Note that recent version of GitLab may have anti-spam on openingissues, leading to ERROR withgl_create_issue() if you abuse the API.You will need to open the issue manually in this case.

Use additional requests

If an API request is not already available in {gitlabr}, functiongitlab() allows to use any request of the GitLab APIhttps://docs.gitlab.com/ce/api/.

For instance, the API documentation shows how to create a new project inhttps://docs.gitlab.com/ce/api/projects.html#create-project:

  • The verb isPOST
  • The request isprojects
  • Required attributes arename orpath (ifname not set)
  • default_branch is an attribute that can be set if wanted, but notrequired

The corresponding use ofgitlab() is:

gitlab(req="projects",verb=httr::POST,name="toto",default_branch="main")

Implement whatever suits your needs !

Unset connection

unset_gitlab_connection()

Using GitLab CI with {gitlabr}

{gitlabr} can also be used to create a.gitlab-ci.yml file to test,build and check an R package, a bookdown, … using GitLab’s CI software.Usegitlabr::use_gitlab_ci() with a specifictype in your projectand your CI should be ready to start in the next commit.

There are pre-defined templates:

  • bookdown-production.yml

  • bookdown.yml

  • check-coverage-pkgdown-renv.yml

  • check-coverage-pkgdown.yml

Further information

  • For an introduction see thevignette("a-gitlabr", package = "gitlabr")
  • When writing custom extensions (“convenience functions”) for{gitlabr} or when you experience any trouble, the very extensiveGitLab API documentation can behelpful.

Contributing to {gitlabr}

You’re welcome to contribute to {gitlabr} by editing the source code,adding more convenience functions, filing issues, etc.CONTRIBUTING.mdcompiles some information helpful in that process.

Code of Conduct

Please note that the gitlabr project is released with aContributorCode ofConduct. Bycontributing to this project, you agree to abide by its terms.

Note that the {gitlabr} package was originally created byJirkaLewandowski. The presentrepository is a fork to be able to continue development of thispackage.


[8]ページ先頭

©2009-2025 Movatter.jp