Skip to content

Commit 5466e81

Browse files
Merge pull request #195 from MordechaiHadad/feat/git-alias
Add latest commit alias
2 parents f70cd68 + 4a6f6b1 commit 5466e81

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/github_requests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct UpstreamVersion {
1212

1313
#[derive(Serialize, Deserialize, Debug)]
1414
pub struct RepoCommit {
15+
pub sha: String,
1516
pub commit: Commit,
1617
}
1718

src/helpers/version/mod.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use self::types::{ParsedVersion, VersionType};
55
use super::directories;
66
use crate::{
77
config::Config,
8-
github_requests::{deserialize_response, UpstreamVersion},
8+
github_requests::{deserialize_response, RepoCommit, UpstreamVersion},
99
};
1010
use anyhow::{anyhow, Context, Result};
1111
use regex::Regex;
@@ -37,6 +37,16 @@ pub async fn parse_version_type(client: &Client, version: &str) -> Result<Parsed
3737
semver: Some(Version::parse(&cloned_version.replace('v', ""))?),
3838
})
3939
}
40+
"head" | "git" | "HEAD" => {
41+
info!("Fetching latest commit");
42+
let latest_commit = get_latest_commit(client).await?;
43+
Ok(ParsedVersion {
44+
tag_name: latest_commit.chars().take(7).collect(),
45+
version_type: VersionType::Hash,
46+
non_parsed_string: latest_commit,
47+
semver: None,
48+
})
49+
}
4050
_ => {
4151
let version_regex = Regex::new(r"^v?[0-9]+\.[0-9]+\.[0-9]+$")?;
4252
let hash_regex = Regex::new(r"\b[0-9a-f]{5,40}\b")?;
@@ -143,3 +153,18 @@ async fn search_stable_version(client: &Client) -> Result<String> {
143153
.ok_or(anyhow!("Cannot find version of stable release"))?;
144154
Ok(stable_pin_release.tag_name.clone())
145155
}
156+
157+
async fn get_latest_commit(client: &Client) -> Result<String> {
158+
let response = client
159+
.get("https://api.github.com/repos/neovim/neovim/commits/master")
160+
.header("user-agent", "bob")
161+
.header("Accept", "application/vnd.github.v3+json")
162+
.send()
163+
.await?
164+
.text()
165+
.await?;
166+
167+
let commit: RepoCommit = deserialize_response(response)?;
168+
169+
Ok(commit.sha)
170+
}

0 commit comments

Comments
 (0)