aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorTeddy Wing2020-07-25 18:38:10 +0200
committerTeddy Wing2020-07-25 18:38:10 +0200
commit4acd5cbce9945ef044dc997cb82cfad8273a0dbc (patch)
tree909aaf4615d08f1cadb299d5876dfa11a16a0c0b /src/bin
parenta22f7a574cbbad22ed637405bafee42593eab87b (diff)
downloadgit-suggestion-4acd5cbce9945ef044dc997cb82cfad8273a0dbc.tar.bz2
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.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/git-sugapply.rs25
1 files changed, 25 insertions, 0 deletions
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();
+}