diff options
author | Teddy Wing | 2020-07-25 18:38:10 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-25 18:38:10 +0200 |
commit | 4acd5cbce9945ef044dc997cb82cfad8273a0dbc (patch) | |
tree | 909aaf4615d08f1cadb299d5876dfa11a16a0c0b /src/bin/git-sugapply.rs | |
parent | a22f7a574cbbad22ed637405bafee42593eab87b (diff) | |
download | git-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/git-sugapply.rs')
-rw-r--r-- | src/bin/git-sugapply.rs | 25 |
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(); +} |