Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
git: support SSH keys for authentication to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine Dodrill committed Jun 11, 2020
1 parent 646f8ea commit f96085c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ This is the first release of palisade!
- TL;DR Rust document
- GitHub Action support
- Commentary across the project
- Support using SSH keys for authentication to GitHub
14 changes: 11 additions & 3 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ use git2::{Cred, RemoteCallbacks, Repository, Signature};
/// Push all tags in the repo to the upstream origin.
pub(crate) fn push_tag(repo: &Repository, token: &String, tag: &String) -> Result<()> {
let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(|_u, _username_from_url, _allowed_types| {
Cred::userpass_plaintext(&token, "")
callbacks.credentials(|_u, _username_from_url, allowed_types| {
if allowed_types.contains(git2::CredentialType::SSH_KEY) {
let user = "git";
git2::Cred::ssh_key_from_agent(user)
} else {
Cred::userpass_plaintext(&token, "")
}
});
let mut remote = repo.find_remote("origin")?;
let mut po = git2::PushOptions::new();
po.remote_callbacks(callbacks);

match remote.push(&[&format!("refs/tags/{}:refs/tags/{}", tag, tag)], Some(&mut po)) {
match remote.push(
&[&format!("refs/tags/{}:refs/tags/{}", tag, tag)],
Some(&mut po),
) {
Ok(_) => Ok(()),
Err(why) => Err(anyhow!("git push error: {:?}", why)),
}
Expand Down

0 comments on commit f96085c

Please sign in to comment.