projects.md 9.8 KB
Newer Older
1 2 3
## Projects

### List projects
N
Nihad Abbasov 已提交
4

R
Rob Taylor 已提交
5
Get a list of projects owned by the authenticated user.
N
Nihad Abbasov 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19

```
GET /projects
```

```json
[
  {
    "id": 3,
    "name": "rails",
    "description": null,
    "default_branch": "master",
    "owner": {
      "id": 1,
20
      "username": "john_smith",
N
Nihad Abbasov 已提交
21 22 23 24 25
      "email": "john@example.com",
      "name": "John Smith",
      "blocked": false,
      "created_at": "2012-05-23T08:00:58Z"
    },
26
    "public": true,
27 28
    "path": "rails",
    "path_with_namespace": "rails/rails",
N
Nihad Abbasov 已提交
29 30 31 32
    "issues_enabled": false,
    "merge_requests_enabled": false,
    "wall_enabled": true,
    "wiki_enabled": true,
33 34
    "created_at": "2012-05-23T08:05:02Z",
    "last_activity_at": "2012-05-23T08:05:02Z"
N
Nihad Abbasov 已提交
35 36 37 38 39 40 41 42
  },
  {
    "id": 5,
    "name": "gitlab",
    "description": null,
    "default_branch": "api",
    "owner": {
      "id": 1,
43
      "username": "john_smith",
N
Nihad Abbasov 已提交
44 45 46 47 48
      "email": "john@example.com",
      "name": "John Smith",
      "blocked": false,
      "created_at": "2012-05-23T08:00:58Z"
    },
49
    "public": true,
50 51
    "path": "gitlab",
    "path_with_namespace": "randx/gitlab",
N
Nihad Abbasov 已提交
52 53 54 55
    "issues_enabled": true,
    "merge_requests_enabled": true,
    "wall_enabled": true,
    "wiki_enabled": true,
56
    "snippets_enabled": true,
57 58
    "created_at": "2012-05-30T12:49:20Z",
    "last_activity_at": "2012-05-23T08:05:02Z"
N
Nihad Abbasov 已提交
59 60 61 62
  }
]
```

63 64

### Get single project
N
Nihad Abbasov 已提交
65

66 67
Get a specific project, identified by project ID or NAME, which is owned by the authentication user.
Currently namespaced projects cannot retrieved by name.
N
Nihad Abbasov 已提交
68 69 70 71 72 73 74

```
GET /projects/:id
```

Parameters:

75
+ `id` (required) - The ID or NAME of a project
N
Nihad Abbasov 已提交
76

A
Alex Denisov 已提交
77 78 79 80
```json
{
  "id": 5,
  "name": "gitlab",
D
Dmitriy Zaporozhets 已提交
81
  "name_with_namespace": "GitLab / gitlabhq",
A
Alex Denisov 已提交
82 83 84 85
  "description": null,
  "default_branch": "api",
  "owner": {
    "id": 1,
86
    "username": "john_smith",
A
Alex Denisov 已提交
87 88 89 90 91
    "email": "john@example.com",
    "name": "John Smith",
    "blocked": false,
    "created_at": "2012-05-23T08:00:58Z"
  },
92
  "public": true,
93 94
  "path": "gitlab",
  "path_with_namespace": "randx/gitlab",
A
Alex Denisov 已提交
95 96 97 98
  "issues_enabled": true,
  "merge_requests_enabled": true,
  "wall_enabled": true,
  "wiki_enabled": true,
99
  "snippets_enabled": true,
100 101
  "created_at": "2012-05-30T12:49:20Z",
  "last_activity_at": "2012-05-23T08:05:02Z"
A
Alex Denisov 已提交
102 103 104
}
```

D
Dmitriy Zaporozhets 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
### Get project events

Get a project events for specific project.
Sorted from newest to latest

```
GET /projects/:id/events
```

Parameters:

+ `id` (required) - The ID or NAME of a project

