github_analytics/api/
mod.rs1use eyre::{eyre, Result};
2
3pub const QUERY: &str = r#"query ($name: String!, $owner: String!) {
5 repository(name: $name, owner: $owner) {
6 pullRequests(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
7 nodes {
8 createdAt
9 mergedAt
10 author {
11 login
12 }
13 }
14 }
15 issues(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
16 nodes {
17 author {
18 login
19 }
20 createdAt
21 closedAt
22 }
23 }
24 }
25 }"#;
26
27const URL: &str = "https://api.github.com/graphql";
29
30pub async fn gql_query(
40 client: &reqwest::Client,
41 query: &&str,
42 token: &String,
43 owner: &&str,
44 repo: &&str,
45) -> Result<serde_json::Value> {
46 client
47 .post(URL)
48 .bearer_auth(token)
49 .json(&serde_json::json!({
50 "query": query,
51 "variables": {
52 "owner": owner,
53 "name": repo,
54 }
55 }))
56 .send()
57 .await?
58 .json::<serde_json::Value>()
59 .await
60 .map_err(|e| eyre!(e))
61}