projects.md 7.6 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 26
      "email": "john@example.com",
      "name": "John Smith",
      "blocked": false,
      "created_at": "2012-05-23T08:00:58Z"
    },
    "private": true,
27 28
    "path": "rails",
    "path_with_namespace": "rails/rails",
N
Nihad Abbasov 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41
    "issues_enabled": false,
    "merge_requests_enabled": false,
    "wall_enabled": true,
    "wiki_enabled": true,
    "created_at": "2012-05-23T08:05:02Z"
  },
  {
    "id": 5,
    "name": "gitlab",
    "description": null,
    "default_branch": "api",
    "owner": {
      "id": 1,
42
      "username": "john_smith",
N
Nihad Abbasov 已提交
43 44 45 46 47 48
      "email": "john@example.com",
      "name": "John Smith",
      "blocked": false,
      "created_at": "2012-05-23T08:00:58Z"
    },
    "private": true,
49 50
    "path": "gitlab",
    "path_with_namespace": "randx/gitlab",
N
Nihad Abbasov 已提交
51 52 53 54 55 56 57 58 59
    "issues_enabled": true,
    "merge_requests_enabled": true,
    "wall_enabled": true,
    "wiki_enabled": true,
    "created_at": "2012-05-30T12:49:20Z"
  }
]
```

60 61

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

R
Rob Taylor 已提交
63
Get a specific project, identified by project ID, which is owned by the authentication user.
N
Nihad Abbasov 已提交
64 65 66 67 68 69 70

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

Parameters:

71
+ `id` (required) - The ID of a project
N
Nihad Abbasov 已提交
72

A
Alex Denisov 已提交
73 74 75 76 77 78 79 80
```json
{
  "id": 5,
  "name": "gitlab",
  "description": null,
  "default_branch": "api",
  "owner": {
    "id": 1,
81
    "username": "john_smith",
A
Alex Denisov 已提交
82 83 84 85 86 87
    "email": "john@example.com",
    "name": "John Smith",
    "blocked": false,
    "created_at": "2012-05-23T08:00:58Z"
  },
  "private": true,
88 89
  "path": "gitlab",
  "path_with_namespace": "randx/gitlab",
A
Alex Denisov 已提交
90 91 92 93 94 95 96 97
  "issues_enabled": true,
  "merge_requests_enabled": true,
  "wall_enabled": true,
  "wiki_enabled": true,
  "created_at": "2012-05-30T12:49:20Z"
}
```

98 99 100 101 102 103 104
Return Values:

+ `200 Ok` if the project with given ID is found and the JSON response
+ `404 Not Found` if no project with ID found


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

106
Creates new project owned by user.
A
Alex Denisov 已提交
107 108 109 110 111 112 113 114

```
POST /projects
```

Parameters:

+ `name` (required) - new project name
N
Nihad Abbasov 已提交
115
+ `description` (optional) - short project description
116 117 118 119 120
+ `default_branch` (optional) - 'master' by default
+ `issues_enabled` (optional) - enabled by default
+ `wall_enabled` (optional) - enabled by default
+ `merge_requests_enabled` (optional) - enabled by default
+ `wiki_enabled` (optional) - enabled by default
A
Alex Denisov 已提交
121

122
Return values:
123

124 125 126 127 128 129 130
+ `201 Created` on success with the project data (see example at `GET /projects/:id`)
+ `400 Bad Request` if the required attribute name is not given
+ `403 Forbidden` if the user is not allowed to create a project, e.g. reached the project limit already
+ `404 Not Found` if something else fails


### List project members
M
miks 已提交
131

N
Nihad Abbasov 已提交
132
Get a list of project team members.
M
miks 已提交
133 134

```
N
Nihad Abbasov 已提交
135
GET /projects/:id/members
M
miks 已提交
136 137 138 139
```

Parameters:

140
+ `id` (required) - The ID of a project
V
Valeriy Sizov 已提交
141
+ `query`         - Query string
M
miks 已提交
142

143 144 145 146 147 148 149 150 151
Return Values:

+ `200 Ok` on success and a list of found team members
+ `404 Not Found` if project with ID not found


## Team members

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

N
Nihad Abbasov 已提交
153
Get a project team member.
154

N
Nihad Abbasov 已提交
155 156 157 158 159
```
GET /projects/:id/members/:user_id
```

Parameters:
160

161
+ `id` (required) - The ID of a project
N
Nihad Abbasov 已提交
162 163 164 165 166
+ `user_id` (required) - The ID of a user

```json
{
  "id": 1,
167
  "username": "john_smith",
N
Nihad Abbasov 已提交
168 169 170 171 172 173
  "email": "john@example.com",
  "name": "John Smith",
  "blocked": false,
  "created_at": "2012-05-23T08:00:58Z",
  "access_level": 40
}
174
```
N
Nihad Abbasov 已提交
175

176 177 178 179 180 181 182
Return Values:

+ `200 Ok` on success and the team member, see example
+ `404 Not Found` if either the project or the team member could not be found


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

184 185 186
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
affect the membership.
N
Nihad Abbasov 已提交
187 188 189

```
POST /projects/:id/members
190 191 192 193
```

Parameters:

194
+ `id` (required) - The ID of a project
N
Nihad Abbasov 已提交
195 196
+ `user_id` (required) - The ID of a user to add
+ `access_level` (required) - Project access level
197

198
Return Values:
M
miks 已提交
199

200 201 202 203 204 205 206
+ `200 Ok` on success and the added user, even if the user is already team member
+ `400 Bad Request` if the required attribute access_level is not given
+ `404 Not Found` if a resource can not be found, e.g. project with ID not available
+ `422 Unprocessable Entity` if an unknown access_level is given


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

N
Nihad Abbasov 已提交
208
Update project team member to specified access level.
M
miks 已提交
209 210

```
N
Nihad Abbasov 已提交
211
PUT /projects/:id/members/:user_id
M
miks 已提交
212 213 214 215
```

Parameters:

216
+ `id` (required) - The ID of a project
N
Nihad Abbasov 已提交
217 218
+ `user_id` (required) - The ID of a team member
+ `access_level` (required) - Project access level
M
miks 已提交
219

220 221 222 223 224 225
Return Values:

+ `200 Ok` on succes and the modified team member
+ `400 Bad Request` if the required attribute access_level is not given
+ `404 Not Found` if a resource can not be found, e.g. project with ID not available
+ `422 Unprocessable Entity` if an unknown access_level is given
M
miks 已提交
226

227 228

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

N
Nihad Abbasov 已提交
230
Removes user from project team.
M
miks 已提交
231 232

```
N
Nihad Abbasov 已提交
233
DELETE /projects/:id/members/:user_id
M
miks 已提交
234 235 236 237
```

Parameters:

238
+ `id` (required) - The ID of a project
N
Nihad Abbasov 已提交
239
+ `user_id` (required) - The ID of a team member
M
miks 已提交
240

241 242 243 244 245 246 247 248
Return Values:

+ `200 Ok` on success
+ `404 Not Found` if either project or user can not be found

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
249
rely on the returned JSON structure.
N
Nihad Abbasov 已提交
250

M
miks 已提交
251

252 253 254 255 256
## Hooks

### List project hooks

Get list of project hooks.
M
miks 已提交
257 258 259 260 261 262 263

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

Parameters:

264
+ `id` (required) - The ID of a project
M
miks 已提交
265

266 267 268 269 270
Return values:

+ `200 Ok` on success with a list of hooks
+ `404 Not Found` if project can not be found

M
miks 已提交
271

272
### Get project hook
273

274
Get a specific hook for project.
275 276 277 278 279

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

280
Parameters:
281

282
+ `id` (required) - The ID of a project
283 284
+ `hook_id` (required) - The ID of a project hook

285 286 287 288 289 290 291 292 293 294 295 296
```json
{
  "id": 1,
  "url": "http://example.com/hook",
  "created_at": "2012-10-12T17:04:47Z"
}
```

Return values:

+ `200 Ok` on sucess and the hook with the given ID
+ `404 Not Found` if the hook can not be found
297

M
miks 已提交
298

299 300 301
### Add project hook

Adds a hook to project.
M
miks 已提交
302 303 304 305 306 307 308

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

Parameters:

309
+ `id` (required) - The ID of a project
M
miks 已提交
310 311
+ `url` (required) - The hook URL

312 313 314 315 316 317
Return values:

+ `201 Created` on success and the newly created hook
+ `400 Bad Request` if url is not given
+ `404 Not Found` if project with ID not found
+ `422 Unprocessable Entity` if the url is invalid (must begin with `http` or `https`)
M
miks 已提交
318

319

320 321 322
### Edit project hook

Edits a hook for project.
323 324 325 326 327 328 329

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

Parameters:

330
+ `id` (required) - The ID of a project
331 332 333
+ `hook_id` (required) - The ID of a project hook
+ `url` (required) - The hook URL

334 335 336 337 338 339
Return values:

+ `200 Ok` on success and the modified hook (see JSON response above)
+ `400 Bad Request` if the url attribute is not given
+ `404 Not Found` if project or hook can not be found
+ `422 Unprocessable Entity` if the url is invalid (must begin with `http` or `https`)
340 341


342
### Delete project hook
M
miks 已提交
343

344 345
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 已提交
346 347 348 349 350 351 352

```
DELETE /projects/:id/hooks
```

Parameters:

353
+ `id` (required) - The ID of a project
M
miks 已提交
354 355
+ `hook_id` (required) - The ID of hook to delete

356 357 358 359 360 361 362
Return values:

+ `200 Ok` on succes
+ `404 Not Found` if the project can not be found

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.