<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Snippets API > 原文:[https://docs.gitlab.com/ee/api/snippets.html](https://docs.gitlab.com/ee/api/snippets.html) * [Snippet visibility level](#snippet-visibility-level) * [List all snippets for a user](#list-all-snippets-for-a-user) * [Get a single snippet](#get-a-single-snippet) * [Single snippet contents](#single-snippet-contents) * [Snippet repository file content](#snippet-repository-file-content) * [Create new snippet](#create-new-snippet) * [Update snippet](#update-snippet) * [Delete snippet](#delete-snippet) * [List all public snippets](#list-all-public-snippets) * [Get user agent details](#get-user-agent-details) # Snippets API[](#snippets-api "Permalink") 在 GitLab 8.15 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/6373) . 片段 API 在[片段上](../user/snippets.html)運行. ## Snippet visibility level[](#snippet-visibility-level "Permalink") GitLab 中的代碼段可以是私有的,內部的或公共的. 您可以使用代碼段中的`visibility`字段進行設置. 代碼段可見性級別的有效值為: | Visibility | Description | | --- | --- | | `private` | 摘要僅對摘要創建者可見. | | `internal` | 所有已登錄用戶都可以看到該代碼段. | | `public` | 無需任何身份驗證即可訪問代碼段. | ## List all snippets for a user[](#list-all-snippets-for-a-user "Permalink") 獲取當前用戶的片段列表. ``` GET /snippets ``` 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets" ``` 響應示例: ``` [ { "id": 42, "title": "Voluptatem iure ut qui aut et consequatur quaerat.", "file_name": "mclaughlin.rb", "description": null, "visibility": "internal", "author": { "id": 22, "name": "User 0", "username": "user0", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon", "web_url": "http://example.com/user0" }, "updated_at": "2018-09-18T01:12:26.383Z", "created_at": "2018-09-18T01:12:26.383Z", "project_id": null, "web_url": "http://example.com/snippets/42", "raw_url": "http://example.com/snippets/42/raw" }, { "id": 41, "title": "Ut praesentium non et atque.", "file_name": "ondrickaemard.rb", "description": null, "visibility": "internal", "author": { "id": 22, "name": "User 0", "username": "user0", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/52e4ce24a915fb7e51e1ad3b57f4b00a?s=80&d=identicon", "web_url": "http://example.com/user0" }, "updated_at": "2018-09-18T01:12:26.360Z", "created_at": "2018-09-18T01:12:26.360Z", "project_id": 1, "web_url": "http://example.com/gitlab-org/gitlab-test/snippets/41", "raw_url": "http://example.com/gitlab-org/gitlab-test/snippets/41/raw" } ] ``` ## Get a single snippet[](#get-a-single-snippet "Permalink") 取得一個摘要. ``` GET /snippets/:id ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 要檢索的代碼段的 ID. | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1" ``` 響應示例: ``` { "id": 1, "title": "test", "file_name": "add.rb", "description": "Ruby test snippet", "visibility": "private", "author": { "id": 1, "username": "john_smith", "email": "john@example.com", "name": "John Smith", "state": "active", "created_at": "2012-05-23T08:00:58Z" }, "expires_at": null, "updated_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z", "project_id": null, "web_url": "http://example.com/snippets/1", "raw_url": "http://example.com/snippets/1/raw" } ``` ## Single snippet contents[](#single-snippet-contents "Permalink") 獲取單個代碼段的原始內容. ``` GET /snippets/:id/raw ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 要檢索的代碼段的 ID. | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/raw" ``` 響應示例: ``` Hello World snippet ``` ## Snippet repository file content[](#snippet-repository-file-content "Permalink") 以純文本形式返回原始文件的內容. ``` GET /snippets/:id/files/:ref/:file_path/raw ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 要檢索的代碼段 ID | | `ref` | string | yes | 引用標簽,分支或提交 | | `file_path` | string | yes | 文件的 URL 編碼路徑 | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/files/master/snippet%2Erb/raw" ``` 響應示例: ``` Hello World snippet ``` ## Create new snippet[](#create-new-snippet "Permalink") 創建一個新的代碼段. **注意:**用戶必須具有創建新代碼段的權限. ``` POST /snippets ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `title` | string | yes | 摘要的標題. | | `file_name` | string | yes | 片段文件的名稱. | | `content` | string | yes | 摘要的內容. | | `description` | string | no | 片段說明. | | `visibility` | string | no | Snippet’s [visibility](#snippet-visibility-level). | 請求示例: ``` curl --request POST \ --data '{"title": "This is a snippet", "content": "Hello world", "description": "Hello World snippet", "file_name": "test.txt", "visibility": "internal" }' \ --header 'Content-Type: application/json' \ --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/snippets" ``` 響應示例: ``` { "id": 1, "title": "This is a snippet", "file_name": "test.txt", "description": "Hello World snippet", "visibility": "internal", "author": { "id": 1, "username": "john_smith", "email": "john@example.com", "name": "John Smith", "state": "active", "created_at": "2012-05-23T08:00:58Z" }, "expires_at": null, "updated_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z", "project_id": null, "web_url": "http://example.com/snippets/1", "raw_url": "http://example.com/snippets/1/raw" } ``` ## Update snippet[](#update-snippet "Permalink") 更新現有代碼段. **注意:**用戶必須具有更改現有代碼段的權限. ``` PUT /snippets/:id ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 要更新的代碼段 ID. | | `title` | string | no | 摘要的標題. | | `file_name` | string | no | 片段文件的名稱. | | `description` | string | no | 片段說明. | | `content` | string | no | 摘要的內容. | | `visibility` | string | no | Snippet’s [visibility](#snippet-visibility-level). | 請求示例: ``` curl --request PUT \ --data '{"title": "foo", "content": "bar"}' \ --header 'Content-Type: application/json' \ --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/snippets/1" ``` 響應示例: ``` { "id": 1, "title": "test", "file_name": "add.rb", "description": "description of snippet", "visibility": "internal", "author": { "id": 1, "username": "john_smith", "email": "john@example.com", "name": "John Smith", "state": "active", "created_at": "2012-05-23T08:00:58Z" }, "expires_at": null, "updated_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z", "project_id": null, "web_url": "http://example.com/snippets/1", "raw_url": "http://example.com/snippets/1/raw" } ``` ## Delete snippet[](#delete-snippet "Permalink") 刪除現有的代碼段. ``` DELETE /snippets/:id ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 要刪除的代碼段的 ID. | 請求示例: ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1" ``` 以下是可能的返回碼: | Code | Description | | --- | --- | | `204` | 刪除成功. 沒有數據返回. | | `404` | 找不到該代碼段. | ## List all public snippets[](#list-all-public-snippets "Permalink") 列出所有公共摘要. ``` GET /snippets/public ``` Parameters: | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `per_page` | integer | no | 每頁要返回的代碼段數. | | `page` | integer | no | 要檢索的頁面. | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/public?per_page=2&page=1" ``` 響應示例: ``` [ { "author": { "avatar_url": "http://www.gravatar.com/avatar/edaf55a9e363ea263e3b981d09e0f7f7?s=80&d=identicon", "id": 12, "name": "Libby Rolfson", "state": "active", "username": "elton_wehner", "web_url": "http://example.com/elton_wehner" }, "created_at": "2016-11-25T16:53:34.504Z", "file_name": "oconnerrice.rb", "id": 49, "title": "Ratione cupiditate et laborum temporibus.", "updated_at": "2016-11-25T16:53:34.504Z", "project_id": null, "web_url": "http://example.com/snippets/49", "raw_url": "http://example.com/snippets/49/raw" }, { "author": { "avatar_url": "http://www.gravatar.com/avatar/36583b28626de71061e6e5a77972c3bd?s=80&d=identicon", "id": 16, "name": "Llewellyn Flatley", "state": "active", "username": "adaline", "web_url": "http://example.com/adaline" }, "created_at": "2016-11-25T16:53:34.479Z", "file_name": "muellershields.rb", "id": 48, "title": "Minus similique nesciunt vel fugiat qui ullam sunt.", "updated_at": "2016-11-25T16:53:34.479Z", "project_id": null, "web_url": "http://example.com/snippets/48", "raw_url": "http://example.com/snippets/49/raw", "visibility": "public" } ] ``` ## Get user agent details[](#get-user-agent-details "Permalink") 在 GitLab 9.4 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/12655) . **注意:**僅適用于管理員. ``` GET /snippets/:id/user_agent_detail ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer | yes | 摘要的 ID. | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/snippets/1/user_agent_detail" ``` 響應示例: ``` { "user_agent": "AppleWebKit/537.36", "ip_address": "127.0.0.1", "akismet_submitted": false } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看