Understanding Builders
All builders in Octocat follow a similar pattern. Each one implements the Builder
trait, and contains setters for each of its fields, nested or not.
Warning
Builders and methods are currently limited in their variety. This will change with time, however it may take a while for work to resume.
The Builder
trait
#[async_trait]
pub trait Builder {
type Response: DeserializeOwned;
async fn execute<T>(self, client: &T) -> Result<Self::Response, GithubRestError>
where
T: Requester;
}
Examples
Example
Commenting on a commit.
use octocat_rs::{
rest::{
builders::{CommitCommentBuilder, Builder},
model::reactions::Reaction,
client::DefaultRequester,
},
};
let res = CommitCommentBuilder::new()
.owner("octocat-rs")
.repo("octocat-rs")
.sha("fcc8348f8286d05976090a9086d64eefb90e3f8b")
.body("Some text here")
.execute(&DefaultRequester::new("TOKEN"))
.await
.unwrap();
// Prints the URL at which you can find the comment you've just made.
dbg!(res.html_url);
Example
Reacting to a commit comment.
use octocat_rs::{
rest::{
builders::{CommentReactionBuilder, Builder},
model::reactions::Reaction,
client::DefaultRequester,
},
};
let _ = CommentReactionBuilder::new()
.owner("octocat-rs")
.repo("octocat-rs")
.comment_id(67534661)
.reaction(Reaction::Rocket)
.execute(&DefaultRequester::new("TOKEN"))
.await
.unwrap();
// Comment you just reacted to: https://github.com/octocat-rs/octocat-rs/commit/40919cbf40530cf15a002d701a1a1bd6a6006105#commitcomment-67534661