```json

[{
  "title": null,
  "project_id": 15,
  "action_name": "closed",
  "target_id": 830,
  "target_type": "Issue",
  "author_id": 1,
  "data": null,
  "target_title": "Public project search field"
}, {
  "title": null,
  "project_id": 15,
  "action_name": "opened",
  "target_id": null,
  "target_type": null,
  "author_id": 1,
  "data": {
    "before": "50d4420237a9de7be1304607147aec22e4a14af7",
    "after": "c5feabde2d8cd023215af4d2ceeb7a64839fc428",
    "ref": "refs/heads/master",
    "user_id": 1,
    "user_name": "Dmitriy Zaporozhets",
    "repository": {
      "name": "gitlabhq",
      "url": "git@dev.gitlab.org:gitlab/gitlabhq.git",
      "description": "GitLab: self hosted Git management software. \r\nDistributed under the MIT License.",
      "homepage": "https://dev.gitlab.org/gitlab/gitlabhq"
    },
    "commits": [{
      "id": "c5feabde2d8cd023215af4d2ceeb7a64839fc428",
      "message": "Add simple search to projects in public area",
      "timestamp": "2013-05-13T18:18:08+00:00",
      "url": "https://dev.gitlab.org/gitlab/gitlabhq/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428",
      "author": {
        "name": "Dmitriy Zaporozhets",
        "email": "dmitriy.zaporozhets@gmail.com"
      }
    }],
    "total_commits_count": 1
  },
  "target_title": null
}, {
  "title": null,
  "project_id": 15,
  "action_name": "closed",
  "target_id": 840,
  "target_type": "Issue",
  "author_id": 1,
  "data": null,
  "target_title": "Finish & merge Code search PR"
}]
```

173 174

### Create project
A
Alex Denisov 已提交
175

176
Creates new project owned by user.
A
Alex Denisov 已提交
177 178 179 180 181 182 183 184

```
POST /projects
```

Parameters:

+ `name` (required) - new project name
N
Nihad Abbasov 已提交
185
+ `description` (optional) - short project description
186
+ `default_branch` (optional) - 'master' by default
187 188 189 190 191
+ `issues_enabled` (optional)
+ `wall_enabled` (optional)
+ `merge_requests_enabled` (optional)
+ `wiki_enabled` (optional) 
+ `snippets_enabled` (optional)
192
+ `public` (optional)
A
Alex Denisov 已提交
193

194
**Project access levels**
195

J
Johannes Schleifenbaum 已提交
196
The project access levels are defined in the `user_project.rb` class. Currently, these levels are recognized:
197 198 199 200 201 202 203 204

```
  GUEST     = 10
  REPORTER  = 20
  DEVELOPER = 30
  MASTER    = 40
```

205

206 207 208
### Create project for user

Creates a new project owned by user. Available only for admins.
209 210 211 212 213 214 215 216 217 218 219

```
POST /projects/user/:user_id
```

Parameters:

+ `user_id` (required) - user_id of owner
+ `name` (required) - new project name
+ `description` (optional) - short project description
+ `default_branch` (optional) - 'master' by default
220 221 222 223 224
+ `issues_enabled` (optional)
+ `wall_enabled` (optional)
+ `merge_requests_enabled` (optional)
+ `wiki_enabled` (optional) 
+ `snippets_enabled` (optional)
225
+ `public` (optional)
A
Alex Denisov 已提交
226

227

228 229 230 231

## Team members

### List project team members
M
miks 已提交
232

N
Nihad Abbasov 已提交
233
Get a list of project team members.
M
miks 已提交
234 235

```
N
Nihad Abbasov 已提交
236
GET /projects/:id/members
M
miks 已提交
237 238 239 240
```

Parameters:

241
+ `id` (required) - The ID or NAME of a project
242
+ `query` (optional) - Query string to search for members
243 244 245


### Get project team member
M
miks 已提交
246

247
Gets a project team member.
248

N
Nihad Abbasov 已提交
249 250 251 252 253
```
GET /projects/:id/members/:user_id
```

Parameters:
254

255
+ `id` (required) - The ID or NAME of a project
N
Nihad Abbasov 已提交
256 257 258 259 260
+ `user_id` (required) - The ID of a user

```json
{
  "id": 1,
261
  "username": "john_smith",
N
Nihad Abbasov 已提交
262 263 264 265 266 267
  "email": "john@example.com",
  "name": "John Smith",
  "blocked": false,
  "created_at": "2012-05-23T08:00:58Z",
  "access_level": 40
}
268
```
N
Nihad Abbasov 已提交
269

270 271

### Add project team member
N
Nihad Abbasov 已提交
272

273 274
Adds a user to a project team. This is an idempotent method and can be called multiple times
with the same parameters. Adding team membership to a user that is already a member does not
275
affect the existing membership.
N
Nihad Abbasov 已提交
276 277 278

```
POST /projects/:id/members
279 280 281 282
```

Parameters:

283
+ `id` (required) - The ID or NAME of a project
N
Nihad Abbasov 已提交
284 285
+ `user_id` (required) - The ID of a user to add
+ `access_level` (required) - Project access level
286

287 288

### Edit project team member
M
miks 已提交
289

290
Updates project team member to a specified access level.
M
miks 已提交
291 292

```
N
Nihad Abbasov 已提交
293
PUT /projects/:id/members/:user_id
M
miks 已提交
294 295 296 297
```

