-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
...so users can get a clickable link to see the list of changes between the revisions. This approach makes a few assumptions: - The repo is hosted on GitHub. - The repo has a remote named `origin`, which points to the GitHub repo.
- Loading branch information
Showing
1 changed file
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ impl Changelog { | |
let lines = Changelog::get_lines_from(&output); | ||
let mut lines_iterator = lines.iter(); | ||
|
||
print!("## {}\n\n", self.to_revision); | ||
println!("## {}", self.to_revision); | ||
print!("[Full Changelog](https://github.com/{}/compare/{}...{})\n\n", | ||
self.get_repo_slug(), self.from_revision, self.to_revision); | ||
|
||
loop { | ||
match lines_iterator.next() { | ||
|
@@ -49,6 +51,35 @@ impl Changelog { | |
.split('\n') | ||
.collect() | ||
} | ||
|
||
fn get_repo_slug(&self) -> String { | ||
let output = Command::new("git") | ||
.arg("remote") | ||
.arg("get-url") | ||
.arg("origin") | ||
.current_dir(&self.repository_path) | ||
.output() | ||
.unwrap_or_else(|e| panic!("Failed to run 'git log' with error: {}", e)); | ||
|
||
let url = String::from_utf8_lossy(&output.stdout).into_owned(); | ||
|
||
// The command output contains a trailing newline that we want to get rid of. | ||
let trimmed_url = url.trim(); | ||
|
||
self.get_repo_slug_from(trimmed_url) | ||
} | ||
|
||
fn get_repo_slug_from(&self, url: &str) -> String { | ||
// This very simplistic and stupid algorithm works for repos of these forms: | ||
// https://github.com/dekellum/fishwife.git | ||
// [email protected]:chaos4ever/chaos.git | ||
let mangled_url = url.replace(":", "/").replace(".git", ""); | ||
let mut url_parts: Vec<_> = mangled_url.split('/').collect(); | ||
let repo_name = url_parts.pop().unwrap(); | ||
let org_name = url_parts.pop().unwrap(); | ||
|
||
format!("{}/{}", org_name, repo_name) | ||
} | ||
} | ||
|
||
fn main() { | ||
|