From 0ec2242497ef3ae7d44602bdb4dbc16f007c2e06 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 12 Jan 2024 16:58:25 +0800 Subject: [PATCH] public-api: encode the params for public api (#1715) --- configs/public_api/openapi.yaml | 748 +++++++++--------- .../services/tidb-data-service/index.ts | 19 +- .../src/routes/v1/trends/repos/index.ts | 7 +- packages/api-server/src/utils/endpoint.ts | 9 +- web/docs/api/list-collections.api.mdx | 4 +- web/docs/api/list-trending-repos.api.mdx | 6 +- 6 files changed, 405 insertions(+), 388 deletions(-) diff --git a/configs/public_api/openapi.yaml b/configs/public_api/openapi.yaml index 35e80f4d81b..64b0461acae 100644 --- a/configs/public_api/openapi.yaml +++ b/configs/public_api/openapi.yaml @@ -269,10 +269,10 @@ paths: properties: repo_id: type: string - description: Collection ID + description: Repository ID repo_name: type: string - description: Collection name + description: Repository name additionalProperties: true example: - id: "1" @@ -329,81 +329,13 @@ paths: limit: 50 databases: - gharchive_dev - /trends/repos/: + /collections/hot/: get: - operationId: list-trending-repos - summary: List trending repos + operationId: list-hot-collections + summary: List hot collections tags: - - Trends - description: >- - Trending repos is an open source alternative to GitHub trends, which - showcases recently popular open source projects in the GitHub community. - - - ā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events. - parameters: - - schema: - type: string - enum: - - past_24_hours - - past_week - - past_month - - past_3_months - default: past_24_hours - in: query - name: period - required: false - description: Specify the period of time to calculate trending repos. - - schema: - type: string - enum: - - All - - JavaScript - - Java - - Python - - PHP - - C++ - - C# - - TypeScript - - Shell - - C - - Ruby - - Rust - - Go - - Kotlin - - HCL - - PowerShell - - CMake - - Groovy - - PLpgSQL - - TSQL - - Dart - - Swift - - HTML - - CSS - - Elixir - - Haskell - - Solidity - - Assembly - - R - - Scala - - Julia - - Lua - - Clojure - - Erlang - - Common Lisp - - Emacs Lisp - - OCaml - - MATLAB - - Objective-C - - Perl - - Fortran - default: All - in: query - name: language - required: false - description: Specify using which programming language to filter trending repos. - If not specified, all languages will be included. + - Collections + description: List hot collections with top repositories of the collection. responses: "200": description: Default Response @@ -479,122 +411,109 @@ paths: description: Whether the column is nullable. additionalProperties: true example: + - col: id + data_type: BIGINT + nullable: false + - col: name + data_type: VARCHAR + nullable: false + - col: repos + data_type: BIGINT + nullable: false - col: repo_id - data_type: INT - nullable: true + data_type: BIGINT + nullable: false - col: repo_name data_type: VARCHAR - nullable: true - - col: primary_language - data_type: VARCHAR - nullable: true - - col: description - data_type: VARCHAR - nullable: true - - col: stars - data_type: INT - nullable: true - - col: forks - data_type: INT - nullable: true - - col: pull_requests + nullable: false + - col: repo_current_period_rank data_type: INT nullable: true - - col: pushes + - col: repo_past_period_rank data_type: INT nullable: true - - col: total_score - data_type: DOUBLE - nullable: true - - col: contributor_logins - data_type: VARCHAR - nullable: true - - col: collection_names - data_type: VARCHAR + - col: repo_rank_changes + data_type: BIGINT nullable: true rows: type: array items: type: object properties: - repo_id: - type: string - description: ID of the repo - repo_name: - type: string - description: Name of the repo - primary_language: - type: string - description: Primary programing language used by the repo - description: + id: type: string - description: Description of the repo - stars: + description: Collection ID + name: type: string - description: Number of stars in the period - forks: + description: Collection name + repos: type: string - description: Number of forks in the period - pull_requests: + description: The number of repositories in the collection + repo_id: type: string - description: Number of pull requests in the period - pushes: + description: Repository ID + repo_name: type: string - description: Number of pushes in the period - total_score: + description: Repository name + repo_current_period_rank: type: string - description: Total score of the repo - contributor_logins: + description: The rank of the repository in the collection in the current period + repo_past_period_rank: type: string - description: Comma separated list of active contributor logins - collection_names: + description: The rank of the repository in the collection in the past period + repo_rank_changes: type: string - description: Comma separated list of collection names + description: The rank changes of the repository in the collection + additionalProperties: true example: - - collection_names: CICD - contributor_logins: cplee,nektos-ci,usagirei,ae-ou,MrNossiom - description: Run your GitHub Actions locally šŸš€ - forks: "5" - primary_language: Go - pull_requests: "6" - pushes: "17" - repo_id: "163883279" - repo_name: nektos/act - stars: "395" - total_score: "1565.7526" - - collection_names: ChatGPT Alternatives - contributor_logins: antonkesy,ruanslv,starplatinum3,AlexandroLuis,realhaik - description: Inference code for LLaMA models - forks: "48" - primary_language: Python - pull_requests: "41" - pushes: "7" - repo_id: "601538369" - repo_name: facebookresearch/llama - stars: "209" - total_score: "1079.0274" - - collection_names: Stable Diffusion Ecosystem - contributor_logins: atiorh,SaladDays831,ZachNagengast,TimYao18,vzsg - description: Stable Diffusion with Core ML on Apple Silicon - forks: "5" - primary_language: Python - pull_requests: "7" - pushes: "5" - repo_id: "566576114" - repo_name: apple/ml-stable-diffusion - stars: "99" - total_score: "575.2498" - - collection_names: Stable Diffusion Ecosystem - contributor_logins: danonymous856,EvilPhi666,FurkanGozukara,Prathyusha-98,ca-kishida - description: High-Resolution Image Synthesis with Latent Diffusion Models - forks: "6" - primary_language: Python - pull_requests: "2" - pushes: "" - repo_id: "569927055" - repo_name: Stability-AI/stablediffusion - stars: "75" - total_score: "483.0236" + - id: "10010" + name: Artificial Intelligence + repos: "36" + repo_id: "155220641" + repo_name: huggingface/transformers + repo_current_period_rank: "1" + repo_past_period_rank: "1" + repo_rank_changes: "0" + - id: "10010" + name: Artificial Intelligence + repos: "36" + repo_id: "65600975" + repo_name: pytorch/pytorch + repo_current_period_rank: "3" + repo_past_period_rank: "4" + repo_rank_changes: "1" + - id: "10010" + name: Artificial Intelligence + repos: "36" + repo_id: "458588993" + repo_name: nebuly-ai/nebullvm + repo_current_period_rank: "2" + repo_past_period_rank: "2" + repo_rank_changes: "0" + - id: "10078" + name: ChatGPT Apps + repos: "36" + repo_id: "599394820" + repo_name: Chanzhaoyu/chatgpt-web + repo_current_period_rank: "3" + repo_past_period_rank: "6" + repo_rank_changes: "3" + - id: "10078" + name: ChatGPT Apps + repos: "36" + repo_id: "609416865" + repo_name: yetone/openai-translator + repo_current_period_rank: "2" + repo_past_period_rank: "" + repo_rank_changes: "" + - id: "10078" + name: ChatGPT Apps + repos: "36" + repo_id: "608555244" + repo_name: microsoft/visual-chatgpt + repo_current_period_rank: "1" + repo_past_period_rank: "" + repo_rank_changes: "" result: type: object properties: @@ -634,18 +553,92 @@ paths: start_ms: 1690957407469 end_ms: 1690957407499 latency: 30ms - row_count: 4 + row_count: 6 row_affect: 0 limit: 50 databases: - gharchive_dev - /collections/hot/: + /trends/repos/: get: - operationId: list-hot-collections - summary: List hot collections + operationId: list-trending-repos + summary: List trending repos tags: - - Collections - description: List hot collections with top repositories of the collection. + - Trends + description: >- + Trending repos is an open source alternative to GitHub trends, which + showcases recently popular open source projects in the GitHub community. + + + > **Note** + + > + + > Please URI encode the requested parameters, e.g. `C++` needs to be encoded as `C%2B%2B`. + + ā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events. + parameters: + - schema: + type: string + enum: + - past_24_hours + - past_week + - past_month + - past_3_months + default: past_24_hours + in: query + name: period + required: false + description: Specify the period of time to calculate trending repos. + - schema: + type: string + enum: + - All + - JavaScript + - Java + - Python + - PHP + - C++ + - C# + - TypeScript + - Shell + - C + - Ruby + - Rust + - Go + - Kotlin + - HCL + - PowerShell + - CMake + - Groovy + - PLpgSQL + - TSQL + - Dart + - Swift + - HTML + - CSS + - Elixir + - Haskell + - Solidity + - Assembly + - R + - Scala + - Julia + - Lua + - Clojure + - Erlang + - Common Lisp + - Emacs Lisp + - OCaml + - MATLAB + - Objective-C + - Perl + - Fortran + default: All + in: query + name: language + required: false + description: Specify using which programming language to filter trending repos. + If not specified, all languages will be included. responses: "200": description: Default Response @@ -721,109 +714,122 @@ paths: description: Whether the column is nullable. additionalProperties: true example: - - col: id - data_type: BIGINT - nullable: false - - col: name - data_type: VARCHAR - nullable: false - - col: repos - data_type: BIGINT - nullable: false - col: repo_id - data_type: BIGINT - nullable: false + data_type: INT + nullable: true - col: repo_name data_type: VARCHAR - nullable: false - - col: repo_current_period_rank + nullable: true + - col: primary_language + data_type: VARCHAR + nullable: true + - col: description + data_type: VARCHAR + nullable: true + - col: stars data_type: INT nullable: true - - col: repo_past_period_rank + - col: forks data_type: INT nullable: true - - col: repo_rank_changes - data_type: BIGINT + - col: pull_requests + data_type: INT + nullable: true + - col: pushes + data_type: INT + nullable: true + - col: total_score + data_type: DOUBLE + nullable: true + - col: contributor_logins + data_type: VARCHAR + nullable: true + - col: collection_names + data_type: VARCHAR nullable: true rows: type: array items: type: object properties: - id: + repo_id: type: string - description: Collection ID - name: + description: ID of the repo + repo_name: type: string - description: Collection name - repos: + description: Name of the repo + primary_language: type: string - description: The number of repositories in the collection - repo_id: + description: Primary programing language used by the repo + description: type: string - description: Repository ID - repo_name: + description: Description of the repo + stars: type: string - description: Repository name - repo_current_period_rank: + description: Number of stars in the period + forks: type: string - description: The rank of the repository in the collection in the current period - repo_past_period_rank: + description: Number of forks in the period + pull_requests: type: string - description: The rank of the repository in the collection in the past period - repo_rank_changes: + description: Number of pull requests in the period + pushes: type: string - description: The rank changes of the repository in the collection - additionalProperties: true + description: Number of pushes in the period + total_score: + type: string + description: Total score of the repo + contributor_logins: + type: string + description: Comma separated list of active contributor logins + collection_names: + type: string + description: Comma separated list of collection names example: - - id: "10010" - name: Artificial Intelligence - repos: "36" - repo_id: "155220641" - repo_name: huggingface/transformers - repo_current_period_rank: "1" - repo_past_period_rank: "1" - repo_rank_changes: "0" - - id: "10010" - name: Artificial Intelligence - repos: "36" - repo_id: "65600975" - repo_name: pytorch/pytorch - repo_current_period_rank: "3" - repo_past_period_rank: "4" - repo_rank_changes: "1" - - id: "10010" - name: Artificial Intelligence - repos: "36" - repo_id: "458588993" - repo_name: nebuly-ai/nebullvm - repo_current_period_rank: "2" - repo_past_period_rank: "2" - repo_rank_changes: "0" - - id: "10078" - name: ChatGPT Apps - repos: "36" - repo_id: "599394820" - repo_name: Chanzhaoyu/chatgpt-web - repo_current_period_rank: "3" - repo_past_period_rank: "6" - repo_rank_changes: "3" - - id: "10078" - name: ChatGPT Apps - repos: "36" - repo_id: "609416865" - repo_name: yetone/openai-translator - repo_current_period_rank: "2" - repo_past_period_rank: "" - repo_rank_changes: "" - - id: "10078" - name: ChatGPT Apps - repos: "36" - repo_id: "608555244" - repo_name: microsoft/visual-chatgpt - repo_current_period_rank: "1" - repo_past_period_rank: "" - repo_rank_changes: "" + - collection_names: CICD + contributor_logins: cplee,nektos-ci,usagirei,ae-ou,MrNossiom + description: Run your GitHub Actions locally šŸš€ + forks: "5" + primary_language: Go + pull_requests: "6" + pushes: "17" + repo_id: "163883279" + repo_name: nektos/act + stars: "395" + total_score: "1565.7526" + - collection_names: ChatGPT Alternatives + contributor_logins: antonkesy,ruanslv,starplatinum3,AlexandroLuis,realhaik + description: Inference code for LLaMA models + forks: "48" + primary_language: Python + pull_requests: "41" + pushes: "7" + repo_id: "601538369" + repo_name: facebookresearch/llama + stars: "209" + total_score: "1079.0274" + - collection_names: Stable Diffusion Ecosystem + contributor_logins: atiorh,SaladDays831,ZachNagengast,TimYao18,vzsg + description: Stable Diffusion with Core ML on Apple Silicon + forks: "5" + primary_language: Python + pull_requests: "7" + pushes: "5" + repo_id: "566576114" + repo_name: apple/ml-stable-diffusion + stars: "99" + total_score: "575.2498" + - collection_names: Stable Diffusion Ecosystem + contributor_logins: danonymous856,EvilPhi666,FurkanGozukara,Prathyusha-98,ca-kishida + description: High-Resolution Image Synthesis with Latent Diffusion Models + forks: "6" + primary_language: Python + pull_requests: "2" + pushes: "" + repo_id: "569927055" + repo_name: Stability-AI/stablediffusion + stars: "75" + total_score: "483.0236" result: type: object properties: @@ -863,7 +869,7 @@ paths: start_ms: 1690957407469 end_ms: 1690957407499 latency: 30ms - row_count: 6 + row_count: 4 row_affect: 0 limit: 50 databases: @@ -2933,17 +2939,15 @@ paths: limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/pull_request_creators/countries/": + "/repos/{owner}/{repo}/stargazers/countries/": get: - operationId: list-countries-of-pr-creators - summary: List countries/regions of PR creators + operationId: list-countries-of-stargazers + summary: List countries/regions of stargazers tags: - - Pull Request Creators + - Stargazers description: > - List countries/regions of pull request creators for the specified - repository. - - + List countries/regions of stargazers for the specified repository. + > **Notice**: > In the overall data, about **3.5%** of GitHub users provided valid country/region information. @@ -3069,7 +3073,7 @@ paths: - col: country_code data_type: CHAR nullable: true - - col: pull_request_creators + - col: stargazers data_type: BIGINT nullable: true - col: percentage @@ -3083,22 +3087,25 @@ paths: country_code: type: string description: Country/region code - percentage: + stargazers: type: string - description: Percentage of pull request creators from the country/region - pull_request_creators: + description: Number of stargazers from the country/region + percentage: type: string - description: Number of pull request creators from the country/region + description: Percentage of stargazers from the country/region example: - country_code: CN - percentage: "0.8802" - pull_request_creators: "13619" - - country_code: NL - percentage: "0.0508" - pull_request_creators: "786" + percentage: "0.5935" + stargazers: "9189" - country_code: US - percentage: "0.0400" - pull_request_creators: "619" + percentage: "0.0996" + stargazers: "1542" + - country_code: JP + percentage: "0.0305" + stargazers: "473" + - country_code: DE + percentage: "0.0267" + stargazers: "413" result: type: object properties: @@ -3138,19 +3145,19 @@ paths: start_ms: 1690957407469 end_ms: 1690957407499 latency: 30ms - row_count: 3 + row_count: 4 row_affect: 0 limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/pull_request_creators/history/": + "/repos/{owner}/{repo}/stargazers/history/": get: - operationId: pull-request-creators-history - summary: Pull request creators history + operationId: stargazers-history + summary: Stargazers history tags: - - Pull Request Creators - description: Querying the historical trend of the number of pull request - creators in a given repository. + - Stargazers + description: Querying the historical trend of the number of stargazers in a + given repository. parameters: - schema: type: string @@ -3280,20 +3287,20 @@ paths: date: type: string description: The date of the data point - pull_request_creators: + stargazers: type: string - description: The cumulative number of pull request creators + description: The cumulative number of stargazers example: - - date: 2023-03-01 - pull_request_creators: "912" - date: 2023-04-01 - pull_request_creators: "915" + stargazers: "35389" - date: 2023-05-01 - pull_request_creators: "924" + stargazers: "35593" - date: 2023-06-01 - pull_request_creators: "932" + stargazers: "35805" + - date: 2023-07-01 + stargazers: "36019" - date: 2023-08-01 - pull_request_creators: "933" + stargazers: "36026" result: type: object properties: @@ -3338,20 +3345,19 @@ paths: limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/pull_request_creators/organizations/": + "/repos/{owner}/{repo}/stargazers/organizations/": get: - operationId: list-organizations-of-pr-creators - summary: List organizations of PR creators + operationId: list-organizations-of-stargazers + summary: List organizations of stargazers tags: - - Pull Request Creators + - Stargazers description: > - List organizations of pull request creators for the specified - repository. + List organizations of stargazers for the specified repository. > **Notice**: - > In the overall data, about **5.62%** of GitHub users has valid organization information. + > In the overall data, about **5.62%** of GitHub users provided valid organization information. > **Note**: @@ -3366,7 +3372,7 @@ paths: in: query name: exclude_unknown required: false - description: Whether to exclude PR creators with unknown organization information + description: Whether to exclude stargazers with unknown organization information - schema: type: string default: 2000-01-01 @@ -3473,7 +3479,7 @@ paths: - col: org_name data_type: VARCHAR nullable: true - - col: pull_request_creators + - col: stargazers data_type: BIGINT nullable: true - col: percentage @@ -3489,23 +3495,23 @@ paths: description: Name of the organization percentage: type: string - description: Percentage of pull request creators from the organization - pull_request_creators: + description: Percentage of stargazers from the organization + stargazers: type: string - description: Number of pull request creators from the organization + description: Number of stargazers from the organization example: - - org_name: pingcap - percentage: "0.3064" - pull_request_creators: "106" + - org_name: tencent + percentage: "0.0217" + stargazers: "199" - org_name: bytedance - percentage: "0.0318" - pull_request_creators: "11" + percentage: "0.0192" + stargazers: "176" - org_name: alibaba - percentage: "0.0260" - pull_request_creators: "9" - - org_name: tencent - percentage: "0.0173" - pull_request_creators: "6" + percentage: "0.0162" + stargazers: "148" + - org_name: pingcap + percentage: "0.0119" + stargazers: "109" result: type: object properties: @@ -3550,15 +3556,17 @@ paths: limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/stargazers/countries/": + "/repos/{owner}/{repo}/pull_request_creators/countries/": get: - operationId: list-countries-of-stargazers - summary: List countries/regions of stargazers + operationId: list-countries-of-pr-creators + summary: List countries/regions of PR creators tags: - - Stargazers + - Pull Request Creators description: > - List countries/regions of stargazers for the specified repository. - + List countries/regions of pull request creators for the specified + repository. + + > **Notice**: > In the overall data, about **3.5%** of GitHub users provided valid country/region information. @@ -3684,7 +3692,7 @@ paths: - col: country_code data_type: CHAR nullable: true - - col: stargazers + - col: pull_request_creators data_type: BIGINT nullable: true - col: percentage @@ -3698,25 +3706,22 @@ paths: country_code: type: string description: Country/region code - stargazers: - type: string - description: Number of stargazers from the country/region percentage: type: string - description: Percentage of stargazers from the country/region + description: Percentage of pull request creators from the country/region + pull_request_creators: + type: string + description: Number of pull request creators from the country/region example: - country_code: CN - percentage: "0.5935" - stargazers: "9189" + percentage: "0.8802" + pull_request_creators: "13619" + - country_code: NL + percentage: "0.0508" + pull_request_creators: "786" - country_code: US - percentage: "0.0996" - stargazers: "1542" - - country_code: JP - percentage: "0.0305" - stargazers: "473" - - country_code: DE - percentage: "0.0267" - stargazers: "413" + percentage: "0.0400" + pull_request_creators: "619" result: type: object properties: @@ -3756,19 +3761,19 @@ paths: start_ms: 1690957407469 end_ms: 1690957407499 latency: 30ms - row_count: 4 + row_count: 3 row_affect: 0 limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/stargazers/history/": + "/repos/{owner}/{repo}/pull_request_creators/history/": get: - operationId: stargazers-history - summary: Stargazers history + operationId: pull-request-creators-history + summary: Pull request creators history tags: - - Stargazers - description: Querying the historical trend of the number of stargazers in a - given repository. + - Pull Request Creators + description: Querying the historical trend of the number of pull request + creators in a given repository. parameters: - schema: type: string @@ -3898,20 +3903,20 @@ paths: date: type: string description: The date of the data point - stargazers: + pull_request_creators: type: string - description: The cumulative number of stargazers + description: The cumulative number of pull request creators example: + - date: 2023-03-01 + pull_request_creators: "912" - date: 2023-04-01 - stargazers: "35389" + pull_request_creators: "915" - date: 2023-05-01 - stargazers: "35593" + pull_request_creators: "924" - date: 2023-06-01 - stargazers: "35805" - - date: 2023-07-01 - stargazers: "36019" + pull_request_creators: "932" - date: 2023-08-01 - stargazers: "36026" + pull_request_creators: "933" result: type: object properties: @@ -3956,19 +3961,20 @@ paths: limit: 50 databases: - gharchive_dev - "/repos/{owner}/{repo}/stargazers/organizations/": + "/repos/{owner}/{repo}/pull_request_creators/organizations/": get: - operationId: list-organizations-of-stargazers - summary: List organizations of stargazers + operationId: list-organizations-of-pr-creators + summary: List organizations of PR creators tags: - - Stargazers + - Pull Request Creators description: > - List organizations of stargazers for the specified repository. + List organizations of pull request creators for the specified + repository. > **Notice**: - > In the overall data, about **5.62%** of GitHub users provided valid organization information. + > In the overall data, about **5.62%** of GitHub users has valid organization information. > **Note**: @@ -3983,7 +3989,7 @@ paths: in: query name: exclude_unknown required: false - description: Whether to exclude stargazers with unknown organization information + description: Whether to exclude PR creators with unknown organization information - schema: type: string default: 2000-01-01 @@ -4090,7 +4096,7 @@ paths: - col: org_name data_type: VARCHAR nullable: true - - col: stargazers + - col: pull_request_creators data_type: BIGINT nullable: true - col: percentage @@ -4106,23 +4112,23 @@ paths: description: Name of the organization percentage: type: string - description: Percentage of stargazers from the organization - stargazers: + description: Percentage of pull request creators from the organization + pull_request_creators: type: string - description: Number of stargazers from the organization + description: Number of pull request creators from the organization example: - - org_name: tencent - percentage: "0.0217" - stargazers: "199" + - org_name: pingcap + percentage: "0.3064" + pull_request_creators: "106" - org_name: bytedance - percentage: "0.0192" - stargazers: "176" + percentage: "0.0318" + pull_request_creators: "11" - org_name: alibaba - percentage: "0.0162" - stargazers: "148" - - org_name: pingcap - percentage: "0.0119" - stargazers: "109" + percentage: "0.0260" + pull_request_creators: "9" + - org_name: tencent + percentage: "0.0173" + pull_request_creators: "6" result: type: object properties: diff --git a/packages/api-server/src/plugins/services/tidb-data-service/index.ts b/packages/api-server/src/plugins/services/tidb-data-service/index.ts index 804be107827..d107fb783bf 100644 --- a/packages/api-server/src/plugins/services/tidb-data-service/index.ts +++ b/packages/api-server/src/plugins/services/tidb-data-service/index.ts @@ -1,10 +1,11 @@ import Axios, {AxiosInstance} from "axios"; -import {FastifyBaseLogger} from "fastify"; -import fp from "fastify-plugin"; -import {DateTime} from "luxon"; -import {URLSearchParams} from "url"; import {countAPIRequest, dataServiceRequestCounter, dataServiceRequestTimer, measure} from "../../../metrics"; + import {APIError} from "../../../utils/error"; +import {DateTime} from "luxon"; +import {FastifyBaseLogger} from "fastify"; +import {URLSearchParams} from "url"; +import fp from "fastify-plugin"; declare module 'fastify' { interface FastifyInstance { @@ -44,9 +45,9 @@ export class TiDBDataService { }); } - async request(originalPath: string) { + async request(targetURL: string) { new URLSearchParams() - const endpointName = new URL(originalPath, 'https://example.org').pathname; + const endpointName = new URL(targetURL, 'https://example.org').pathname; if (!endpointName) { throw new APIError(400, 'Invalid query name.'); } @@ -57,12 +58,12 @@ export class TiDBDataService { return await countAPIRequest(counter, endpointName, async () => { return await measure(timer, async () => { const startTime = DateTime.now(); - const res = await this.client.get(`${originalPath}`); + const res = await this.client.get(targetURL); const endTime = DateTime.now(); const duration = endTime.diff(startTime, 'seconds').seconds; this.logger.info({ - targetURL: originalPath, - endpoint: endpointName, + targetURL, + endpointName, }, `āœ… Finished request to TiDB Data Service (endpoint: ${endpointName}), cost: ${duration} s.`); return res; }); diff --git a/packages/api-server/src/routes/v1/trends/repos/index.ts b/packages/api-server/src/routes/v1/trends/repos/index.ts index 161519be565..267b0454bbc 100644 --- a/packages/api-server/src/routes/v1/trends/repos/index.ts +++ b/packages/api-server/src/routes/v1/trends/repos/index.ts @@ -1,5 +1,6 @@ +import {getSuccessResponse, proxyGet} from "../../../../utils/endpoint"; + import {FastifyPluginAsync} from "fastify"; -import {proxyGet, getSuccessResponse} from "../../../../utils/endpoint"; const schema = { operationId: 'list-trending-repos', @@ -7,6 +8,10 @@ const schema = { method: 'GET', description: `Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community. +> **Note** +> +> Please URI encode the requested parameters, e.g. \`C++\` needs to be encoded as \`C%2B%2B\`. + ā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.`, tags: ['Trends'], querystring: { diff --git a/packages/api-server/src/utils/endpoint.ts b/packages/api-server/src/utils/endpoint.ts index 2aea7daa486..5cd19db7e57 100644 --- a/packages/api-server/src/utils/endpoint.ts +++ b/packages/api-server/src/utils/endpoint.ts @@ -1,5 +1,5 @@ -import {FastifyInstance} from "fastify"; import {APIError} from "./error"; +import {FastifyInstance} from "fastify"; export function proxyGet( app: FastifyInstance, @@ -22,13 +22,14 @@ export function proxyGet( // Remove prefix and query string from url. const url = new URL(req.url, 'http://localhost'); let pathname = url.pathname.replace(/^\/(public|v1)/, ''); + // Map query params to query strings. const query = req.query as any; const queryKeys = Object.keys(query); const queryStrings = []; queryStrings.push(...queryKeys.map((queryKey) => { - return `${queryKey}=${query[queryKey]}`; + return `${queryKey}=${encodeURIComponent(query[queryKey])}`; })); // Remove path params from url. @@ -41,7 +42,7 @@ export function proxyGet( // TODO: remove it after TiDB data service supports path params. // Map path params to query strings. queryStrings.push(...paramKeys.map((paramKey) => { - return `${paramKey}=${params[paramKey]}`; + return `${paramKey}=${encodeURIComponent(params[paramKey])}`; })); // Remove trailing slash from url. @@ -53,7 +54,7 @@ export function proxyGet( } // Retrieve query result from TiDB data service. - const targetURL = `${pathname}?${queryStrings.join('&')}`; + const targetURL = `${pathname}?${queryStrings.join('&')}`; const res = await app.tidbDataService.request(targetURL); delete res.headers['transfer-encoding']; diff --git a/web/docs/api/list-collections.api.mdx b/web/docs/api/list-collections.api.mdx index 11752d7049d..86ff53deb49 100644 --- a/web/docs/api/list-collections.api.mdx +++ b/web/docs/api/list-collections.api.mdx @@ -5,7 +5,7 @@ description: "List collections." sidebar_label: "List collections" hide_title: true hide_table_of_contents: true -api: {"operationId":"list-collections","tags":["Collections"],"description":"List collections.","responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","required":["type","data"],"properties":{"type":{"type":"string","description":"The type of the endpoint.","enum":["sql_endpoint"],"example":"sql_endpoint"},"data":{"type":"object","required":["columns","rows","result"],"properties":{"columns":{"type":"array","items":{"type":"object","required":["col","data_type","nullable"],"properties":{"col":{"type":"string","description":"The name of the column in the query result."},"data_type":{"type":"string","enum":["CHAR","BIGINT","DECIMAL","INT","UNSIGNED BIGINT","TINYINT","TIMESTAMP","TEXT","VARCHAR","DATETIME","DOUBLE","FLOAT","DATE","TIME","YEAR","MEDIUMINT","SMALLINT","BIT","BINARY","VARBINARY","JSON","ENUM","SET","TINYTEXT","MEDIUMTEXT","LONGTEXT","TINYBLOB","MEDIUMBLOB","BLOB","LONGBLOB"],"description":"The data type of the column."},"nullable":{"type":"boolean","description":"Whether the column is nullable."}},"additionalProperties":true},"example":[{"col":"id","data_type":"BIGINT","nullable":false},{"col":"name","data_type":"VARCHAR","nullable":false}]},"rows":{"type":"array","items":{"type":"object","properties":{"repo_id":{"type":"string","description":"Collection ID"},"repo_name":{"type":"string","description":"Collection name"}},"additionalProperties":true},"example":[{"id":"1","name":"Static Site Generator"},{"id":"2","name":"Open Source Database"},{"id":"10001","name":"CSS Framework"},{"id":"10002","name":"Google Analytics Alternative"},{"id":"10003","name":"Low Code Development Tool"}]},"result":{"type":"object","properties":{"code":{"type":"number","description":"The code of the response."},"message":{"type":"string","description":"The message of the response."},"start_ms":{"type":"number","description":"The start time of the query in milliseconds."},"end_ms":{"type":"number","description":"The end time of the query in milliseconds."},"latency":{"type":"string","description":"The latency of the query."},"row_count":{"type":"number","description":"The number of rows in the query result."},"row_affect":{"type":"number","description":"The number of rows affected by the query."},"limit":{"type":"number","description":"The maximum number of rows in the query result."},"databases":{"type":"array","description":"The databases used in the query.","items":{"type":"string"}}},"additionalProperties":true,"example":{"code":200,"message":"Query OK!","start_ms":1690957407469,"end_ms":1690957407499,"latency":"30ms","row_count":5,"row_affect":0,"limit":50,"databases":["gharchive_dev"]}}}}}}}}}},"method":"get","path":"/collections/","servers":[{"url":"https://api.ossinsight.io/v1"}],"info":{"title":"OSSInsight Public API","description":"\nOSSInsight Public APIs (beta) provide a convenient way to access insight data for open source projects on GitHub, supplementing the existing GitHub API.\n\nIt provides data query in different dimensions, including:\n\n```mdx-code-block\nimport DocCardList from '@theme/DocCardList';\nimport {useCurrentSidebarCategory} from '@docusaurus/theme-common';\n\n {\n // Exclude Introduction and Showcase pages\n return item.docId !== 'api/showcase' && item.docId !== 'api/ossinsight-public-api';\n})}/>\n```\n\n## Usage\n\nThe OSSInsight Public API is designed to follow the OpenAPI specification and can be accessed by initiating HTTP requests using the command line `curl` or web request libraries in different programming languages.\n\n### Base URL\n\nAll API requests are based on the following URL:\n\n```shell\nhttps://api.ossinsight.io/v1\n```\n\n### Authentication\n\nNo authentication is required for beta version of public APIs, but there are [rate limits](#rate-limit) for API requests.\n\n> Note:\n> We will add authentication way for larger API requests in future releases.\n\n### Rate Limit\n\nFor each IP address, the rate limit allows for up to **600 requests per hour**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit: 600\nx-ratelimit-remaining: 599\n```\n\nIn addition, we have also set up a global rate limit of up to **1000 requests per minute**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit-minute: 1000\nx-ratelimit-remaining-minute: 97\n```\n\n### Example\n\nFor example, if you want to know what countries the stargazers in the `pingcap/tidb` repository are located in, you can make a request using the curl command as follows:\n\n```shell\ncurl https://api.ossinsight.io/v1/repos/pingcap/tidb/stargazers/countries\n```\n\n
\n\nExample Response\n\n```json\n{\n \"type\": \"sql_endpoint\",\n \"data\": {\n \"columns\": [\n {\n \"col\": \"country_or_area\",\n \"data_type\": \"CHAR\",\n \"nullable\": true\n },\n {\n \"col\": \"count\",\n \"data_type\": \"BIGINT\",\n \"nullable\": true\n },\n {\n \"col\": \"percentage\",\n \"data_type\": \"DECIMAL\",\n \"nullable\": true\n }\n ],\n \"rows\": [\n {\n \"count\": \"9183\",\n \"country_or_area\": \"CN\",\n \"percentage\": \"0.5936\"\n },\n {\n \"count\": \"1542\",\n \"country_or_area\": \"US\",\n \"percentage\": \"0.0997\"\n },\n {\n \"count\": \"471\",\n \"country_or_area\": \"JP\",\n \"percentage\": \"0.0304\"\n }\n ],\n \"result\": {\n \"code\": 200,\n \"message\": \"Query OK!\",\n \"start_ms\": 1690351487809,\n \"end_ms\": 1690351487930,\n \"latency\": \"121ms\",\n \"row_count\": 132,\n \"row_affect\": 0,\n \"limit\": 300,\n \"databases\": [\n \"gharchive_dev\"\n ]\n }\n }\n}\n```\n\n
\n\n## Request New API \n\nIf the API in the documentation does not meet your query requirements, please contact us as follows:\n\n- Email us at ossinsight@pingcap.com\n- Open an issue in the [OSSInsight GitHub repository](https://github.com/pingcap/ossinsight/issues/new?assignees=&labels=type%2Ffeature&projects=&template=feature_request.md&title=New%20API)\n","version":"v1beta"},"postman":{"name":"List collections","description":{"content":"List collections.","type":"text/plain"},"url":{"path":["collections",""],"host":["{{baseUrl}}"],"query":[],"variable":[]},"header":[{"key":"Accept","value":"application/json"}],"method":"GET"}} +api: {"operationId":"list-collections","tags":["Collections"],"description":"List collections.","responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","required":["type","data"],"properties":{"type":{"type":"string","description":"The type of the endpoint.","enum":["sql_endpoint"],"example":"sql_endpoint"},"data":{"type":"object","required":["columns","rows","result"],"properties":{"columns":{"type":"array","items":{"type":"object","required":["col","data_type","nullable"],"properties":{"col":{"type":"string","description":"The name of the column in the query result."},"data_type":{"type":"string","enum":["CHAR","BIGINT","DECIMAL","INT","UNSIGNED BIGINT","TINYINT","TIMESTAMP","TEXT","VARCHAR","DATETIME","DOUBLE","FLOAT","DATE","TIME","YEAR","MEDIUMINT","SMALLINT","BIT","BINARY","VARBINARY","JSON","ENUM","SET","TINYTEXT","MEDIUMTEXT","LONGTEXT","TINYBLOB","MEDIUMBLOB","BLOB","LONGBLOB"],"description":"The data type of the column."},"nullable":{"type":"boolean","description":"Whether the column is nullable."}},"additionalProperties":true},"example":[{"col":"id","data_type":"BIGINT","nullable":false},{"col":"name","data_type":"VARCHAR","nullable":false}]},"rows":{"type":"array","items":{"type":"object","properties":{"repo_id":{"type":"string","description":"Repository ID"},"repo_name":{"type":"string","description":"Repository name"}},"additionalProperties":true},"example":[{"id":"1","name":"Static Site Generator"},{"id":"2","name":"Open Source Database"},{"id":"10001","name":"CSS Framework"},{"id":"10002","name":"Google Analytics Alternative"},{"id":"10003","name":"Low Code Development Tool"}]},"result":{"type":"object","properties":{"code":{"type":"number","description":"The code of the response."},"message":{"type":"string","description":"The message of the response."},"start_ms":{"type":"number","description":"The start time of the query in milliseconds."},"end_ms":{"type":"number","description":"The end time of the query in milliseconds."},"latency":{"type":"string","description":"The latency of the query."},"row_count":{"type":"number","description":"The number of rows in the query result."},"row_affect":{"type":"number","description":"The number of rows affected by the query."},"limit":{"type":"number","description":"The maximum number of rows in the query result."},"databases":{"type":"array","description":"The databases used in the query.","items":{"type":"string"}}},"additionalProperties":true,"example":{"code":200,"message":"Query OK!","start_ms":1690957407469,"end_ms":1690957407499,"latency":"30ms","row_count":5,"row_affect":0,"limit":50,"databases":["gharchive_dev"]}}}}}}}}}},"method":"get","path":"/collections/","servers":[{"url":"https://api.ossinsight.io/v1"}],"info":{"title":"OSSInsight Public API","description":"\nOSSInsight Public APIs (beta) provide a convenient way to access insight data for open source projects on GitHub, supplementing the existing GitHub API.\n\nIt provides data query in different dimensions, including:\n\n```mdx-code-block\nimport DocCardList from '@theme/DocCardList';\nimport {useCurrentSidebarCategory} from '@docusaurus/theme-common';\n\n {\n // Exclude Introduction and Showcase pages\n return item.docId !== 'api/showcase' && item.docId !== 'api/ossinsight-public-api';\n})}/>\n```\n\n## Usage\n\nThe OSSInsight Public API is designed to follow the OpenAPI specification and can be accessed by initiating HTTP requests using the command line `curl` or web request libraries in different programming languages.\n\n### Base URL\n\nAll API requests are based on the following URL:\n\n```shell\nhttps://api.ossinsight.io/v1\n```\n\n### Authentication\n\nNo authentication is required for beta version of public APIs, but there are [rate limits](#rate-limit) for API requests.\n\n> Note:\n> We will add authentication way for larger API requests in future releases.\n\n### Rate Limit\n\nFor each IP address, the rate limit allows for up to **600 requests per hour**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit: 600\nx-ratelimit-remaining: 599\n```\n\nIn addition, we have also set up a global rate limit of up to **1000 requests per minute**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit-minute: 1000\nx-ratelimit-remaining-minute: 97\n```\n\n### Example\n\nFor example, if you want to know what countries the stargazers in the `pingcap/tidb` repository are located in, you can make a request using the curl command as follows:\n\n```shell\ncurl https://api.ossinsight.io/v1/repos/pingcap/tidb/stargazers/countries\n```\n\n
\n\nExample Response\n\n```json\n{\n \"type\": \"sql_endpoint\",\n \"data\": {\n \"columns\": [\n {\n \"col\": \"country_or_area\",\n \"data_type\": \"CHAR\",\n \"nullable\": true\n },\n {\n \"col\": \"count\",\n \"data_type\": \"BIGINT\",\n \"nullable\": true\n },\n {\n \"col\": \"percentage\",\n \"data_type\": \"DECIMAL\",\n \"nullable\": true\n }\n ],\n \"rows\": [\n {\n \"count\": \"9183\",\n \"country_or_area\": \"CN\",\n \"percentage\": \"0.5936\"\n },\n {\n \"count\": \"1542\",\n \"country_or_area\": \"US\",\n \"percentage\": \"0.0997\"\n },\n {\n \"count\": \"471\",\n \"country_or_area\": \"JP\",\n \"percentage\": \"0.0304\"\n }\n ],\n \"result\": {\n \"code\": 200,\n \"message\": \"Query OK!\",\n \"start_ms\": 1690351487809,\n \"end_ms\": 1690351487930,\n \"latency\": \"121ms\",\n \"row_count\": 132,\n \"row_affect\": 0,\n \"limit\": 300,\n \"databases\": [\n \"gharchive_dev\"\n ]\n }\n }\n}\n```\n\n
\n\n## Request New API \n\nIf the API in the documentation does not meet your query requirements, please contact us as follows:\n\n- Email us at ossinsight@pingcap.com\n- Open an issue in the [OSSInsight GitHub repository](https://github.com/pingcap/ossinsight/issues/new?assignees=&labels=type%2Ffeature&projects=&template=feature_request.md&title=New%20API)\n","version":"v1beta"},"postman":{"name":"List collections","description":{"content":"List collections.","type":"text/plain"},"url":{"path":["collections",""],"host":["{{baseUrl}}"],"query":[],"variable":[]},"header":[{"key":"Accept","value":"application/json"}],"method":"GET"}} sidebar_class_name: "get api-method" info_path: docs/api/ossinsight-public-api custom_edit_url: null @@ -30,4 +30,4 @@ List collections. Default Response -
Schema
    data object required
    columns object[] required
  • Array [
  • ]
  • rows object[] required
  • Array [
  • ]
  • result object required
\ No newline at end of file +
Schema
    data object required
    columns object[] required
  • Array [
  • ]
  • rows object[] required
  • Array [
  • ]
  • result object required
\ No newline at end of file diff --git a/web/docs/api/list-trending-repos.api.mdx b/web/docs/api/list-trending-repos.api.mdx index fc0d012301f..3bb7c7ecbd0 100644 --- a/web/docs/api/list-trending-repos.api.mdx +++ b/web/docs/api/list-trending-repos.api.mdx @@ -5,7 +5,7 @@ description: "Trending repos is an open source alternative to GitHub trends, whi sidebar_label: "List trending repos" hide_title: true hide_table_of_contents: true -api: {"operationId":"list-trending-repos","tags":["Trends"],"description":"Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community.\n\nā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.","parameters":[{"schema":{"type":"string","enum":["past_24_hours","past_week","past_month","past_3_months"],"default":"past_24_hours"},"in":"query","name":"period","required":false,"description":"Specify the period of time to calculate trending repos."},{"schema":{"type":"string","enum":["All","JavaScript","Java","Python","PHP","C++","C#","TypeScript","Shell","C","Ruby","Rust","Go","Kotlin","HCL","PowerShell","CMake","Groovy","PLpgSQL","TSQL","Dart","Swift","HTML","CSS","Elixir","Haskell","Solidity","Assembly","R","Scala","Julia","Lua","Clojure","Erlang","Common Lisp","Emacs Lisp","OCaml","MATLAB","Objective-C","Perl","Fortran"],"default":"All"},"in":"query","name":"language","required":false,"description":"Specify using which programming language to filter trending repos. If not specified, all languages will be included."}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","required":["type","data"],"properties":{"type":{"type":"string","description":"The type of the endpoint.","enum":["sql_endpoint"],"example":"sql_endpoint"},"data":{"type":"object","required":["columns","rows","result"],"properties":{"columns":{"type":"array","items":{"type":"object","required":["col","data_type","nullable"],"properties":{"col":{"type":"string","description":"The name of the column in the query result."},"data_type":{"type":"string","enum":["CHAR","BIGINT","DECIMAL","INT","UNSIGNED BIGINT","TINYINT","TIMESTAMP","TEXT","VARCHAR","DATETIME","DOUBLE","FLOAT","DATE","TIME","YEAR","MEDIUMINT","SMALLINT","BIT","BINARY","VARBINARY","JSON","ENUM","SET","TINYTEXT","MEDIUMTEXT","LONGTEXT","TINYBLOB","MEDIUMBLOB","BLOB","LONGBLOB"],"description":"The data type of the column."},"nullable":{"type":"boolean","description":"Whether the column is nullable."}},"additionalProperties":true},"example":[{"col":"repo_id","data_type":"INT","nullable":true},{"col":"repo_name","data_type":"VARCHAR","nullable":true},{"col":"primary_language","data_type":"VARCHAR","nullable":true},{"col":"description","data_type":"VARCHAR","nullable":true},{"col":"stars","data_type":"INT","nullable":true},{"col":"forks","data_type":"INT","nullable":true},{"col":"pull_requests","data_type":"INT","nullable":true},{"col":"pushes","data_type":"INT","nullable":true},{"col":"total_score","data_type":"DOUBLE","nullable":true},{"col":"contributor_logins","data_type":"VARCHAR","nullable":true},{"col":"collection_names","data_type":"VARCHAR","nullable":true}]},"rows":{"type":"array","items":{"type":"object","properties":{"repo_id":{"type":"string","description":"ID of the repo"},"repo_name":{"type":"string","description":"Name of the repo"},"primary_language":{"type":"string","description":"Primary programing language used by the repo"},"description":{"type":"string","description":"Description of the repo"},"stars":{"type":"string","description":"Number of stars in the period"},"forks":{"type":"string","description":"Number of forks in the period"},"pull_requests":{"type":"string","description":"Number of pull requests in the period"},"pushes":{"type":"string","description":"Number of pushes in the period"},"total_score":{"type":"string","description":"Total score of the repo"},"contributor_logins":{"type":"string","description":"Comma separated list of active contributor logins"},"collection_names":{"type":"string","description":"Comma separated list of collection names"}}},"example":[{"collection_names":"CICD","contributor_logins":"cplee,nektos-ci,usagirei,ae-ou,MrNossiom","description":"Run your GitHub Actions locally šŸš€","forks":"5","primary_language":"Go","pull_requests":"6","pushes":"17","repo_id":"163883279","repo_name":"nektos/act","stars":"395","total_score":"1565.7526"},{"collection_names":"ChatGPT Alternatives","contributor_logins":"antonkesy,ruanslv,starplatinum3,AlexandroLuis,realhaik","description":"Inference code for LLaMA models","forks":"48","primary_language":"Python","pull_requests":"41","pushes":"7","repo_id":"601538369","repo_name":"facebookresearch/llama","stars":"209","total_score":"1079.0274"},{"collection_names":"Stable Diffusion Ecosystem","contributor_logins":"atiorh,SaladDays831,ZachNagengast,TimYao18,vzsg","description":"Stable Diffusion with Core ML on Apple Silicon","forks":"5","primary_language":"Python","pull_requests":"7","pushes":"5","repo_id":"566576114","repo_name":"apple/ml-stable-diffusion","stars":"99","total_score":"575.2498"},{"collection_names":"Stable Diffusion Ecosystem","contributor_logins":"danonymous856,EvilPhi666,FurkanGozukara,Prathyusha-98,ca-kishida","description":"High-Resolution Image Synthesis with Latent Diffusion Models","forks":"6","primary_language":"Python","pull_requests":"2","pushes":"","repo_id":"569927055","repo_name":"Stability-AI/stablediffusion","stars":"75","total_score":"483.0236"}]},"result":{"type":"object","properties":{"code":{"type":"number","description":"The code of the response."},"message":{"type":"string","description":"The message of the response."},"start_ms":{"type":"number","description":"The start time of the query in milliseconds."},"end_ms":{"type":"number","description":"The end time of the query in milliseconds."},"latency":{"type":"string","description":"The latency of the query."},"row_count":{"type":"number","description":"The number of rows in the query result."},"row_affect":{"type":"number","description":"The number of rows affected by the query."},"limit":{"type":"number","description":"The maximum number of rows in the query result."},"databases":{"type":"array","description":"The databases used in the query.","items":{"type":"string"}}},"additionalProperties":true,"example":{"code":200,"message":"Query OK!","start_ms":1690957407469,"end_ms":1690957407499,"latency":"30ms","row_count":4,"row_affect":0,"limit":50,"databases":["gharchive_dev"]}}}}}}}}}},"method":"get","path":"/trends/repos/","servers":[{"url":"https://api.ossinsight.io/v1"}],"info":{"title":"OSSInsight Public API","description":"\nOSSInsight Public APIs (beta) provide a convenient way to access insight data for open source projects on GitHub, supplementing the existing GitHub API.\n\nIt provides data query in different dimensions, including:\n\n```mdx-code-block\nimport DocCardList from '@theme/DocCardList';\nimport {useCurrentSidebarCategory} from '@docusaurus/theme-common';\n\n {\n // Exclude Introduction and Showcase pages\n return item.docId !== 'api/showcase' && item.docId !== 'api/ossinsight-public-api';\n})}/>\n```\n\n## Usage\n\nThe OSSInsight Public API is designed to follow the OpenAPI specification and can be accessed by initiating HTTP requests using the command line `curl` or web request libraries in different programming languages.\n\n### Base URL\n\nAll API requests are based on the following URL:\n\n```shell\nhttps://api.ossinsight.io/v1\n```\n\n### Authentication\n\nNo authentication is required for beta version of public APIs, but there are [rate limits](#rate-limit) for API requests.\n\n> Note:\n> We will add authentication way for larger API requests in future releases.\n\n### Rate Limit\n\nFor each IP address, the rate limit allows for up to **600 requests per hour**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit: 600\nx-ratelimit-remaining: 599\n```\n\nIn addition, we have also set up a global rate limit of up to **1000 requests per minute**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit-minute: 1000\nx-ratelimit-remaining-minute: 97\n```\n\n### Example\n\nFor example, if you want to know what countries the stargazers in the `pingcap/tidb` repository are located in, you can make a request using the curl command as follows:\n\n```shell\ncurl https://api.ossinsight.io/v1/repos/pingcap/tidb/stargazers/countries\n```\n\n
\n\nExample Response\n\n```json\n{\n \"type\": \"sql_endpoint\",\n \"data\": {\n \"columns\": [\n {\n \"col\": \"country_or_area\",\n \"data_type\": \"CHAR\",\n \"nullable\": true\n },\n {\n \"col\": \"count\",\n \"data_type\": \"BIGINT\",\n \"nullable\": true\n },\n {\n \"col\": \"percentage\",\n \"data_type\": \"DECIMAL\",\n \"nullable\": true\n }\n ],\n \"rows\": [\n {\n \"count\": \"9183\",\n \"country_or_area\": \"CN\",\n \"percentage\": \"0.5936\"\n },\n {\n \"count\": \"1542\",\n \"country_or_area\": \"US\",\n \"percentage\": \"0.0997\"\n },\n {\n \"count\": \"471\",\n \"country_or_area\": \"JP\",\n \"percentage\": \"0.0304\"\n }\n ],\n \"result\": {\n \"code\": 200,\n \"message\": \"Query OK!\",\n \"start_ms\": 1690351487809,\n \"end_ms\": 1690351487930,\n \"latency\": \"121ms\",\n \"row_count\": 132,\n \"row_affect\": 0,\n \"limit\": 300,\n \"databases\": [\n \"gharchive_dev\"\n ]\n }\n }\n}\n```\n\n
\n\n## Request New API \n\nIf the API in the documentation does not meet your query requirements, please contact us as follows:\n\n- Email us at ossinsight@pingcap.com\n- Open an issue in the [OSSInsight GitHub repository](https://github.com/pingcap/ossinsight/issues/new?assignees=&labels=type%2Ffeature&projects=&template=feature_request.md&title=New%20API)\n","version":"v1beta"},"postman":{"name":"List trending repos","description":{"content":"Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community.\n\nā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.","type":"text/plain"},"url":{"path":["trends","repos",""],"host":["{{baseUrl}}"],"query":[{"disabled":false,"description":{"content":"Specify the period of time to calculate trending repos.","type":"text/plain"},"key":"period","value":""},{"disabled":false,"description":{"content":"Specify using which programming language to filter trending repos. If not specified, all languages will be included.","type":"text/plain"},"key":"language","value":""}],"variable":[]},"header":[{"key":"Accept","value":"application/json"}],"method":"GET"}} +api: {"operationId":"list-trending-repos","tags":["Trends"],"description":"Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community.\n\n> **Note**\n>\n> Please URI encode the requested parameters, e.g. `C++` needs to be encoded as `C%2B%2B`.\n \nā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.","parameters":[{"schema":{"type":"string","enum":["past_24_hours","past_week","past_month","past_3_months"],"default":"past_24_hours"},"in":"query","name":"period","required":false,"description":"Specify the period of time to calculate trending repos."},{"schema":{"type":"string","enum":["All","JavaScript","Java","Python","PHP","C++","C#","TypeScript","Shell","C","Ruby","Rust","Go","Kotlin","HCL","PowerShell","CMake","Groovy","PLpgSQL","TSQL","Dart","Swift","HTML","CSS","Elixir","Haskell","Solidity","Assembly","R","Scala","Julia","Lua","Clojure","Erlang","Common Lisp","Emacs Lisp","OCaml","MATLAB","Objective-C","Perl","Fortran"],"default":"All"},"in":"query","name":"language","required":false,"description":"Specify using which programming language to filter trending repos. If not specified, all languages will be included."}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","required":["type","data"],"properties":{"type":{"type":"string","description":"The type of the endpoint.","enum":["sql_endpoint"],"example":"sql_endpoint"},"data":{"type":"object","required":["columns","rows","result"],"properties":{"columns":{"type":"array","items":{"type":"object","required":["col","data_type","nullable"],"properties":{"col":{"type":"string","description":"The name of the column in the query result."},"data_type":{"type":"string","enum":["CHAR","BIGINT","DECIMAL","INT","UNSIGNED BIGINT","TINYINT","TIMESTAMP","TEXT","VARCHAR","DATETIME","DOUBLE","FLOAT","DATE","TIME","YEAR","MEDIUMINT","SMALLINT","BIT","BINARY","VARBINARY","JSON","ENUM","SET","TINYTEXT","MEDIUMTEXT","LONGTEXT","TINYBLOB","MEDIUMBLOB","BLOB","LONGBLOB"],"description":"The data type of the column."},"nullable":{"type":"boolean","description":"Whether the column is nullable."}},"additionalProperties":true},"example":[{"col":"repo_id","data_type":"INT","nullable":true},{"col":"repo_name","data_type":"VARCHAR","nullable":true},{"col":"primary_language","data_type":"VARCHAR","nullable":true},{"col":"description","data_type":"VARCHAR","nullable":true},{"col":"stars","data_type":"INT","nullable":true},{"col":"forks","data_type":"INT","nullable":true},{"col":"pull_requests","data_type":"INT","nullable":true},{"col":"pushes","data_type":"INT","nullable":true},{"col":"total_score","data_type":"DOUBLE","nullable":true},{"col":"contributor_logins","data_type":"VARCHAR","nullable":true},{"col":"collection_names","data_type":"VARCHAR","nullable":true}]},"rows":{"type":"array","items":{"type":"object","properties":{"repo_id":{"type":"string","description":"ID of the repo"},"repo_name":{"type":"string","description":"Name of the repo"},"primary_language":{"type":"string","description":"Primary programing language used by the repo"},"description":{"type":"string","description":"Description of the repo"},"stars":{"type":"string","description":"Number of stars in the period"},"forks":{"type":"string","description":"Number of forks in the period"},"pull_requests":{"type":"string","description":"Number of pull requests in the period"},"pushes":{"type":"string","description":"Number of pushes in the period"},"total_score":{"type":"string","description":"Total score of the repo"},"contributor_logins":{"type":"string","description":"Comma separated list of active contributor logins"},"collection_names":{"type":"string","description":"Comma separated list of collection names"}}},"example":[{"collection_names":"CICD","contributor_logins":"cplee,nektos-ci,usagirei,ae-ou,MrNossiom","description":"Run your GitHub Actions locally šŸš€","forks":"5","primary_language":"Go","pull_requests":"6","pushes":"17","repo_id":"163883279","repo_name":"nektos/act","stars":"395","total_score":"1565.7526"},{"collection_names":"ChatGPT Alternatives","contributor_logins":"antonkesy,ruanslv,starplatinum3,AlexandroLuis,realhaik","description":"Inference code for LLaMA models","forks":"48","primary_language":"Python","pull_requests":"41","pushes":"7","repo_id":"601538369","repo_name":"facebookresearch/llama","stars":"209","total_score":"1079.0274"},{"collection_names":"Stable Diffusion Ecosystem","contributor_logins":"atiorh,SaladDays831,ZachNagengast,TimYao18,vzsg","description":"Stable Diffusion with Core ML on Apple Silicon","forks":"5","primary_language":"Python","pull_requests":"7","pushes":"5","repo_id":"566576114","repo_name":"apple/ml-stable-diffusion","stars":"99","total_score":"575.2498"},{"collection_names":"Stable Diffusion Ecosystem","contributor_logins":"danonymous856,EvilPhi666,FurkanGozukara,Prathyusha-98,ca-kishida","description":"High-Resolution Image Synthesis with Latent Diffusion Models","forks":"6","primary_language":"Python","pull_requests":"2","pushes":"","repo_id":"569927055","repo_name":"Stability-AI/stablediffusion","stars":"75","total_score":"483.0236"}]},"result":{"type":"object","properties":{"code":{"type":"number","description":"The code of the response."},"message":{"type":"string","description":"The message of the response."},"start_ms":{"type":"number","description":"The start time of the query in milliseconds."},"end_ms":{"type":"number","description":"The end time of the query in milliseconds."},"latency":{"type":"string","description":"The latency of the query."},"row_count":{"type":"number","description":"The number of rows in the query result."},"row_affect":{"type":"number","description":"The number of rows affected by the query."},"limit":{"type":"number","description":"The maximum number of rows in the query result."},"databases":{"type":"array","description":"The databases used in the query.","items":{"type":"string"}}},"additionalProperties":true,"example":{"code":200,"message":"Query OK!","start_ms":1690957407469,"end_ms":1690957407499,"latency":"30ms","row_count":4,"row_affect":0,"limit":50,"databases":["gharchive_dev"]}}}}}}}}}},"method":"get","path":"/trends/repos/","servers":[{"url":"https://api.ossinsight.io/v1"}],"info":{"title":"OSSInsight Public API","description":"\nOSSInsight Public APIs (beta) provide a convenient way to access insight data for open source projects on GitHub, supplementing the existing GitHub API.\n\nIt provides data query in different dimensions, including:\n\n```mdx-code-block\nimport DocCardList from '@theme/DocCardList';\nimport {useCurrentSidebarCategory} from '@docusaurus/theme-common';\n\n {\n // Exclude Introduction and Showcase pages\n return item.docId !== 'api/showcase' && item.docId !== 'api/ossinsight-public-api';\n})}/>\n```\n\n## Usage\n\nThe OSSInsight Public API is designed to follow the OpenAPI specification and can be accessed by initiating HTTP requests using the command line `curl` or web request libraries in different programming languages.\n\n### Base URL\n\nAll API requests are based on the following URL:\n\n```shell\nhttps://api.ossinsight.io/v1\n```\n\n### Authentication\n\nNo authentication is required for beta version of public APIs, but there are [rate limits](#rate-limit) for API requests.\n\n> Note:\n> We will add authentication way for larger API requests in future releases.\n\n### Rate Limit\n\nFor each IP address, the rate limit allows for up to **600 requests per hour**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit: 600\nx-ratelimit-remaining: 599\n```\n\nIn addition, we have also set up a global rate limit of up to **1000 requests per minute**, which can be checked by the following fields in the Response Header to see the current usage:\n\n```\nx-ratelimit-limit-minute: 1000\nx-ratelimit-remaining-minute: 97\n```\n\n### Example\n\nFor example, if you want to know what countries the stargazers in the `pingcap/tidb` repository are located in, you can make a request using the curl command as follows:\n\n```shell\ncurl https://api.ossinsight.io/v1/repos/pingcap/tidb/stargazers/countries\n```\n\n
\n\nExample Response\n\n```json\n{\n \"type\": \"sql_endpoint\",\n \"data\": {\n \"columns\": [\n {\n \"col\": \"country_or_area\",\n \"data_type\": \"CHAR\",\n \"nullable\": true\n },\n {\n \"col\": \"count\",\n \"data_type\": \"BIGINT\",\n \"nullable\": true\n },\n {\n \"col\": \"percentage\",\n \"data_type\": \"DECIMAL\",\n \"nullable\": true\n }\n ],\n \"rows\": [\n {\n \"count\": \"9183\",\n \"country_or_area\": \"CN\",\n \"percentage\": \"0.5936\"\n },\n {\n \"count\": \"1542\",\n \"country_or_area\": \"US\",\n \"percentage\": \"0.0997\"\n },\n {\n \"count\": \"471\",\n \"country_or_area\": \"JP\",\n \"percentage\": \"0.0304\"\n }\n ],\n \"result\": {\n \"code\": 200,\n \"message\": \"Query OK!\",\n \"start_ms\": 1690351487809,\n \"end_ms\": 1690351487930,\n \"latency\": \"121ms\",\n \"row_count\": 132,\n \"row_affect\": 0,\n \"limit\": 300,\n \"databases\": [\n \"gharchive_dev\"\n ]\n }\n }\n}\n```\n\n
\n\n## Request New API \n\nIf the API in the documentation does not meet your query requirements, please contact us as follows:\n\n- Email us at ossinsight@pingcap.com\n- Open an issue in the [OSSInsight GitHub repository](https://github.com/pingcap/ossinsight/issues/new?assignees=&labels=type%2Ffeature&projects=&template=feature_request.md&title=New%20API)\n","version":"v1beta"},"postman":{"name":"List trending repos","description":{"content":"Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community.\n\n> **Note**\n>\n> Please URI encode the requested parameters, e.g. `C++` needs to be encoded as `C%2B%2B`.\n \nā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.","type":"text/plain"},"url":{"path":["trends","repos",""],"host":["{{baseUrl}}"],"query":[{"disabled":false,"description":{"content":"Specify the period of time to calculate trending repos.","type":"text/plain"},"key":"period","value":""},{"disabled":false,"description":{"content":"Specify using which programming language to filter trending repos. If not specified, all languages will be included.","type":"text/plain"},"key":"language","value":""}],"variable":[]},"header":[{"key":"Accept","value":"application/json"}],"method":"GET"}} sidebar_class_name: "get api-method" info_path: docs/api/ossinsight-public-api custom_edit_url: null @@ -26,6 +26,10 @@ import TabItem from "@theme/TabItem"; Trending repos is an open source alternative to GitHub trends, which showcases recently popular open source projects in the GitHub community. +> **Note** +> +> Please URI encode the requested parameters, e.g. `C++` needs to be encoded as `C%2B%2B`. + ā˜ļø Daily run on [TiDB Cloud](https://tidbcloud.com/?utm_source=ossinsight&utm_medium=ossinsight_api), analyze upon dataset that has over 6 billion GitHub events.
Query Parameters