Parameters:

298
+ `id` (required) - The ID or NAME of a project
N
Nihad Abbasov 已提交
299 300
+ `user_id` (required) - The ID of a team member
+ `access_level` (required) - Project access level
M
miks 已提交
301

302 303

### Remove project team member
M
miks 已提交
304

N
Nihad Abbasov 已提交
305
Removes user from project team.
M
miks 已提交
306 307

```
N
Nihad Abbasov 已提交
308
DELETE /projects/:id/members/:user_id
M
miks 已提交
309 310 311 312
```

Parameters:

313
+ `id` (required) - The ID or NAME of a project
N
Nihad Abbasov 已提交
314
+ `user_id` (required) - The ID of a team member
M
miks 已提交
315

316 317 318
This method is idempotent and can be called multiple times with the same parameters.
Revoking team membership for a user who is not currently a team member is considered success.
Please note that the returned JSON currently differs slightly. Thus you should not
319
rely on the returned JSON structure.
N
Nihad Abbasov 已提交
320

M
miks 已提交
321

322 323 324 325 326
## Hooks

### List project hooks

Get list of project hooks.
M
miks 已提交
327 328 329 330 331 332 333

```
GET /projects/:id/hooks
```

Parameters:

334
+ `id` (required) - The ID or NAME of a project
M
miks 已提交
335 336


337
### Get project hook
338

339
Get a specific hook for project.
340 341 342 343 344

```
GET /projects/:id/hooks/:hook_id
```

345
Parameters:
346

347
+ `id` (required) - The ID or NAME of a project
348 349
+ `hook_id` (required) - The ID of a project hook

350 351 352 353 354 355 356 357
```json
{
  "id": 1,
  "url": "http://example.com/hook",
  "created_at": "2012-10-12T17:04:47Z"
}
```

M
miks 已提交
358

359 360 361
### Add project hook

Adds a hook to project.
M
miks 已提交
362 363 364 365 366 367 368

```
POST /projects/:id/hooks
```

Parameters:

369
+ `id` (required) - The ID or NAME of a project
M
miks 已提交
370 371
+ `url` (required) - The hook URL

372

373 374 375
### Edit project hook

Edits a hook for project.
376 377 378 379 380 381 382

```
PUT /projects/:id/hooks/:hook_id
```

Parameters:

383
+ `id` (required) - The ID or NAME of a project
384 385 386 387
+ `hook_id` (required) - The ID of a project hook
+ `url` (required) - The hook URL


388
### Delete project hook
M
miks 已提交
389

390 391
Removes a hook from project. This is an idempotent method and can be called multiple times.
Either the hook is available or not.
M
miks 已提交
392 393

```
394
DELETE /projects/:id/hooks/:hook_id
M
miks 已提交
395 396 397 398
```

Parameters:

399
+ `id` (required) - The ID or NAME of a project
M
miks 已提交
400 401
+ `hook_id` (required) - The ID of hook to delete

402 403
Note the JSON response differs if the hook is available or not. If the project hook
is available before it is returned in the JSON response or an empty response is returned.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461


## Branches

### List branches

Lists all branches of a project.

```
GET /projects/:id/repository/branches
```

Parameters:

+ `id` (required) - The ID of the project


### List single branch

Lists a specific branch of a project.

```
GET /projects/:id/repository/branches/:branch
```

Parameters:

+ `id` (required) - The ID of the project.
+ `branch` (required) - The name of the branch.


### Protect single branch

Protects a single branch of a project.

```
PUT /projects/:id/repository/branches/:branch/protect
```

Parameters:

+ `id` (required) - The ID of the project.
+ `branch` (required) - The name of the branch.


### Unprotect single branch

Unprotects a single branch of a project.

```
PUT /projects/:id/repository/branches/:branch/unprotect
```

Parameters:

+ `id` (required) - The ID of the project.
+ `branch` (required) - The name of the branch.

462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

## Admin fork relation

Allows modification of the forked relationship between existing projects. . Available only for admins.

### Create a forked from/to relation between existing projects.

```
POST /projects/:id/fork/:forked_from_id
```

Parameters:

+ `id` (required) - The ID of the project
+ `forked_from_id:` (required) - The ID of the project that was forked from

### Delete an existing forked from relationship

```
DELETE /projects/:id/fork
```

Parameter:

486
+ `id` (required) - The ID of the project
I
Izaak Alpert 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499


## Search for projects by name

Search for projects by name which are public or the calling user has access to

```
GET /projects/search/:query
```

Parameters:

+   query (required) - A string contained in the project name
500 501
+   per_page (optional) - number of projects to return per page
+   page (optional) - the page to retrieve