<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Project snippets > 原文:[https://docs.gitlab.com/ee/api/project_snippets.html](https://docs.gitlab.com/ee/api/project_snippets.html) * [Snippet visibility level](#snippet-visibility-level) * [List snippets](#list-snippets) * [Single snippet](#single-snippet) * [Create new snippet](#create-new-snippet) * [Update snippet](#update-snippet) * [Delete snippet](#delete-snippet) * [Snippet content](#snippet-content) * [Snippet repository file content](#snippet-repository-file-content) * [Get user agent details](#get-user-agent-details) # Project snippets[](#project-snippets "Permalink") ## Snippet visibility level[](#snippet-visibility-level "Permalink") GitLab 中的片段可以是私有的,內部的或公共的. 您可以使用代碼段中的`visibility`字段進行設置. 摘要可見性級別的常量為: | visibility | Description | | --- | --- | | `private` | 該代碼段僅在代碼段創建者中可見 | | `internal` | 所有已登錄的用戶都可以看到該代碼段 | | `public` | 無需任何身份驗證即可訪問該代碼段 | **注意:**從 2019 年 7 月開始,GitLab.com 上的新項目,組和摘要的`` `Internal`可見性''設置被禁用. 使用" `Internal`可見性"設置的現有項目,組和摘錄保留此設置. 您可以在[相關問題中](https://gitlab.com/gitlab-org/gitlab/-/issues/12388)閱讀有關更改的更多信息. ## List snippets[](#list-snippets "Permalink") 獲取項目摘要列表. ``` GET /projects/:id/snippets ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) ## Single snippet[](#single-snippet "Permalink") 獲得一個項目片段. ``` GET /projects/:id/snippets/:snippet_id ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `snippet_id` (必填)-項目代碼段的 ID ``` { "id": 1, "title": "test", "file_name": "add.rb", "description": "Ruby test snippet", "author": { "id": 1, "username": "john_smith", "email": "john@example.com", "name": "John Smith", "state": "active", "created_at": "2012-05-23T08:00:58Z" }, "updated_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z", "project_id": 1, "web_url": "http://example.com/example/example/snippets/1", "raw_url": "http://example.com/example/example/snippets/1/raw" } ``` ## Create new snippet[](#create-new-snippet "Permalink") 創建一個新的項目片段. 用戶必須具有創建新代碼段的權限. ``` POST /projects/:id/snippets ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `title` (required) - The title of a snippet * `file_name` (必填)-代碼段文件的名稱 * `description` (可選)-代碼段的說明 * `content` (必填)-代碼段的內容 * `visibility` (必填)-代碼段的可見性 請求示例: ``` curl --request POST "https://gitlab.com/api/v4/projects/:id/snippets" \ --header "PRIVATE-TOKEN: <your access token>" \ --header "Content-Type: application/json" \ -d @snippet.json ``` 上面的示例請求中使用的`snippet.json` : ``` { "title" : "Example Snippet Title", "description" : "More verbose snippet description", "file_name" : "example.txt", "content" : "source code \n with multiple lines\n", "visibility" : "private" } ``` ## Update snippet[](#update-snippet "Permalink") 更新現有的項目代碼段. 用戶必須具有更改現有代碼段的權限. ``` PUT /projects/:id/snippets/:snippet_id ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `snippet_id` (必填)-項目代碼段的 ID * `title` (可選)-摘要的標題 * `file_name` (可選)-代碼段文件的名稱 * `description` (可選)-代碼段的說明 * `content` (可選)-代碼段的內容 * `visibility` (可選)-代碼段的可見性 請求示例: ``` curl --request PUT "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id" \ --header "PRIVATE-TOKEN: <your_access_token>" \ --header "Content-Type: application/json" \ -d @snippet.json ``` 上面的示例請求中使用的`snippet.json` : ``` { "title" : "Updated Snippet Title", "description" : "More verbose snippet description", "file_name" : "new_filename.txt", "content" : "updated source code \n with multiple lines\n", "visibility" : "private" } ``` ## Delete snippet[](#delete-snippet "Permalink") 刪除現有項目片段. 如果操作成功,則返回`204 No Content`狀態代碼;如果找不到資源,則返回`404` . ``` DELETE /projects/:id/snippets/:snippet_id ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `snippet_id` (必填)-項目代碼段的 ID 請求示例: ``` curl --request DELETE "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id" \ --header "PRIVATE-TOKEN: <your_access_token>" ``` ## Snippet content[](#snippet-content "Permalink") 以純文本形式返回原始項目代碼段. ``` GET /projects/:id/snippets/:snippet_id/raw ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `snippet_id` (必填)-項目代碼段的 ID 請求示例: ``` curl "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id/raw" \ --header "PRIVATE-TOKEN: <your_access_token>" ``` ## Snippet repository file content[](#snippet-repository-file-content "Permalink") 以純文本形式返回原始文件的內容. ``` GET /projects/:id/snippets/:snippet_id/files/:ref/:file_path/raw ``` Parameters: * `id` (必填)-經過身份驗證的用戶擁有[的項目](README.html#namespaced-path-encoding)的 ID 或[URL 編碼路徑](README.html#namespaced-path-encoding) * `snippet_id` (必填)-項目代碼段的 ID * `ref` (必填)-分支,標記或提交的名稱,例如 master * `file_path` (必填)-文件的 URL 編碼路徑,例如 snippet%2Erb 請求示例: ``` curl "https://gitlab.com/api/v4/projects/1/snippets/2/files/master/snippet%2Erb/raw" \ --header "PRIVATE-TOKEN: <your_access_token>" ``` ## Get user agent details[](#get-user-agent-details "Permalink") 在 GitLab 9.4 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/29508) . 僅適用于管理員. ``` GET /projects/:id/snippets/:snippet_id/user_agent_detail ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | Integer | yes | 項目 ID | | `snippet_id` | Integer | yes | 片段的 ID | 請求示例: ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/snippets/2/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>

                              哎呀哎呀视频在线观看