BigW Consortium Gitlab

project_snippets.md 2.69 KB
Newer Older
1 2
# Project snippets

3 4 5 6 7 8 9 10 11 12 13 14 15
### Snippet visibility level

Snippets in GitLab can be either private, internal or public.
You can set it with the `visibility_level` field in the snippet.

Constants for snippet visibility levels are:

| Visibility | visibility_level | Description |
| ---------- | ---------------- | ----------- |
| Private    | `0`  | The snippet is visible only the snippet creator |
| Internal   | `10` | The snippet is visible for any logged in user |
| Public     | `20` | The snippet can be accessed without any authentication |

16 17
## List snippets

18 19 20 21 22 23 24 25
Get a list of project snippets.

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

Parameters:

26
- `id` (required) - The ID of a project
27

28 29
## Single snippet

30
Get a single project snippet.
31 32 33 34 35 36 37

```
GET /projects/:id/snippets/:snippet_id
```

Parameters:

38 39
- `id` (required) - The ID of a project
- `snippet_id` (required) - The ID of a project's snippet
40 41 42 43 44 45 46 47

```json
{
  "id": 1,
  "title": "test",
  "file_name": "add.rb",
  "author": {
    "id": 1,
48
    "username": "john_smith",
49 50
    "email": "john@example.com",
    "name": "John Smith",
51
    "state": "active",
52 53
    "created_at": "2012-05-23T08:00:58Z"
  },
54
  "expires_at": null,
55
  "updated_at": "2012-06-28T10:52:04Z",
56 57
  "created_at": "2012-06-28T10:52:04Z",
  "web_url": "http://example.com/example/example/snippets/1"
58 59 60
}
```

61
## Create new snippet
62

63
Creates a new project snippet. The user must have permission to create new snippets.
64 65 66 67 68 69 70

```
POST /projects/:id/snippets
```

Parameters:

71 72 73 74
- `id` (required) - The ID of a project
- `title` (required) - The title of a snippet
- `file_name` (required) - The name of a snippet file
- `code` (required) - The content of a snippet
75
- `visibility_level` (required) - The snippet's visibility
76

77
## Update snippet
78

79
Updates an existing project snippet. The user must have permission to change an existing snippet.
80 81 82 83 84 85 86

```
PUT /projects/:id/snippets/:snippet_id
```

Parameters:

87 88 89 90 91
- `id` (required) - The ID of a project
- `snippet_id` (required) - The ID of a project's snippet
- `title` (optional) - The title of a snippet
- `file_name` (optional) - The name of a snippet file
- `code` (optional) - The content of a snippet
92
- `visibility_level` (optional) - The snippet's visibility
93 94 95

## Delete snippet

96
Deletes an existing project snippet. This is an idempotent function and deleting a non-existent
97
snippet still returns a `200 OK` status code.
98 99 100 101 102 103 104

```
DELETE /projects/:id/snippets/:snippet_id
```

Parameters:

105 106
- `id` (required) - The ID of a project
- `snippet_id` (required) - The ID of a project's snippet
107 108 109

## Snippet content

110
Returns the raw project snippet as plain text.
111 112 113 114 115 116 117

```
GET /projects/:id/snippets/:snippet_id/raw
```

Parameters:

118 119
- `id` (required) - The ID of a project
- `snippet_id` (required) - The ID of a project's snippet