os-checker / plugin-github-api

0 stars 0 forks source link

重构:使用 GraphQL 获取 Github APIs #3

Open zjp-CN opened 2 weeks ago

zjp-CN commented 2 weeks ago

https://docs.github.com/en/graphql/overview/about-the-graphql-api

https://lib.rs/crates/graphql_client

https://github.com/graphql-rust/graphql-client/blob/main/examples/github/examples/github.rs

原因:

// REST API
struct Info {
    owner: Owner,
    license: Option<License>,
}
struct Owner {
    /// user name
    login: String,
    /// Organization, User, Bot or something
    r#type: String,
}
struct License {
    spdx_id: String,
}

// GraphQL: 只需要定义 scheme 来描述如何查询
struct Info {
    owner: String,
    owner_type: String,
    license: Option<String>,
}
zjp-CN commented 1 day ago
查看 os-checker 组织的仓库和是否产生自 fork 的情况

```graphql { organization(login: "os-checker") { repositories(last: 10) { nodes { name isFork parent { owner { login } name } } } } } ``` ```json { "data": { "organization": { "repositories": { "nodes": [ { "name": "plugin-cargo", "isFork": false, "parent": null }, { "name": "charon", "isFork": true, "parent": { "owner": { "login": "AeneasVerif" }, "name": "charon" } }, { "name": "Rudra", "isFork": true, "parent": { "owner": { "login": "sslab-gatech" }, "name": "Rudra" } }, { "name": "Starry", "isFork": true, "parent": { "owner": { "login": "Starry-OS" }, "name": "Starry" } }, { "name": "docs", "isFork": false, "parent": null }, { "name": "lkmodel", "isFork": true, "parent": { "owner": { "login": "shilei-massclouds" }, "name": "lkmodel" } }, { "name": "MWE-feature-selection-in-workspace", "isFork": false, "parent": null }, { "name": "plugin", "isFork": false, "parent": null }, { "name": "test-database", "isFork": false, "parent": null }, { "name": "os-checker-action", "isFork": false, "parent": null } ] } } } } ```

筛选 os-checker 组织中被 fork 仓库的父仓库

```graphql { organization(login: "os-checker") { repositories(last: 10, isFork: true) { nodes { name parent { owner { login } name } } } } } ``` ```json { "data": { "organization": { "repositories": { "nodes": [ { "name": "MIRAI", "parent": { "owner": { "login": "endorlabs" }, "name": "MIRAI" } }, { "name": "kern-crates.github", "parent": { "owner": { "login": "kern-crates" }, "name": ".github" } }, { "name": "cargo_metadata", "parent": { "owner": { "login": "oli-obk" }, "name": "cargo_metadata" } }, { "name": "jsonxf", "parent": { "owner": { "login": "gamache" }, "name": "jsonxf" } }, { "name": "RAP", "parent": { "owner": { "login": "Artisan-Lab" }, "name": "RAP" } }, { "name": "fork-cargo-geiger", "parent": { "owner": { "login": "mleonhard" }, "name": "fork-cargo-geiger" } }, { "name": "charon", "parent": { "owner": { "login": "AeneasVerif" }, "name": "charon" } }, { "name": "Rudra", "parent": { "owner": { "login": "sslab-gatech" }, "name": "Rudra" } }, { "name": "Starry", "parent": { "owner": { "login": "Starry-OS" }, "name": "Starry" } }, { "name": "lkmodel", "parent": { "owner": { "login": "shilei-massclouds" }, "name": "lkmodel" } } ] } } } } ```