forked from ixpantia/gitear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
111 lines (78 loc) · 2.88 KB
/
README.Rmd
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(gitear)
library(dplyr)
library(dplyr)
library(jsonlite)
library(mockery)
```
# gitear <a href="https://ixpantia.github.io/gitear/"><img src="man/figures/gitear.png" align="right" width="30%"></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/gitear)](https://cran.r-project.org/package=gitear)
[![Travis build status](https://travis-ci.org/ixpantia/gitear.svg?branch=master)](https://travis-ci.org/ixpantia/gitear)
[![Codecov test coverage](https://codecov.io/gh/ixpantia/gitear/branch/master/graph/badge.svg)](https://codecov.io/gh/ixpantia/gitear?branch=master)
<!-- badges: end -->
The goal of gitear is to request your self-hosted Git service data and import
it to R in a tidy data frame.
`gitear` is a package that communicates with the
[gitea](https://gitea.io/en-us/) API.
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("ixpantia/gitear")
```
## Usage
First go to your gitea self hosted service and grab your API Token. Then you
should be able to the following:
```{r, echo = FALSE}
r <- readRDS(system.file("helper_data/response_example.RDS",
package = "gitear"))
content_issues <- jsonlite::fromJSON(system.file("helper_data/get_issues.json",
package = "gitear"))
mockery::stub(where = get_issues,
what = "GET",
how = r)
mockery::stub(where = get_issues,
what = "fromJSON",
how = content_issues)
```
```{r example}
# 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")
issues
```
## **Environmental variables:**
In order to work with environmental variables to make your scripts safer from
somebody getting your credentials, you can follow the next workflow:
1. Create an .Renviron file with your credentials
2. Restart your R session
3. Store your credentials in an object for using it in your script
Your script could look something like this:
```{r example_2}
# Storing credentials in an object
example_key <- Sys.getenv("example_key")
example_url <- Sys.getenv("example_url")
# Using a function from gitear
issues <- get_issues(base_url = example_url,
api_key = example_key,
owner = "empresa",
repo = "repo_prueba")
# Check the output
glimpse(issues)
```