Access Gitea from R

ixpantia

2020-08-26

Gitea is a community managed, lightweight code hosting solution were projects and their respective git repositories can be managed https://gitea.io. This package gives an interface to the ‘Gitea’ API to access and manage repositories, issues and organizations directly in R.

Starting with gitear

If you want to start using the functions from gitear you should first go to your gitea service and create an API KEY. You will find this under your avatar, configuration, application and then generate a new token.

Be aware that you should save this token somewhere because its shown just once.

This is going to be your API TOKEN. Then you can use a function like this:

# Credentials

api_token <- "gfdsgfd8ba18a866bsdfgsdfgs3a2dc9303453b0c92dcfb19"
url_ixpantia <- "https://prueba.com"

# Example function use:

issues <- get_issues(base_url = url_ixpantia,
                       api_key = api_token,
                       owner = "empresa",
                       repo = "repo_prueba")

glimpse(issues)
#> Rows: 2
#> Columns: 10
#> $ number       <int> 3, 2
#> $ title        <chr> "Primer tiquete para prueba", "Primer tiquete para prueb…
#> $ body         <chr> "Este es el cuerpo del tiquete", "Este es el cuerpo del …
#> $ created_date <chr> "2020-07-15", "2020-07-15"
#> $ created_time <chr> "23:43:42", "23:12:37"
#> $ updated_date <chr> "2020-07-24", "2020-07-24"
#> $ updated_time <chr> "14:41:47", "14:41:37"
#> $ due_date     <chr> "2020-07-31T23:59:59Z", "2020-07-31T23:59:59Z"
#> $ author       <chr> "juan", "juan"
#> $ assignee     <chr> "juan", "juan"

For the examples below, we are going to use credentials stored in a .Renviron file, which we are going to call from this variables:

example_key <- Sys.getenv("example_key")
example_url <- Sys.getenv("example_url")

Get information about your organization

We can also obtain information from some organization defined in our gitea service:

# Example function use

organizations <- get_an_organization(base_url = example_url,
                                     api_key = example_key,
                                     org = "empresa") 

glimpse(organizations)
#> Rows: 1
#> Columns: 9
#> $ id                            <int> 8
#> $ username                      <chr> "empresa"
#> $ full_name                     <chr> ""
#> $ avatar_url                    <chr> "https://prueba.com/user/avatar/empresa…
#> $ description                   <chr> ""
#> $ website                       <chr> ""
#> $ location                      <chr> ""
#> $ visibility                    <chr> "public"
#> $ repo_admin_change_team_access <lgl> FALSE

Get repositories information from one organization

And we can also see which repositories are associated with that same organization:

# Example function use

repos <- get_list_repos_org(base_url = example_url, 
                            api_key = example_key, 
                            org = "empresa")

glimpse(repos)
#> Rows: 2
#> Columns: 37
#> $ id                          <int> 52, 57
#> $ owner                       <df[,10]> <data.frame[2 x 10]>
#> $ name                        <chr> "repo_prueba", "git-core-test-2"
#> $ full_name                   <chr> "empresa/repo_prueba", "empresa/git-core-…
#> $ description                 <chr> "Repositorio de prueba", ""
#> $ empty                       <lgl> FALSE, FALSE
#> $ private                     <lgl> FALSE, FALSE
#> $ fork                        <lgl> FALSE, FALSE
#> $ template                    <lgl> FALSE, FALSE
#> $ mirror                      <lgl> FALSE, FALSE
#> $ size                        <int> 0, 0
#> $ html_url                    <chr> "https://prueba.com/empresa/repo_prueba",…
#> $ ssh_url                     <chr> "git@prueba.com:empresa/repo_prueba.git",…
#> $ clone_url                   <chr> "https://prueba.com/empresa/repo_prueba.g…
#> $ original_url                <chr> "", ""
#> $ website                     <chr> "", ""
#> $ stars_count                 <int> 0, 0
#> $ forks_count                 <int> 1, 0
#> $ watchers_count              <int> 4, 4
#> $ open_issues_count           <int> 8, 0
#> $ open_pr_counter             <int> 0, 0
#> $ release_counter             <int> 0, 0
#> $ default_branch              <chr> "master", "master"
#> $ archived                    <lgl> FALSE, FALSE
#> $ created_at                  <chr> "2020-07-15T23:11:39Z", "2020-07-18T22:02…
#> $ updated_at                  <chr> "2020-07-23T20:12:37Z", "2020-07-18T22:02…
#> $ permissions                 <df[,3]> <data.frame[2 x 3]>
#> $ has_issues                  <lgl> TRUE, TRUE
#> $ internal_tracker            <df[,3]> <data.frame[2 x 3]>
#> $ has_wiki                    <lgl> TRUE, TRUE
#> $ has_pull_requests           <lgl> TRUE, TRUE
#> $ ignore_whitespace_conflicts <lgl> FALSE, FALSE
#> $ allow_merge_commits         <lgl> TRUE, TRUE
#> $ allow_rebase                <lgl> TRUE, TRUE
#> $ allow_rebase_explicit       <lgl> TRUE, TRUE
#> $ allow_squash_merge          <lgl> TRUE, TRUE
#> $ avatar_url                  <chr> "", ""

