Compare commits

..

1 commit

Author SHA1 Message Date
3ce69efeba WIP: add github crate
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-28 06:37:53 +01:00
4 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,45 @@
use git_next_config as config;
use git_next_git as git;
use kxio::network::{self, Network};
pub async fn get_all(
repo_details: &git::RepoDetails,
net: &Network,
) -> git::branch::Result<Vec<config::BranchName>> {
let hostname = &repo_details.forge.hostname();
let repo_path = &repo_details.repo_path;
use secrecy::ExposeSecret;
let token = repo_details.forge.token().expose_secret();
let url = network::NetUrl::new(format!(
"https://{hostname}/api/v1/repos/{repo_path}/branches?token={token}"
));
let request = network::NetRequest::new(
network::RequestMethod::Get,
url,
network::NetRequestHeaders::new(),
network::RequestBody::None,
network::ResponseType::Json,
None,
network::NetRequestLogging::None,
);
let response = net.get::<Vec<Branch>>(request).await?;
let branches = response
.response_body()
.unwrap_or_default()
.into_iter()
.map(config::BranchName::from)
.collect::<Vec<_>>();
Ok(branches)
}
#[derive(Debug, serde::Deserialize)]
struct Branch {
name: String,
}
impl From<Branch> for config::BranchName {
fn from(value: Branch) -> Self {
Self::new(value.name)
}
}

View file

@ -0,0 +1,3 @@
mod get_all;
pub use get_all::get_all;

View file

@ -1,3 +1,5 @@
pub mod branch;
use git_next_git as git;
use kxio::network::{self, Network};

View file

@ -2,6 +2,7 @@
#![allow(dead_code)]
use derive_more::Constructor;
use git_next_config as config;
use git_next_git as git;
use kxio::network::Network;
@ -18,6 +19,9 @@ impl git_next_git::ForgeLike for Github {
fn name(&self) -> String {
"github".to_string()
}
async fn branches_get_all(&self) -> Result<Vec<config::BranchName>, git::branch::Error> {
todo!();
}
/// Checks the results of any (e.g. CI) status checks for the commit.
async fn commit_status(&self, _commit: &git::Commit) -> git::commit::Status {