Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Add repo sub command
Browse files Browse the repository at this point in the history
- Add `repo` sub command.
- Show repo basic info as the inital functionality.
- Use the GH graphql api.
- Add `graphql_client` crate.
- Add `graphql` queries directory in the root with the basic_info query.
- Include files generated using `graphql-client` CLI.
   This need to be part of a `build.rs` for later.
  • Loading branch information
aslamplr committed May 15, 2020
1 parent a5ed8f1 commit 361ca4c
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
SECRET.txt
graphql/schema/

188 changes: 188 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ sodiumoxide = "0.2.5"
base64 = "0.12.0"
async-trait = "0.1.30"
ansi_term = "0.12.1"
graphql_client = "0.9.0"
20 changes: 20 additions & 0 deletions graphql/query/repo_basic_info.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
query RepoBasicInfoQuery($name: String!, $owner: String!) {
repository(name: $name, owner: $owner) {
nameWithOwner
description
createdAt
pushedAt
homepageUrl
isPrivate
isArchived
primaryLanguage {
name
}
licenseInfo {
name
}
stargazers {
totalCount
}
}
}
33 changes: 33 additions & 0 deletions src/core/basic_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use super::repos::{Repo, RepoRequest};
pub use crate::graphql::repo_basic_info::repo_basic_info_query as basic_info_response;
use crate::{graphql::repo_basic_info::RepoBasicInfoQuery, utils::graphql::query_graphql};
use anyhow::Result;
use async_trait::async_trait;
use graphql_client::GraphQLQuery as _;

pub type BasicInfoResponse = basic_info_response::ResponseData;

#[async_trait]
pub trait BasicInfo {
async fn get_basic_info(&self) -> Result<BasicInfoResponse>;
}

impl From<&Repo<'_>> for basic_info_response::Variables {
fn from(repo: &Repo<'_>) -> Self {
basic_info_response::Variables {
name: repo.repo_name.to_owned(),
owner: repo.repo_owner.to_owned(),
}
}
}

#[async_trait]
impl BasicInfo for RepoRequest<'_> {
async fn get_basic_info(&self) -> Result<BasicInfoResponse> {
let RepoRequest(repo, auth_token) = self;
let graphql_query = RepoBasicInfoQuery::build_query(repo.into());
let resp = query_graphql(graphql_query, &auth_token).await?;
resp.data
.ok_or_else(|| anyhow::anyhow!("Couldn't find repository basic information!"))
}
}
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod basic_info;
pub mod repos;
pub mod secrets;
1 change: 1 addition & 0 deletions src/graphql/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod repo_basic_info;
Loading

0 comments on commit 361ca4c

Please sign in to comment.