pub struct Repos { /* private fields */ }
Expand description
The Repos struct provides methods for interacting with repositories.
Implementations§
Source§impl Repos
impl Repos
Sourcepub fn delete(&self) -> DeleteRepoBuilder
pub fn delete(&self) -> DeleteRepoBuilder
Deletes a repository by its owner and name. WARNING: This is irreversible and will delete all data associated with the repository. This action cannot be undone. When invoking this method, you will not be asked for confirmation. Use with caution, please don’t nuke your repositories.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.repos("owner", "repo")
.delete()
.send(&client)
.await
.unwrap();
Sourcepub fn get(&self) -> GetRepoBuilder
pub fn get(&self) -> GetRepoBuilder
Gets a repository by its owner and name. This will return a [Repository] object if the repository exists and is visible to the currently authenticated user.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let repo = client
.repos("owner", "repo")
.get()
.send(&client)
.await
.unwrap();
Sourcepub fn create_fork(&self) -> CreateForkBuilder
pub fn create_fork(&self) -> CreateForkBuilder
Forks a repository by its owner and name. The [CreateForkOption] struct provides a number of optional fields to customize the fork, but all fields are entirely optional. If you don’t set any fields, the fork will be created with the same name as the original repository in the authenticated user’s account.
§Examples
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let forked_repo = client
.repos("owner", "repo")
.create_fork()
.name("my-fork")
.send(&client)
.await
.unwrap();
This will fork the repository “owner/repo” into the authenticated user’s account with the name “my-fork”.
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let forked_repo = client
.repos("owner", "repo")
.create_fork()
.organization("my-org")
.send(&client)
.await
.unwrap();
This will fork the repository “owner/repo” into the organization “my-org” with the same name as the original repository.
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let created_repo = client
.user()
.create_repo("my-new-repo")
.send(&client)
.await
.unwrap();
let forked_repo = client
.repos("owner", "my-new-repo")
.create_fork()
.name("my-new-repo")
.send(&client)
.await
.expect_err("Repository with the same name should already exist for the current user");
This will create a new repository with the name “my-new-repo” for the authenticated user, then attempt to fork the repository “owner/repo” into the authenticated user’s account. The fork will fail because a repository with the same name already exists.
Sourcepub fn edit(&self) -> EditRepoBuilder
pub fn edit(&self) -> EditRepoBuilder
Edits a repository by its owner and name.
If you don’t set any fields, the repository will not be modified.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let repo = client
.repos("owner", "repo")
.edit()
.description("A new description")
.send(&client)
.await
.unwrap();
This will set the description of the repository “owner/repo” to “A new description”. If you want to remove the description, you can set it to an empty string.
Sourcepub fn get_forks(&self) -> ListForksBuilder
pub fn get_forks(&self) -> ListForksBuilder
Lists the forks of a repository by its owner and name.
Sourcepub fn get_commits(&self) -> GetCommitsBuilder
pub fn get_commits(&self) -> GetCommitsBuilder
Gets a list of commits for a repository. The [GetCommitsOption] struct provides a number of optional fields to filter the results, but all fields are entirely optional. If you don’t set any fields, you will get the most recent commits for the default branch.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let commits = client
.repos("owner", "repo")
.get_commits()
.send(&client)
.await
.unwrap();
Sourcepub fn list_branches(&self) -> ListBranchesBuilder
pub fn list_branches(&self) -> ListBranchesBuilder
Lists a repository’s branches.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let branches = client
.repos("owner", "repo")
.list_branches()
.send(&client)
.await
.unwrap();
This will list the branches for the repository “owner/repo”.
Sourcepub fn create_branch(
&self,
new_branch_name: impl ToString,
) -> CreateBranchBuilder
pub fn create_branch( &self, new_branch_name: impl ToString, ) -> CreateBranchBuilder
Creates a new branch in a repository.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.repos("owner", "repo")
.create_branch("new-branch")
.old_ref_name("main")
.send(&client)
.await
.unwrap();
This will create a new branch named “new-branch” in the repository “owner/repo” based on the “main” branch.
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.repos("owner", "repo")
.create_branch("new-branch")
.send(&client)
.await
.unwrap();
This will create a new empty branch named “new-branch” in the repository “owner/repo”
Sourcepub fn get_branch(&self, branch: impl ToString) -> GetBranchBuilder
pub fn get_branch(&self, branch: impl ToString) -> GetBranchBuilder
Gets a branch in a repository. This will return a Branch object if the branch exists.
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
let branch = client
.repos("owner", "repo")
.get_branch("main")
.send(&client)
.await
.unwrap();
This will get the branch “main” in the repository “owner/repo”.
Sourcepub fn delete_branch(&self, branch: impl ToString) -> DeleteBranchBuilder
pub fn delete_branch(&self, branch: impl ToString) -> DeleteBranchBuilder
Deletes a branch in a repository. WARNING: This is irreversible and will delete all data associated with the branch. This action cannot be undone. When invoking this method, you will not be asked for confirmation. Use with caution
§Example
let client = Client::new(
"https://gitea.example.com",
Auth::Token("your-token")
);
client
.repos("owner", "repo")
.delete_branch("branch-to-delete")
.send(&client)
.await
.unwrap();
This will delete the branch “branch-to-delete” in the repository “owner/repo”.