Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 93c5b6f

Browse files
committed
Find next version bump
1 parent f5b7a49 commit 93c5b6f

File tree

4 files changed

+64
-51
lines changed

4 files changed

+64
-51
lines changed

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "commit-walker"
2+
name = "commit_walker"
33
version = "0.1.0"
44
authors = ["Jan-Erik Rediger <janerik@fnordig.de>"]
55

‎src/lib.rs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
extern crate git2;
2+
extern crate semver;
3+
extern crate commit_analyzer;
4+
5+
use git2::{Repository, Commit};
6+
use semver::Version;
7+
use commit_analyzer::CommitType;
8+
9+
fn range_to_head(commit: &str) -> String {
10+
format!("{}..HEAD", commit)
11+
}
12+
13+
fn format_commit(commit: Commit) -> String {
14+
format!("{}\n{}", commit.id(), commit.message().unwrap_or(""))
15+
}
16+
17+
pub fn latest_tag(path: &str) -> Version {
18+
let repo = Repository::open(path).unwrap();
19+
let mut biggest_tag = Version::parse("0.0.0").unwrap();
20+
21+
let tags = repo.tag_names(None).unwrap();
22+
for tag in tags.iter() {
23+
let tag = tag.unwrap();
24+
let tag = &tag[1..];
25+
let v = Version::parse(tag).unwrap();
26+
27+
if v > biggest_tag {
28+
biggest_tag = v;
29+
}
30+
}
31+
32+
biggest_tag
33+
}
34+
35+
pub fn version_bump_since_latest(path: &str) -> CommitType {
36+
let tag = latest_tag(path);
37+
38+
let tag = format!("v{}", tag.to_string());
39+
version_bump_since_tag(path, &tag)
40+
}
41+
42+
pub fn version_bump_since_tag(path: &str, tag: &str) -> CommitType {
43+
let tag = range_to_head(tag);
44+
45+
let repo = Repository::open(path).unwrap();
46+
47+
let mut walker = repo.revwalk().unwrap();
48+
walker.push_range(&tag).unwrap();
49+
50+
let tag = walker.map(|c| repo.find_commit(c).unwrap())
51+
.map(|c| format_commit(c))
52+
.map(|c| commit_analyzer::analyze_single(&c).unwrap())
53+
.max().unwrap();
54+
55+
tag
56+
}

‎src/main.rs‎

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,16 @@
1-
extern crate git2;
2-
extern crate semver;
3-
extern crate commit_analyzer;
4-
5-
use git2::{Repository, Commit};
6-
use semver::Version;
1+
extern crate commit_walker;
72

83
use std::env;
94

10-
fn range_to_head(commit: &str) -> String {
11-
format!("{}..HEAD", commit)
12-
}
13-
14-
fn format_commit(commit: Commit) -> String {
15-
format!("{}\n{}", commit.id(), commit.message().unwrap_or(""))
16-
}
17-
185
fn main() {
196
let args = env::args().skip(1).collect::<Vec<_>>();
207

218
let path = args[0].clone();
22-
// let tag = args[1].clone();
23-
24-
let repo = Repository::open(path).unwrap();
25-
let mut biggest_tag = Version::parse("0.0.0").unwrap();
26-
27-
if let Some(tag) = args.get(1) {
28-
biggest_tag = Version::parse(tag).unwrap();
29-
} else {
30-
println!("Tags!");
31-
let tags = repo.tag_names(None).unwrap();
32-
for tag in tags.iter() {
33-
let tag = tag.unwrap();
34-
let tag = &tag[1..];
35-
let v = Version::parse(tag).unwrap();
36-
37-
if v > biggest_tag {
38-
biggest_tag = v;
39-
}
40-
}
41-
}
42-
43-
println!("Biggest tag: {:?}", biggest_tag.to_string());
449

45-
let mut walker = repo.revwalk().unwrap();
46-
// walker.push_head();
47-
//let oid = Oid::from_str("8a4fb449a5db41a539f2738e5f5ce9d3804d555a").unwrap();
48-
//walker.set_sorting(git2::SORT_TIME);
49-
let start_tag = format!("v{}", biggest_tag.to_string());
50-
let start_tag = range_to_head(&start_tag);
51-
walker.push_range(&start_tag).unwrap();
10+
let bump = match args.get(1) {
11+
Some(tag) => commit_walker::version_bump_since_tag(&path, &tag),
12+
None => commit_walker::version_bump_since_latest(&path)
13+
};
5214

53-
println!("Walker!");
54-
let commits = walker.map(|c| repo.find_commit(c).unwrap())
55-
.map(|c| format_commit(c))
56-
.map(|c| commit_analyzer::analyze_single(&c).unwrap())
57-
.max();
58-
println!("Commits: {:?}", commits);
15+
println!("Next version: {:?}", bump);
5916
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /