### Get Repository Settings (Ruby) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-repo-settings This Ruby example uses the `net/http` library to make a GET request to the GitCode API for repository settings. It shows how to construct the URL, set headers, and process the response. ```ruby require 'net/http' require 'uri' owner = ':owner' repo = ':repo' access_token = '' uri = URI.parse("https://api.gitcode.com/api/v5/repos/#{owner}/#{repo}/repo_settings?access_token=#{access_token}") request = Net::HTTP::Get.new(uri.request_uri) request['Accept'] = 'application/json' response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request(request) end puts response.body ``` -------------------------------- ### Get Repository Single WebHook - HTTP Request Example Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-hooks-id This section provides a direct HTTP GET request example for fetching a single repository webhook. It specifies the URL structure and required parameters (owner, repo, id) and the authorization token. This is useful for testing the API endpoint directly or for use in scripting. ```http GET https://api.gitcode.com/api/v5/repos/:owner/:repo/hooks/:id --- **Query Parameters** **access_token** stringrequired 用户授权码 ``` -------------------------------- ### Get Repository Settings (Java) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-repo-settings This Java example shows how to use Apache HttpClient to perform a GET request to the GitCode API for repository settings. It covers creating the client, request, setting headers, and processing the response. ```java import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; public class GitCodeApi { public static void main(String[] args) throws ClientProtocolException, IOException { String url = "https://api.gitcode.com/api/v5/repos/:owner/:repo/repo_settings?access_token="; HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(url); request.addHeader("Accept", "application/json"); HttpResponse response = client.execute(request); String responseBody = EntityUtils.toString(response.getEntity()); System.out.println(responseBody); } } ``` -------------------------------- ### Get Pull Request Reactions (C# Example) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-pulls-number-user-reactions This C# code uses HttpClient to fetch user reactions for a GitCode Pull Request. It constructs the GET request, sets the Accept header, sends the request, and handles the response, ensuring it's successful before reading the content as a string. This example requires the .NET HttpClient class. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://api.gitcode.com/api/v5/repos/:owner/:repo/pulls/:number/user_reactions"); request.Headers.Add("Accept", "application/json"); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Get Repository Settings (JavaScript) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-repo-settings A JavaScript example using the `fetch` API to make a GET request to the GitCode API for repository settings. This demonstrates asynchronous request handling and response processing in a browser or Node.js environment. ```javascript async function getRepoSettings() { const owner = ':owner'; const repo = ':repo'; const accessToken = ''; const url = `https://api.gitcode.com/api/v5/repos/${owner}/${repo}/repo_settings?access_token=${accessToken}`; try { const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching repository settings:', error); } } getRepoSettings(); ``` -------------------------------- ### Get Repository Issues (API Request Example) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-issues This example demonstrates how to make an API request to retrieve all issues for a specific repository on GitCode. It requires the owner and repository name as path parameters, along with an access token. Optional query parameters can be used to filter and sort the results. ```http GET https://api.gitcode.com/api/v5/repos/:owner/:repo/issues?access_token=YOUR_ACCESS_TOKEN&state=open&labels=bug&sort=created&direction=desc&since=2024-11-10T08:10:30.000%2B08:00&page=1&per_page=20&created_at=2024-11-20T13:00:21+08:00&milestone=none&assignee=some_user_id&creator=some_username&created_after=2024-11-20T13:00:21+08:00&created_before=2024-11-20T13:00:21+08:00&updated_after=2024-11-20T13:00:21+08:00&updated_before=2024-11-20T13:00:21+08:00 ``` -------------------------------- ### Get Repository Tree (Go) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-git-trees-sha A Go program example for retrieving the repository directory tree from the GitCode API. It shows how to construct the request and process the JSON response. ```go package main import ( "fmt" "io/ioutil" "net/http" ) func main() { url := "https://api.gitcode.com/api/v5/repos/:owner/:repo/git/trees/:sha" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Accept", "application/json") resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Repository Tree (Java) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-git-trees-sha Java code example for fetching the repository directory tree using standard Java libraries. It demonstrates setting up the HTTP request and reading the response. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GitCodeTreeFetcher { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.gitcode.com/api/v5/repos/:owner/:repo/git/trees/:sha")) .header("Accept", "application/json") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` -------------------------------- ### Initialize HttpClient for GitCode API Request (C#) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-user-starred Demonstrates how to initialize an HttpClient object in C# to make requests to the GitCode API. This involves creating a client instance and defining the request method and URL. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://api.gitcode.com/api/v5/user/starred"); request.Headers.Add("Accept", "application/json"); ``` -------------------------------- ### Example GitCode API Repository Response Source: https://docs.gitcode.com/docs/apis/get-api-v-5-search-repositories This is an example of a successful response for retrieving repository information from the GitCode API. It demonstrates the structure and typical values for fields like repository name, URL, timestamps, and owner details. This example aids in understanding the data format. ```json { "id": 1431191, "full_name": "gh_mirrors/al/allure2", "human_name": "GitHub 加速计划 / al / allure2", "url": "https://api.gitcode.com/api/v5/repos/gh_mirrors/al/allure2", "namespace": { "id": 2192652, "type": "enterprise", "name": "al", "path": "al", "html_url": "https://gitcode.com/al" }, "path": "allure2", "name": "allure2", "description": "Allure Report is a flexible, lightweight multi-language test reporting tool. It provides clear graphical reports and allows everyone involved in the development process to extract the maximum of information from the everyday testing process", "status": "开始", "ssh_url_to_repo": "git@gitcode.com:gh_mirrors/al/allure2.git", "http_url_to_repo": "https://gitcode.com/gh_mirrors/al/allure2.git", "web_url": "https://gitcode.com/gh_mirrors/al/allure2", "created_at": "2023-12-18T00:42:15.557+08:00", "updated_at": "2024-11-05T10:54:59.948+08:00", "homepage": "https://gitcode.com/gh_mirrors/al/allure2", "members": [ "Gitcode-Assistant", "coco_gitcode", "gitshumei" ], "forks_count": 0, "stargazers_count": 9, "relation": "", "permission": { "push": false }, "internal": false, "open_issues_count": 0, "has_issue": false, "watchers_count": 4, "enterprise": { "id": 2192652, "path": "al", "html_url": "https://gitcode.com/al", "type": "enterprise" }, "default_branch": "main", "fork": false, "pushed_at": "2024-08-06T23:34:38.476+08:00", "owner": { "id": "69090", "login": "coco_gitcode", "name": "GitCode优质项目", "type": "User" }, "issue_template_source": "project", "private": false, "public": true } ``` -------------------------------- ### Get Repository Commits (JSON Example) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-commits This is an example response from the GitCode API for retrieving repository commits. It shows a single commit object with all its associated details, including URLs, SHA, commit message, author, and committer information. ```json { "url": "https://api.gitcode.com/api/v5/repos/mactribe/test02/commits/66a12f572722ebe2cad44f44d48e253a0f027e09", "sha": "66a12f572722ebe2cad44f44d48e253a0f027e09", "html_url": "https://test.gitcode.net/mactribe/test02/commits/detail/66a12f572722ebe2cad44f44d48e253a0f027e09", "comments_url": "https://api.gitcode.com/api/v5/repos/mactribe/test02/commits/66a12f572722ebe2cad44f44d48e253a0f027e09/comments", "commit": { "author": { "date": "2024-09-25T08:14:59+08:00", "email": "my@dengmengmian.com" }, "committer": { "date": "2024-09-25T08:14:59+08:00", "email": "my@dengmengmian.com" }, "tree": { "sha": "6214a5921eda7f5148f249587b74201d5946a6d4", "url": "https://api.gitcode.com/api/v5/repos/mactribe/test02/git/trees/6214a5921eda7f5148f249587b74201d5946a6d4" }, "message": "feat:所有issue number 都改为 string 类型" }, "author": { "email": "my@dengmengmian.com", "login": "dengmengmian(麻凡)", "type": "User" }, "committer": { "date": "2024-09-25T08:14:59+08:00", "email": "my@dengmengmian.com", "type": "User" }, "parents": [ { "sha": "0c41318014c472534a2abc2e0aa498fd49d046f1", "url": "https://api.gitcode.com/api/v5/repos/mactribe/test02/commits/0c41318014c472534a2abc2e0aa498fd49d046f1" } ] } ``` -------------------------------- ### Get Repository Settings (Curl) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-repo-settings A command-line example using curl to fetch repository settings from the GitCode API. This demonstrates a basic GET request with necessary parameters. ```shell curl -X GET "https://api.gitcode.com/api/v5/repos/:owner/:repo/repo_settings?access_token=" -H "Accept: application/json" ``` -------------------------------- ### List Repository Webhooks using cURL (Shell) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-hooks This example shows how to list repository webhooks using cURL from the command line. It specifies the HTTP method, the API endpoint URL, and includes the required 'access_token' query parameter. Replace ':owner', ':repo', and 'YOUR_ACCESS_TOKEN' with your specific details. ```shell curl -X GET "https://api.gitcode.com/api/v5/repos/:owner/:repo/hooks?access_token=YOUR_ACCESS_TOKEN" ``` -------------------------------- ### Get Enterprise Milestone Details using Python Source: https://docs.gitcode.com/docs/apis/get-api-v-8-enterprise-enterprise-id-milestones-milestone-id This Python script uses the `requests` library to fetch enterprise milestone details. It sends a GET request to the GitCode API endpoint, including the access token as a query parameter, and prints the JSON response. Ensure you have the `requests` library installed (`pip install requests`). ```python import requests def get_enterprise_milestone(enterprise_id, milestone_id, access_token): url = f"https://api.gitcode.com/api/v8/enterprises/{enterprise_id}/milestones/{milestone_id}" params = { "access_token": access_token } headers = { "Accept": "application/json" } response = requests.get(url, params=params, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() # Example usage: # enterprise_id = "your_enterprise_id" # milestone_id = "your_milestone_id" # access_token = "your_access_token" # try: # milestone_data = get_enterprise_milestone(enterprise_id, milestone_id, access_token) # print(milestone_data) # except requests.exceptions.RequestException as e: # print(f"Error: {e}") ``` -------------------------------- ### OAuth Token Response Example Source: https://docs.gitcode.com/docs/apis/oauth An example JSON response when successfully exchanging an authorization code for an access token. It includes the access token, its expiration time, refresh token, granted scopes, and creation timestamp. ```JSON { "access_token": "eyPZPVNfsibj9tap_ibj3t3p", "expires_in": 1296000, "refresh_token": "b77ced3aee884348852160deab3697a1", "scope": "all_user all_key all_groups all_projects all_pr all_issue all_note all_hook all_repository", "created_at": "2024-04-20T09:07:59.889Z" } ``` -------------------------------- ### Get Repository Events using various languages Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-events-access-token-your-token This section provides code examples for fetching repository events from the GitCode API. It demonstrates how to make GET requests to the specified endpoint, including setting required parameters and handling responses. Supported languages include C#, Curl, Dart, Go, HTTP, Java, JavaScript, Kotlin, C, Node.js, Objective-C, OCaml, PHP, PowerShell, Python, R, Ruby, Rust, Shell, and Swift. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://api.gitcode.com/api/v5/repos/:owner/:repo/events"); request.Headers.Add("Accept", "application/json"); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` ```curl curl -X GET "https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN" ``` ```dart import 'package:http/http.dart' as http; Future getRepoEvents(String owner, String repo, String accessToken) async { final url = Uri.parse('https://api.gitcode.com/api/v5/repos/$owner/$repo/events'); final response = await http.get(url, headers: { 'Authorization': 'token $accessToken', 'Accept': 'application/json', }); if (response.statusCode == 200) { print(response.body); } else { print('Request failed with status: ${response.statusCode}.'); } } // Example usage: // getRepoEvents('owner', 'repo', 'YOUR_ACCESS_TOKEN'); ``` ```go package main import ( "fmt" "io/ioutil" "net/http" ) func main() { url := "https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN" resp, err := http.Get(url) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GitCodeEvents { public static void main(String[] args) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN")) .header("Accept", "application/json") .build(); try { HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` ```javascript async function getRepoEvents(owner, repo, accessToken) { const url = `https://api.gitcode.com/api/v5/repos/${owner}/${repo}/events?access_token=${accessToken}`; try { const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching repository events:', error); } } // Example usage: // getRepoEvents('owner', 'repo', 'YOUR_ACCESS_TOKEN'); ``` ```kotlin import okhttp3.OkHttpClient import okhttp3.Request fun main() { val client = OkHttpClient() val request = Request.Builder() .url("https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN") .header("Accept", "application/json") .build() client.newCall(request).execute().use { response -> if (!response.isSuccessful) throw IOException("Unexpected code $response") val responseBody = response.body?.string() println(responseBody) } } ``` ```php ``` ```powershell $owner = "owner" $repo = "repo" $accessToken = "YOUR_ACCESS_TOKEN" $url = "https://api.gitcode.com/api/v5/repos/$owner/$repo/events?access_token=$accessToken" $response = Invoke-RestMethod -Uri $url -Method Get -Headers @{ "Accept" = "application/json" } Write-Host $response ``` ```python import requests def get_repo_events(owner, repo, access_token): url = f"https://api.gitcode.com/api/v5/repos/{owner}/{repo}/events" params = { 'access_token': access_token, 'filter': 'all' # Example filter } headers = { 'Accept': 'application/json' } response = requests.get(url, params=params, headers=headers) response.raise_for_status() # Raise an exception for bad status codes return response.json() # Example usage: # owner = 'owner' # repo = 'repo' # access_token = 'YOUR_ACCESS_TOKEN' # events = get_repo_events(owner, repo, access_token) # print(events) ``` ```ruby require 'net/http' require 'uri' uri = URI.parse("https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN") request = Net::HTTP::Get.new(uri) request['Accept'] = 'application/json' response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request(request) end puts response.body ``` ```rust use reqwest::Error; #[tokio::main] async fn main() -> Result<(), Error> { let client = reqwest::Client::new(); let url = "https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN"; let response = client.get(url) .header("Accept", "application/json") .send() .await?; let body = response.text().await?; println!("{}", body); Ok(()) } ``` ```shell curl -X GET "https://api.gitcode.com/api/v5/repos/:owner/:repo/events?access_token=YOUR_ACCESS_TOKEN" \ -H "Accept: application/json" ``` -------------------------------- ### Get Repository Tree (HTTP Request) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-git-trees-sha Demonstrates how to make an HTTP GET request to the GitCode API to fetch the directory tree of a repository. This is a foundational example for interacting with the API. ```http GET https://api.gitcode.com/api/v5/repos/:owner/:repo/git/trees/:sha ``` -------------------------------- ### Create Repository Label (Go) Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-labels This Go code illustrates how to create a repository label using the standard net/http package. It sets up a POST request, adds necessary headers, and encodes the label information into the request body. The response is then printed or handled based on the status code. ```go package main import ( "fmt" "net/http" "strings" ) func main() { url := "https://api.gitcode.com/api/v5/repos/:owner/:repo/labels" payload := strings.NewReader("access_token=&name=&color=") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("content-type", "application/x-www-form-urlencoded") req.Header.Add("Accept", "application/json") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() // Process response body and status code here fmt.Println(res.StatusCode) } ``` -------------------------------- ### Get Repository Labels using Node.js http Module Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-labels This Node.js example uses the built-in 'http' module to make a GET request to the GitCode API for repository labels and logs the response. ```nodejs const http = require('http'); const options = { hostname: 'api.gitcode.com', port: 80, path: '/api/v5/repos/:owner/:repo/labels', method: 'GET', headers: { 'Accept': 'application/json' } }; const req = http.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }); req.on('error', (error) => { console.error(`Error: ${error}`); }); req.end(); ``` -------------------------------- ### C# HttpClient Example for Enterprise Group Projects API Source: https://docs.gitcode.com/docs/apis/get-api-v-8-enterprise-enterprise-id-groups-projects Provides a C# example using HttpClient to call the GitCode API for fetching enterprise group projects. It shows how to set up the request, add necessary headers, send the request, and process the JSON response. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://api.gitcode.com/api/v8/enterprises/:enterprise/groups/projects"); request.Headers.Add("Accept", "application/json"); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Create File (Rust) Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-contents-path This Rust code snippet demonstrates creating a file using the `reqwest` crate. It shows how to construct a POST request with a JSON body and handle the asynchronous response. ```rust use reqwest::Error; use serde_json::json; #[tokio::main] async fn main() -> Result<(), Error> { let client = reqwest::Client::new(); let url = "https://api.gitcode.com/api/v5/repos/:owner/:repo/contents/:path"; let access_token = ""; let response = client.post(url) .header("Content-Type", "application/json") .header("Authorization", format!("token {}", access_token)) .json(&json!({ "content": "string", "message": "string", "branch": "string", "author[name]": "string", "author[email]": "string" })) .send() .await?; if response.status().is_success() { let body = response.text().await?; println!("File created successfully: {}", body); } else { println!("Failed to create file: Status code {}", response.status()); } Ok(()) } ``` -------------------------------- ### Get Pull Request Settings with JavaScript (Fetch API) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-pull-request-settings A JavaScript example using the Fetch API to get pull request settings from GitCode. This asynchronous function makes a GET request and handles the response, logging the JSON data to the console. ```javascript async function getPullRequestSettings(owner, repo, accessToken) { const url = `https://api.gitcode.com/api/v5/repos/${owner}/${repo}/pull_request_settings?access_token=${accessToken}`; try { const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching pull request settings:', error); } } ``` -------------------------------- ### Download Statistics API Successful Response Example Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-download-statistics This JSON example represents a successful response from the download statistics API. It provides a detailed breakdown of download counts for multiple days, along with the total and historical download statistics. ```JSON { "download_statistics_detail": [ { "pdate": "2024-11-13", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 38 }, { "pdate": "2024-11-14", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 38 }, { "pdate": "2024-11-15", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 38 }, { "pdate": "2024-11-16", "repo_id": "625513", "today_dl_cnt": 5, "total_dl_cnt": 43 }, { "pdate": "2024-11-17", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 43 }, { "pdate": "2024-11-18", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 43 }, { "pdate": "2024-11-19", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 43 }, { "pdate": "2024-11-20", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 43 }, { "pdate": "2024-11-21", "repo_id": "625513", "today_dl_cnt": 2, "total_dl_cnt": 45 }, { "pdate": "2024-11-22", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 45 }, { "pdate": "2024-11-23", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 45 }, { "pdate": "2024-11-24", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 45 }, { "pdate": "2024-11-25", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 45 }, { "pdate": "2024-11-26", "repo_id": "625513", "today_dl_cnt": 0, "total_dl_cnt": 45 } ], "download_statistics_total": 7, "download_statistics_history_total": 45 } ``` -------------------------------- ### Get User Namespace Example Response Source: https://docs.gitcode.com/docs/apis/get-api-v-5-user-namespace This is an example of a successful JSON response when retrieving a user's namespace using the GitCode API. It includes the namespace's unique ID, its path, a display name, its HTML URL on GitCode, and its type (e.g., 'group'). ```json { "id": 138108, "path": "xiaogang_test", "name": "aaasfd/sda/fsdaf/sdfsa", "html_url": "https://gitcode.com/xiaogang_test", "type": "group" } ``` -------------------------------- ### Create File (Java) Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-contents-path This Java code snippet demonstrates creating a file using the `HttpURLConnection` class. It shows how to set up the POST request, write the JSON payload to the output stream, and read the response from the input stream. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class CreateFile { public static void main(String[] args) { try { URL url = new URL("https://api.gitcode.com/api/v5/repos/:owner/:repo/contents/:path"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Authorization", "token "); String jsonInputString = "{\"content\": \"string\", \"message\": \"string\", \"branch\": \"string\", \"author[name]\": \"string\", \"author[email]\": \"string\"}"; try (OutputStream os = conn.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = conn.getResponseCode(); System.out.println("POST Response Code: " + responseCode); if (responseCode == HttpURLConnection.HTTP_CREATED) { // 201 Created System.out.println("File created successfully."); } else { System.out.println("Failed to create file."); } conn.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Download Statistics API Response Example (JSON) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-download-statistics This is an example of the JSON response returned by the download statistics API. It includes details such as download counts for specific dates, total download counts, and historical totals. ```JSON { "download_statistics_detail": [ { "pdate": "string", "repo_id": "string", "today_dl_cnt": 0, "total_dl_cnt": 0 } ], "download_statistics_total": 0, "download_statistics_history_total": 0 } ``` -------------------------------- ### GitCode API Example Successful Response (JSON) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-user-starred Illustrates a typical JSON object returned by the GitCode API upon a successful request. This example provides concrete values for the fields defined in the schema. ```json { "id": 777621, "full_name": "xiaogang/private-new2", "human_name": "xiaogang / private-new2", "url": "https://api.gitcode.com/api/v5/repos/xiaogang/private-new2", "namespace": { "id": 137117, "type": "user", "name": "xiaogang", "path": "xiaogang", "html_url": "https://gitcode.com/xiaogang" }, "path": "private-new2", "name": "private-new2", "parentfull_name": "xiaogang_test/private-new", "description": "特朗普", "status": "开始", "ssh_url_to_repo": "ssh://git@gitcode.com:2222/xiaogang/private-new2.git", "http_url_to_repo": "https://gitcode.com/xiaogang/private-new2.git", "web_url": "https://gitcode.com/xiaogang/private-new2", "created_at": "2024-12-11T17:41:14.536+08:00", "updated_at": "2024-12-11T17:41:14.536+08:00", "homepage": "https://gitcode.com/xiaogang/private-new2", "members": [ "xiaogang" ], "parent": { "full_name": "xiaogang_test/private-new", "human_name": "xiaogang_test / private-new" }, "forks_count": 0, "stargazers_count": 1, "relation": "master", "permission": { "pull": true, "push": true, "admin": true }, "internal": false, "open_issues_count": 0, "has_issue": false, "has_issues": false, "watchers_count": 0, "enterprise": { "id": 137117, "path": "xiaogang", "html_url": "https://gitcode.com/xiaogang", "type": "user" }, "default_branch": "main", "fork": true, "pushed_at": "2024-12-20T19:14:34.979+08:00", "owner": { "id": "496", "login": "xiaogang", "name": "肖刚", "type": "User" }, "issue_template_source": "project", "project_creator": "xiaogang", "private": false, "public": true } ``` -------------------------------- ### Get Repository Labels using cURL Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-labels This example shows how to fetch repository labels from the GitCode API using a cURL command. It specifies the GET method and the API endpoint, including necessary path parameters. ```curl GET https://api.gitcode.com/api/v5/repos/:owner/:repo/labels ``` -------------------------------- ### Get Enterprise Milestone Details using HTTP GET Request Source: https://docs.gitcode.com/docs/apis/get-api-v-8-enterprise-enterprise-id-milestones-milestone-id This example illustrates a basic HTTP GET request to retrieve enterprise milestone details. It shows the endpoint URL and expected parameters. This can be adapted for use with various HTTP clients or command-line tools. ```http GET https://api.gitcode.com/api/v8/enterprises/:enterprise/milestones/:milestone_id?access_token=USER_AUTH_CODE ``` -------------------------------- ### Example Response (Partial Data - JSON) Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-pulls-number-testers This example demonstrates a successful response from the GitCode API where not all fields (like avatar_url) are present for the assigned tester. It still adheres to the general response structure but highlights potential variations in returned data. ```json { "id": 452, "login": "zhanghq2", "name": "zhanghq2" } ``` -------------------------------- ### Create File (Go) Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-contents-path This Go code snippet shows how to create a file in a GitCode repository using the `net/http` package. It constructs a POST request with a JSON body containing the file content and commit details, and handles the response. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.gitcode.com/api/v5/repos/:owner/:repo/contents/:path" method := "POST" requestBody, err := json.Marshal(map[string]string{ "content": "string", "message": "string", "branch": "string", "author[name]": "string", "author[email]": "string", }) if err != nil { fmt.Printf("Error marshaling JSON: %v\n", err) return } client := &http.Client{} req, err := http.NewRequest(method, url, bytes.NewBuffer(requestBody)) if err != nil { fmt.Printf("Error creating request: %v\n", err) return } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "token ") resp, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %v\n", err) return } defer resp.Body.Close() if resp.StatusCode == http.StatusCreated { fmt.Println("File created successfully") } else { fmt.Printf("Error creating file: Status Code %d\n", resp.StatusCode) } } ``` -------------------------------- ### Get Enterprise Labels List (C#) Source: https://docs.gitcode.com/docs/apis/get-api-v-8-enterprises-enterprise-labels Provides a C# example using HttpClient to fetch labels for an enterprise. This code sends a GET request to the GitCode API and handles the response, ensuring success and reading the content as a string. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://api.gitcode.com/api/v8/enterprises/:enterprise/labels"); request.Headers.Add("Accept", "application/json"); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Create Repository Tag using Go Source: https://docs.gitcode.com/docs/apis/post-api-v-5-repos-owner-repo-tags This Go code example demonstrates creating a repository tag using the http client. It sends a POST request to the GitCode API, including the owner, repository name, access token, and the tag details in the request body. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.gitcode.com/api/v5/repos/:owner/:repo/tags" accessToken := "" tagData := map[string]string{ "refs": "main", "tag_name": "v1.0.0", "tag_message": "Initial release" } jsonData, err := json.Marshal(tagData) if err != nil { fmt.Println("Error marshaling JSON:", err) return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") req.Header.Set("Authorization", "token "+accessToken) client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() fmt.Println("Status Code:", resp.StatusCode) // Process response body here } ``` -------------------------------- ### Get Repository Settings (Python) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-repos-owner-repo-repo-settings This Python example uses the `requests` library to make an HTTP GET request to the GitCode API to fetch repository settings. It demonstrates setting parameters, headers, and handling the JSON response. ```python import requests owner = ':owner' repo = ':repo' access_token = '' url = f"https://api.gitcode.com/api/v5/repos/{owner}/{repo}/repo_settings" params = { 'access_token': access_token } headers = { 'Accept': 'application/json' } try: response = requests.get(url, params=params, headers=headers) response.raise_for_status() # Raise an exception for bad status codes data = response.json() print(data) except requests.exceptions.RequestException as e: print(f"Error fetching repository settings: {e}") ``` -------------------------------- ### GitCode API Successful Event Data Example (JSON) Source: https://docs.gitcode.com/docs/apis/get-api-v-5-users-username-events This is an example of a successful response from the GitCode API, illustrating the data structure for events. It showcases a 'pushed to' action with detailed author, project, and push information, including commit hashes and branch names. ```json { "events": { "2024-08-27": [ { "action": 5, "action_name": "pushed to", "author": { "id": 704, "iam_id": "5c340cab034d455992541f00f9936fb4", "username": "dengmengmian", "state": "active", "avatar_url": "https://gitcode-img.obs.cn-south-1.myhuaweicloud.com:443/fa/fe/f32a9fecc53e890afbd48fd098b0f6c5f20f062581400c76c85e5baab3f0d5b2.png", "email": "", "name": "dengmengmian", "name_cn": "dengmengmian", "web_url": "https://test.gitcode.net/dengmengmian" }, "author_id": 704, "author_username": "dengmengmian", "created_at": "2024-08-27T10:34:05.093Z", "project": { "main_repository_language": [ null, null ], "star_count": 0, "forks_count": 0, "develop_mode": "normal", "stared": false }, "project_id": 507167, "project_name": "mactribe/midsommarcartoon", "push_data": { "commit_count": 1, "action": "pushed", "ref_type": "branch", "commit_from": "2ce472fec073f77804c3480ccf128219a6172e54", "commit_to": "14b742fe434797fb073ba536804011f735f2f430", "ref": "main", "commit_title": "文件title" }, "_links": { "project": "https://test.gitcode.net/mactribe/midsommarcartoon", "action_type": "" } }, { "action": 5, "action_name": "pushed to", "author": { "id": 704, "iam_id": "5c340cab034d455992541f00f9936fb4", "username": "dengmengmian", "state": "active", "avatar_url": "https://gitcode-img.obs.cn-south-1.myhuaweicloud.com:443/fa/fe/f32a9fecc53e890afbd48fd098b0f6c5f20f062581400c76c85e5baab3f0d5b2.png", "email": "", "name": "dengmengmian", "name_cn": "dengmengmian", "web_url": "https://test.gitcode.net/dengmengmian" }, "author_id": 704, "author_username": "dengmengmian", "created_at": "2024-08-27T10:31:17.494Z", "project": { "main_repository_language": [ null, null ], "star_count": 0, "forks_count": 0, "develop_mode": "normal", "stared": false }, "project_id": 507167, "project_name": "mactribe/midsommarcartoon", "push_data": { "commit_count": 1, "action": "pushed", "ref_type": "branch" } } ] }, "next": "string" } ```