User information

But we can not only get information about projects and repositories, we can also see specific information about users:

# Example function use

users <- get_list_users(base_url = example_url, 
                        api_key = example_key)

glimpse(users)
#> Rows: 4
#> Columns: 11
#> $ data.id         <int> 3, 25, 15, 9
#> $ data.login      <chr> "pedro", "juan", "pedro", "maria"
#> $ data.full_name  <chr> "", "", "", ""
#> $ data.email      <chr> "pedro@correo.com", "juan@correo.com", "pedro@correo.…
#> $ data.avatar_url <chr> "https://prueba.com/user/avatar/pedro/-1", "https://p…
#> $ data.language   <chr> "es-ES", "es-ES", "es-ES", "es-ES"
#> $ data.is_admin   <lgl> FALSE, TRUE, FALSE, TRUE
#> $ data.last_login <chr> "2020-07-18T20:01:18Z", "2020-07-23T20:12:11Z", "2020…
#> $ data.created    <chr> "2018-10-14T23:08:52Z", "2020-03-09T23:46:56Z", "2019…
#> $ data.username   <chr> "pedro", "juan", "pedro", "maria"
#> $ ok              <lgl> TRUE, TRUE, TRUE, TRUE

All commits from a specific repository

We can also see the commits made to a certain repository in a very simple way

# Example function use

commits <- get_commits(base_url = example_url, 
                     api_key = example_key,
                     owner = "empresa",
                     repo = "repo_prueba")

head(commits)
#>                                                                                                          url
#> 1 https://prueba.com/api/v1/repos/empresa/repo_prueba/git/commits/77226be181cd8f00ba34rsfsgs26445e2df128fcf1
#>                                          sha
#> 1 77226be181cd8f00ba34rsfsgs26445e2df128fcf1
#>                                                                                   html_url
#> 1 https://prueba.com/empresa/repo_prueba/commit/77226be181cd8f00ba34rsfsgs26445e2df128fcf1
#>                                                                                                   commit.url
#> 1 https://prueba.com/api/v1/repos/empresa/repo_prueba/git/commits/77226be181cd8f00ba34rsfsgs26445e2df128fcf1
#>   commit.author.name commit.author.email   commit.author.date
#> 1               juan     juan@correo.com 2020-07-15T23:11:40Z
#>   commit.committer.name commit.committer.email commit.committer.date
#> 1                  juan        juan@correo.com  2020-07-15T23:11:40Z
#>   commit.message
#> 1 Initial commit
#>                                                                                            commit.tree.url
#> 1 https://prueba.com/api/v1/repos/empresa/repo_prueba/git/trees/77226be181cd8f00ba34rsfsgs26445e2df128fcf1
#>                              commit.tree.sha author.id author.login
#> 1 77226be181cd8f00ba34rsfsgs26445e2df128fcf1        25         juan
#>   author.full_name    author.email                      author.avatar_url
#> 1                  juan@correo.com https://prueba.com/user/avatar/juan/-1
#>   author.language author.is_admin    author.last_login       author.created
#> 1           es-ES            TRUE 2020-07-23T20:12:11Z 2020-03-09T23:46:56Z
#>   author.username committer.id committer.login committer.full_name
#> 1            juan           25            juan                    
#>   committer.email                   committer.avatar_url committer.language
#> 1 juan@correo.com https://prueba.com/user/avatar/juan/-1              es-ES
#>   committer.is_admin committer.last_login    committer.created
#> 1               TRUE 2020-07-23T20:12:11Z 2020-03-09T23:46:56Z
#>   committer.username parents
#> 1               juan    NULL

These are just some of the functionality of gitea, there are other information that we can obtain about a gitea service.