aboutsummaryrefslogtreecommitdiffstats
path: root/github-suggestion/src/suggestion.rs
diff options
context:
space:
mode:
authorTeddy Wing2020-08-02 18:49:36 +0200
committerTeddy Wing2020-08-02 18:49:51 +0200
commit8e5ac6f2d4e52eea95e5a6fc2905ce511ac4956e (patch)
treef5e56fbf1fc673c8a75f160c297fa79d0937e0d4 /github-suggestion/src/suggestion.rs
parent646ed6c2027864b6373453c2f529796f01b3e715 (diff)
downloadgit-suggestion-8e5ac6f2d4e52eea95e5a6fc2905ce511ac4956e.tar.bz2
Add documentation comments
Light documentation for our various functions and types.
Diffstat (limited to 'github-suggestion/src/suggestion.rs')
-rw-r--r--github-suggestion/src/suggestion.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/github-suggestion/src/suggestion.rs b/github-suggestion/src/suggestion.rs
index 2c92e6a..48fcb0c 100644
--- a/github-suggestion/src/suggestion.rs
+++ b/github-suggestion/src/suggestion.rs
@@ -40,6 +40,7 @@ enum LineEnding {
CrLf,
}
+/// A suggestion comment extracted from the GitHub API.
#[derive(Debug, Deserialize)]
pub struct Suggestion {
#[serde(rename = "diff_hunk")]
@@ -60,12 +61,14 @@ pub struct Suggestion {
}
impl Suggestion {
+ /// Get the suggestion diff for the current repository.
pub fn diff(&self) -> Result<String, Error> {
let repo = Repository::open(".")?;
self.diff_with_repo(&repo)
}
+ /// Get the suggestion diff for `repo`.
fn diff_with_repo(&self, repo: &Repository) -> Result<String, Error> {
let commit = repo.find_commit(self.commit.parse()?)?;
@@ -104,6 +107,7 @@ impl Suggestion {
)
}
+ /// Extract suggestion code from a comment body.
fn suggestion_with_line_ending(
&self,
line_ending: &LineEnding,
@@ -120,6 +124,7 @@ impl Suggestion {
Ok(s)
}
+ /// Apply the suggestion to the current repository.
pub fn apply(&self) -> Result<(), Error> {
let repo = Repository::open(".")?;
@@ -135,6 +140,7 @@ impl Suggestion {
Ok(())
}
+ /// Apply the patch in `reader` to `writer`.
fn apply_to<R: BufRead, W: Write>(
&self,
reader: R,