1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! # gritty
//!
//! Gritty is a library for interacting with different Git providers through a common interface.
//! It provides a main trait, [remote::Remote], which has implementations for different Git
//! providers:
//! - [remote::github::GitHubRemote]
//! - [remote::gitlab::GitlabRemote]
//! - [remote::gitea::GiteaRemote]
//!
//! The [remote::Remote] trait provides a main method `create_remote` which returns a remote for
//! the given [remote::Provider] and configuration:
//! ```
//! # async fn run() {
//! use gritty::remote::{self, Remote, RemoteConfig, Provider, Auth, CloneProtocol};
//! use gritty::remote::github::GitHubRemote;
//!
//! let config = RemoteConfig {
//! username: "octocat".to_string(),
//! clone_protocol: CloneProtocol::HTTPS,
//! url: "https://github.com".to_string(),
//! auth: Auth::Token { token: "your-gh-token".to_string() },
//! };
//!
//! let remote = remote::create_remote(&config, Provider::GitHub).await.unwrap();
//! # }
//! ```
//!
//! The [remote::Remote] trait provides methods for interacting with repositories:
//! ```
//! # async fn run() {
//! # use gritty::remote::{
//! self, Remote, RemoteConfig, Provider, Auth, CloneProtocol,
//! RepoCreateInfo, ListReposInfo, RepoForkOption,
//! };
//! # use gritty::remote::github::GitHubRemote;
//! # let config = RemoteConfig {
//! # username: "octocat".to_string(),
//! # clone_protocol: CloneProtocol::HTTPS,
//! # url: "https://github.com".to_string(),
//! # auth: Auth::Token { token: "your-gh-token".to_string() },
//! # };
//! # let remote = remote::create_remote(&config, Provider::GitHub).await.unwrap();
//!
//! // Check if we're authenticated
//! let auth = remote.check_auth().await.unwrap();
//! if !auth {
//! println!("We're not authenticated :(");
//! return;
//! }
//!
//! // Get information about octocat/hello-world
//! let repo = remote.get_repo_info("hello-world").await.unwrap();
//!
//! // Create a new repository
//! let repo_create_info = RepoCreateInfo {
//! name: "a-new-repo".to_string(),
//! description: Some("A new repository for testing".to_string()),
//! license: Some("MIT".to_string()),
//! private: false,
//! init: false,
//! };
//! let new_repo = remote.create_repo(repo_create_info).await.unwrap();
//!
//! // List all repositories, including private ones
//! let list_repos_info = ListReposInfo {
//! private: true, // Include private repositories
//! forks: false, // Exclude forked repositories
//! };
//! let private_repos = remote.list_repos(list_repos_info).await.unwrap();
//!
//! // Fork octocat/hello-world to the authenticated user
//! let repo_fork_info = RepoForkOption {
//! owner: "octocat".to_string(),
//! repo: "hello-world".to_string(),
//! ..Default::default()
//! };
//! let forked_repo = remote.create_fork(repo_fork_info).await.unwrap();
//! # }
//! ```