aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..c0aeb3b
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,67 @@
+#![warn(rust_2018_idioms)]
+
+
+use github_rs::client::{Executor, Github};
+use serde_json::Value;
+use thiserror::Error;
+
+
+#[derive(Debug, Error)]
+pub enum Error {
+ #[error("GitHub client error: {0}")]
+ Github(String),
+}
+
+
+pub struct Suggestion<'a> {
+ client: Github,
+ owner: &'a str,
+ repo: &'a str,
+}
+
+impl<'a> Suggestion<'a> {
+ pub fn new(token: &str, owner: &'a str, repo: &'a str) -> Self {
+ let client = Github::new(&token).unwrap();
+
+ Suggestion { client, owner, repo }
+ }
+
+ pub fn fetch(&self, id: &str) -> Result<(), Error> {
+ let comment = self.client
+ .get()
+ .repos()
+ .owner(self.owner)
+ .repo(self.repo)
+ .pulls()
+ .comments()
+ .id(id)
+ .execute::<Value>();
+
+ match comment {
+ Ok((_, _, json)) => {
+ println!("{:?}", json);
+
+ Ok(())
+ },
+ Err(e) => Err(Error::Github(e.to_string())),
+ }
+ }
+
+ pub fn patch(&self) {
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn suggestion_fetch_gets_pull_request_comment() {
+ let suggestion = Suggestion::new(
+ env!("GITHUB_TOKEN"),
+ "cli",
+ "cli",
+ );
+ suggestion.fetch("438947607").unwrap();
+ }
+}