From 4acd5cbce9945ef044dc997cb82cfad8273a0dbc Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 25 Jul 2020 18:38:10 +0200 Subject: Add git-sugapply bin An executable to apply a suggested change to the appropriate file in the repo. Add a new `SuggestionUrl` type that allows us to extract the necessary data to fetch a suggestion comment from the GitHub API using a GitHub pull request comment URL. --- src/bin/git-sugapply.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/git-sugapply.rs (limited to 'src/bin') diff --git a/src/bin/git-sugapply.rs b/src/bin/git-sugapply.rs new file mode 100644 index 0000000..d569147 --- /dev/null +++ b/src/bin/git-sugapply.rs @@ -0,0 +1,25 @@ +use std::env; +use std::process; + +use git_suggested_patch::{Client, SuggestionUrl}; + + +fn main() { + let args: Vec<_> = env::args().collect(); + + if args.len() < 2 { + process::exit(111); + } + + let url: SuggestionUrl = args[1].parse().unwrap(); + + let client = Client::new( + env!("GITHUB_TOKEN"), + &url.owner, + &url.repo, + ); + + let suggestion = client.fetch(&url.comment_id).unwrap(); + + suggestion.apply().unwrap(); +} -- cgit v1.2.3