File: examples.md

package info (click to toggle)
ruby-gitlab 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,824 kB
  • sloc: ruby: 12,742; makefile: 7; sh: 4; javascript: 3
file content (39 lines) | stat: -rw-r--r-- 811 bytes parent folder | download
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
<!-- THIS DOCUMENT IS PUBLISHED ON https://narkoz.github.io/gitlab -->
# Examples

## Get private token

Authorize and get the private token of a user

```rb
user = Gitlab.session('email', 'password')
user.private_token #=> "qEsq1pt6HJPaNciie3MG"
```

## Mass create projects

Bulk create projects and repositories

```rb
# See: https://narkoz.github.io/gitlab/configuration
client = Gitlab.client(endpoint: endpoint, private_token: private_token)

project_names = %w[project1 project2 project007]

project_names.each do |name|
  project = client.create_project name
  puts "#{name} created on #{project.web_url}"
end
```

## Handling errors

The client raises errors inherited from `Gitlab::Error::Error`

```rb
begin
  client.create_project 'example'
rescue Gitlab::Error::Error => error
  puts error
end
```