1
0
Fork 0

Adding upstream version 0.7.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-04 07:26:33 +01:00
parent 3be060267e
commit 5e5f129729
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
11 changed files with 2459 additions and 3856 deletions

View file

@ -1,6 +1,6 @@
{
"git": {
"sha1": "041a56ecea92e78400f8dea7dad2b7f9c175c22a"
"sha1": "6f990c84d4cdffb994f1008cf5dba94c9b3b32ca"
},
"path_in_vcs": ""
}

1689
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,7 @@
[package]
edition = "2021"
name = "forgejo-api"
version = "0.6.0"
version = "0.7.0"
build = false
autolib = false
autobins = false
@ -32,6 +32,10 @@ path = "src/lib.rs"
name = "admin"
path = "tests/admin.rs"
[[test]]
name = "headers"
path = "tests/headers.rs"
[[test]]
name = "organization"
path = "tests/organization.rs"

2
Cargo.toml.orig generated
View file

@ -1,7 +1,7 @@
workspace = { members = ["generator"] }
[package]
name = "forgejo-api"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0 OR MIT"
repository = "https://codeberg.org/Cyborus/forgejo-api"

View file

@ -119,11 +119,11 @@ impl crate::Forgejo {
pub async fn admin_get_all_emails(
&self,
query: AdminGetAllEmailsQuery,
) -> Result<(EmailListHeaders, Vec<Email>), ForgejoError> {
) -> Result<Vec<Email>, ForgejoError> {
let request = self.get(&format!("admin/emails?{query}")).build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -133,11 +133,11 @@ impl crate::Forgejo {
pub async fn admin_search_emails(
&self,
query: AdminSearchEmailsQuery,
) -> Result<(EmailListHeaders, Vec<Email>), ForgejoError> {
) -> Result<Vec<Email>, ForgejoError> {
let request = self.get(&format!("admin/emails/search?{query}")).build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -725,13 +725,11 @@ impl crate::Forgejo {
}
/// Returns a list of all gitignore templates
pub async fn list_gitignores_templates(
&self,
) -> Result<(GitignoreTemplateListHeaders, Vec<String>), ForgejoError> {
pub async fn list_gitignores_templates(&self) -> Result<Vec<String>, ForgejoError> {
let request = self.get("gitignore/templates").build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -752,13 +750,11 @@ impl crate::Forgejo {
}
/// Returns a list of all label templates
pub async fn list_label_templates(
&self,
) -> Result<(LabelTemplateListHeaders, Vec<String>), ForgejoError> {
pub async fn list_label_templates(&self) -> Result<Vec<String>, ForgejoError> {
let request = self.get("label/templates").build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -781,11 +777,11 @@ impl crate::Forgejo {
/// Returns a list of all license templates
pub async fn list_license_templates(
&self,
) -> Result<(LicenseTemplateListHeaders, Vec<LicensesTemplateListEntry>), ForgejoError> {
) -> Result<Vec<LicensesTemplateListEntry>, ForgejoError> {
let request = self.get("licenses").build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -2006,13 +2002,13 @@ impl crate::Forgejo {
owner: &str,
repo: &str,
query: ListActionTasksQuery,
) -> Result<(TasksListHeaders, ActionTaskResponse), ForgejoError> {
) -> Result<ActionTaskResponse, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/actions/tasks?{query}"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -2270,13 +2266,13 @@ impl crate::Forgejo {
&self,
owner: &str,
repo: &str,
) -> Result<(BranchProtectionListHeaders, Vec<BranchProtection>), ForgejoError> {
) -> Result<Vec<BranchProtection>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/branch_protections"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -3186,13 +3182,13 @@ impl crate::Forgejo {
&self,
owner: &str,
repo: &str,
) -> Result<(ReferenceListHeaders, Vec<Reference>), ForgejoError> {
) -> Result<Vec<Reference>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/git/refs"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -3207,13 +3203,13 @@ impl crate::Forgejo {
owner: &str,
repo: &str,
r#ref: &str,
) -> Result<(ReferenceListHeaders, Vec<Reference>), ForgejoError> {
) -> Result<Vec<Reference>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/git/refs/{ref}"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -3673,13 +3669,13 @@ impl crate::Forgejo {
owner: &str,
repo: &str,
id: u64,
) -> Result<(AttachmentListHeaders, Vec<Attachment>), ForgejoError> {
) -> Result<Vec<Attachment>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/issues/comments/{id}/assets"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -3967,13 +3963,13 @@ impl crate::Forgejo {
owner: &str,
repo: &str,
index: u64,
) -> Result<(AttachmentListHeaders, Vec<Attachment>), ForgejoError> {
) -> Result<Vec<Attachment>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/issues/{index}/assets"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -5764,7 +5760,7 @@ impl crate::Forgejo {
repo: &str,
index: u64,
id: u64,
) -> Result<(PullReviewCommentListHeaders, Vec<PullReviewComment>), ForgejoError> {
) -> Result<Vec<PullReviewComment>, ForgejoError> {
let request = self
.get(&format!(
"repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments"
@ -5772,7 +5768,7 @@ impl crate::Forgejo {
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -6236,13 +6232,13 @@ impl crate::Forgejo {
owner: &str,
repo: &str,
id: u64,
) -> Result<(AttachmentListHeaders, Vec<Attachment>), ForgejoError> {
) -> Result<Vec<Attachment>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/releases/{id}/assets"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -6561,13 +6557,13 @@ impl crate::Forgejo {
&self,
owner: &str,
repo: &str,
) -> Result<(TagProtectionListHeaders, Vec<TagProtection>), ForgejoError> {
) -> Result<Vec<TagProtection>, ForgejoError> {
let request = self
.get(&format!("repos/{owner}/{repo}/tag_protections"))
.build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -7717,11 +7713,11 @@ impl crate::Forgejo {
}
/// List the authenticated user's email addresses
pub async fn user_list_emails(&self) -> Result<(EmailListHeaders, Vec<Email>), ForgejoError> {
pub async fn user_list_emails(&self) -> Result<Vec<Email>, ForgejoError> {
let request = self.get("user/emails").build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
200 => Ok((response.headers().try_into()?, response.json().await?)),
200 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}
@ -7732,11 +7728,11 @@ impl crate::Forgejo {
pub async fn user_add_email(
&self,
body: CreateEmailOption,
) -> Result<(EmailListHeaders, Vec<Email>), ForgejoError> {
) -> Result<Vec<Email>, ForgejoError> {
let request = self.post("user/emails").json(&body).build()?;
let response = self.execute(request).await?;
match response.status().as_u16() {
201 => Ok((response.headers().try_into()?, response.json().await?)),
201 => Ok(response.json().await?),
_ => Err(ForgejoError::UnexpectedStatusCode(response.status())),
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -34,7 +34,7 @@ async fn user() {
"could not find new user"
);
let query = AdminGetAllEmailsQuery::default();
let (_, users) = api
let users = api
.admin_get_all_emails(query)
.await
.expect("failed to search emails");

View file

@ -1,3 +1,4 @@
use forgejo_api::structs::*;
use forgejo_api::Forgejo;
pub fn login() -> Forgejo {
@ -15,3 +16,117 @@ pub fn login_pass(username: &str, password: &str) -> Forgejo {
};
Forgejo::new(auth, url).unwrap()
}
pub struct Git {
dir: &'static std::path::Path,
}
impl Git {
pub fn new<T: AsRef<std::path::Path> + ?Sized>(path: &'static T) -> Self {
let dir = path.as_ref();
std::fs::create_dir_all(dir).unwrap();
Self { dir }
}
pub fn run(&self, args: &[impl AsRef<std::ffi::OsStr>]) {
let mut cmd = std::process::Command::new("git");
cmd.current_dir(self.dir);
let _ = cmd.args(args).status().unwrap();
}
}
pub async fn setup_local_repo(git: &Git) {
git.run(&["config", "--global", "init.defaultBranch", "main"]);
git.run(&["init"]);
git.run(&["config", "user.name", "TestingAdmin"]);
git.run(&["config", "user.email", "admin@noreply.example.org"]);
tokio::fs::write(&git.dir.join("README.md"), "# Test\nThis is a test repo")
.await
.unwrap();
git.run(&["add", "."]);
git.run(&["commit", "-m", "initial commit"]);
}
pub async fn basic_repo(api: &forgejo_api::Forgejo, git: &Git, name: &str) -> Repository {
setup_local_repo(git).await;
let repo_opt = CreateRepoOption {
auto_init: Some(false),
default_branch: Some("main".into()),
description: Some("Test Repo".into()),
gitignores: Some("".into()),
issue_labels: Some("".into()),
license: Some("".into()),
name: name.into(),
object_format_name: None,
private: Some(false),
readme: None,
template: Some(false),
trust_model: Some(CreateRepoOptionTrustModel::Default),
};
let remote_repo = api.create_current_user_repo(repo_opt).await.unwrap();
assert!(
remote_repo.has_pull_requests.unwrap(),
"repo does not accept pull requests"
);
assert!(
remote_repo.owner.as_ref().unwrap().login.as_ref().unwrap() == "TestingAdmin",
"repo owner is not \"TestingAdmin\""
);
assert!(
remote_repo.name.as_ref().unwrap() == name,
"repo name is not \"{name}\""
);
let mut remote_url = remote_repo.clone_url.clone().unwrap();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
git.run(&["remote", "add", "origin", remote_url.as_str()]);
git.run(&["push", "-u", "origin", "main"]);
remote_repo
}
pub async fn basic_org_repo(
api: &forgejo_api::Forgejo,
git: &Git,
org: &str,
name: &str,
) -> Repository {
setup_local_repo(git).await;
let repo_opt = CreateRepoOption {
auto_init: Some(false),
default_branch: Some("main".into()),
description: Some("Test Repo".into()),
gitignores: Some("".into()),
issue_labels: Some("".into()),
license: Some("".into()),
name: name.into(),
object_format_name: None,
private: Some(false),
readme: None,
template: Some(false),
trust_model: Some(CreateRepoOptionTrustModel::Default),
};
let remote_repo = api.create_org_repo(org, repo_opt).await.unwrap();
assert!(
remote_repo.has_pull_requests.unwrap(),
"repo does not accept pull requests"
);
assert!(
remote_repo.owner.as_ref().unwrap().login.as_ref().unwrap() == org,
"repo owner is not \"TestingAdmin\""
);
assert!(
remote_repo.name.as_ref().unwrap() == name,
"repo name is not \"{name}\""
);
let mut remote_url = remote_repo.clone_url.clone().unwrap();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
git.run(&["remote", "add", "origin", remote_url.as_str()]);
git.run(&["push", "-u", "origin", "main"]);
remote_repo
}

385
tests/headers.rs Normal file
View file

@ -0,0 +1,385 @@
mod common;
use common::Git;
use forgejo_api::structs::*;
macro_rules! test_header {
($e:expr, $header:ident) => {
let (headers, _) = $e.await.expect("api called failed");
assert!(headers.$header.is_some());
};
}
#[tokio::test]
async fn total_count() {
// password login needed for user_get_tokens
let api = common::login_pass("TestingAdmin", "password");
test_header!(
api.user_get_tokens("TestingAdmin", UserGetTokensQuery::default()),
x_total_count
);
test_header!(
api.user_list_activity_feeds("TestingAdmin", UserListActivityFeedsQuery::default()),
x_total_count
);
test_header!(
api.user_current_list_gpg_keys(UserCurrentListGpgKeysQuery::default()),
x_total_count
);
test_header!(
api.user_get_oauth2_applications(UserGetOAuth2ApplicationsQuery::default()),
x_total_count
);
test_header!(
api.user_get_oauth2_applications(UserGetOAuth2ApplicationsQuery::default()),
x_total_count
);
test_header!(
api.user_current_list_keys(UserCurrentListKeysQuery::default()),
x_total_count
);
test_header!(
api.user_list_blocked_users(UserListBlockedUsersQuery::default()),
x_total_count
);
test_header!(
api.user_current_list_repos(UserCurrentListReposQuery::default()),
x_total_count
);
test_header!(
api.user_get_stop_watches(UserGetStopWatchesQuery::default()),
x_total_count
);
test_header!(
api.user_current_tracked_times(UserCurrentTrackedTimesQuery::default()),
x_total_count
);
test_header!(
api.user_list_followers("TestingAdmin", UserListFollowersQuery::default()),
x_total_count
);
test_header!(
api.list_packages("TestingAdmin", ListPackagesQuery::default()),
x_total_count
);
test_header!(
api.notify_get_list(NotifyGetListQuery::default()),
x_total_count
);
let git = Git::new("./test_repos/header_test");
common::basic_repo(&api, &git, "header_test").await;
let body = CreateIssueOption {
assignee: None,
assignees: None,
body: None,
closed: None,
due_date: None,
labels: None,
milestone: None,
r#ref: None,
title: "Test".into(),
};
api.issue_create_issue("TestingAdmin", "header_test", body)
.await
.unwrap();
let body = EditReactionOption {
content: Some("+1".into()),
};
api.issue_post_issue_reaction("TestingAdmin", "header_test", 1, body)
.await
.unwrap();
test_header!(
api.issue_get_issue_reactions(
"TestingAdmin",
"header_test",
1,
IssueGetIssueReactionsQuery::default()
),
x_total_count
);
test_header!(
api.issue_list_issues(
"TestingAdmin",
"header_test",
IssueListIssuesQuery::default()
),
x_total_count
);
test_header!(
api.issue_list_labels(
"TestingAdmin",
"header_test",
IssueListLabelsQuery::default()
),
x_total_count
);
test_header!(
api.issue_get_milestones_list(
"TestingAdmin",
"header_test",
IssueGetMilestonesListQuery::default()
),
x_total_count
);
git.run(&["switch", "-c", "pluey"]);
tokio::fs::write("./test_repos/header_test/pluey.txt", "wahoo")
.await
.unwrap();
git.run(&["add", "."]);
git.run(&["commit", "-m", "\"We implemented pluey\""]);
git.run(&["push"]);
let body = CreatePullRequestOption {
assignee: None,
assignees: None,
base: Some("main".into()),
body: None,
due_date: None,
head: Some("pluey".into()),
labels: None,
milestone: None,
title: Some("pluey".into()),
};
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
let pr = api
.repo_create_pull_request("TestingAdmin", "header_test", body)
.await
.unwrap();
test_header!(
api.repo_get_pull_request_files(
"TestingAdmin",
"header_test",
2,
RepoGetPullRequestFilesQuery::default()
),
x_total_count
);
test_header!(
api.issue_get_comments(
"TestingAdmin",
"header_test",
1,
IssueGetCommentsQuery::default()
),
x_total_count
);
test_header!(
api.repo_get_pull_request_commits(
"TestingAdmin",
"header_test",
2,
RepoGetPullRequestCommitsQuery::default()
),
x_total_count
);
let sha = pr.head.unwrap().sha.unwrap();
test_header!(
api.repo_list_pull_requests(
"TestingAdmin",
"header_test",
RepoListPullRequestsQuery::default()
),
x_total_count
);
let body = CreatePullReviewOptions {
body: Some("woah".into()),
comments: None,
commit_id: None,
event: None,
};
api.repo_create_pull_review("TestingAdmin", "header_test", 2, body)
.await
.unwrap();
test_header!(
api.repo_list_pull_reviews(
"TestingAdmin",
"header_test",
2,
RepoListPullReviewsQuery::default()
),
x_total_count
);
test_header!(
api.issue_get_comments_and_timeline(
"TestingAdmin",
"header_test",
2,
IssueGetCommentsAndTimelineQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_push_mirrors(
"TestingAdmin",
"header_test",
RepoListPushMirrorsQuery::default()
),
x_total_count
);
//tokio::time::sleep(std::time::Duration::from_secs(2)).await;
test_header!(
api.repo_list_branches(
"TestingAdmin",
"header_test",
RepoListBranchesQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_branches(
"TestingAdmin",
"header_test",
RepoListBranchesQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_statuses(
"TestingAdmin",
"header_test",
&sha,
RepoListStatusesQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_keys("TestingAdmin", "header_test", RepoListKeysQuery::default()),
x_total_count
);
test_header!(
api.repo_list_hooks("TestingAdmin", "header_test", RepoListHooksQuery::default()),
x_total_count
);
test_header!(
api.repo_list_releases(
"TestingAdmin",
"header_test",
RepoListReleasesQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_actions_secrets(
"TestingAdmin",
"header_test",
RepoListActionsSecretsQuery::default()
),
x_total_count
);
test_header!(
api.repo_list_tags("TestingAdmin", "header_test", RepoListTagsQuery::default()),
x_total_count
);
test_header!(
api.get_repo_variables_list(
"TestingAdmin",
"header_test",
GetRepoVariablesListQuery::default()
),
x_total_count
);
let body = CreateWikiPageOptions {
content_base64: Some(
"WW91IGRlY29kZWQgdGhpcyB0byBzZWUgd2hhdCBpdCBzYXlzPyBZb3UncmUgcXVpdGUgYSBuZXJk".into(),
),
message: Some("wahoo".into()),
title: Some("Home".into()),
};
api.repo_create_wiki_page("TestingAdmin", "header_test", body)
.await
.unwrap();
test_header!(
api.repo_get_wiki_page_revisions(
"TestingAdmin",
"header_test",
"Home",
RepoGetWikiPageRevisionsQuery::default()
),
x_total_count
);
test_header!(
api.repo_get_wiki_pages(
"TestingAdmin",
"header_test",
RepoGetWikiPagesQuery::default()
),
x_total_count
);
test_header!(
api.admin_cron_list(AdminCronListQuery::default()),
x_total_count
);
//test_header!(api.admin_list_quota_groups(), x_total_count);
//test_header!(api.admin_list_quota_rules(), x_total_count);
//test_header!(api.user_list_quota_artifacts(UserListQuotaArtifactsQuery::default()), x_total_count);
//test_header!(api.user_list_quota_attachments(UserListQuotaAttachmentsQuery::default()), x_total_count);
//test_header!(api.user_list_quota_packages(UserListQuotaPackagesQuery::default()), x_total_count);
let body = CreateOrgOption {
description: None,
email: None,
full_name: None,
location: None,
repo_admin_change_team_access: None,
username: "header-test-org".into(),
visibility: None,
website: None,
};
api.org_create(body).await.unwrap();
test_header!(
api.org_list_teams("header-test-org", OrgListTeamsQuery::default()),
x_total_count
);
test_header!(api.org_get_all(OrgGetAllQuery::default()), x_total_count);
}
#[tokio::test]
async fn has_more() {
let api = common::login_pass("TestingAdmin", "password");
let git = Git::new("./test_repos/header_more_test");
common::basic_repo(&api, &git, "header_more_test").await;
git.run(&["switch", "-c", "pluey"]);
tokio::fs::write("./test_repos/header_more_test/pluey.txt", "wahoo")
.await
.unwrap();
git.run(&["add", "."]);
git.run(&["commit", "-m", "\"We implemented pluey\""]);
git.run(&["push"]);
let body = CreatePullRequestOption {
assignee: None,
assignees: None,
base: Some("main".into()),
body: None,
due_date: None,
head: Some("pluey".into()),
labels: None,
milestone: None,
title: Some("pluey".into()),
};
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
api.repo_create_pull_request("TestingAdmin", "header_more_test", body)
.await
.unwrap();
test_header!(
api.repo_get_pull_request_files(
"TestingAdmin",
"header_more_test",
1,
RepoGetPullRequestFilesQuery::default()
),
x_has_more
);
test_header!(
api.repo_get_pull_request_commits(
"TestingAdmin",
"header_more_test",
1,
RepoGetPullRequestCommitsQuery::default()
),
x_has_more
);
}

View file

@ -2,119 +2,7 @@ use forgejo_api::structs::*;
mod common;
struct Git {
dir: &'static std::path::Path,
}
impl Git {
fn new<T: AsRef<std::path::Path> + ?Sized>(path: &'static T) -> Self {
let dir = path.as_ref();
std::fs::create_dir_all(dir).unwrap();
Self { dir }
}
fn run(&self, args: &[impl AsRef<std::ffi::OsStr>]) {
let mut cmd = std::process::Command::new("git");
cmd.current_dir(self.dir);
let _ = cmd.args(args).status().unwrap();
}
}
async fn setup_local_repo(git: &Git) {
git.run(&["config", "--global", "init.defaultBranch", "main"]);
git.run(&["init"]);
git.run(&["config", "user.name", "TestingAdmin"]);
git.run(&["config", "user.email", "admin@noreply.example.org"]);
tokio::fs::write(&git.dir.join("README.md"), "# Test\nThis is a test repo")
.await
.unwrap();
git.run(&["add", "."]);
git.run(&["commit", "-m", "initial commit"]);
}
async fn basic_repo(api: &forgejo_api::Forgejo, git: &Git, name: &str) -> Repository {
setup_local_repo(git).await;
let repo_opt = CreateRepoOption {
auto_init: Some(false),
default_branch: Some("main".into()),
description: Some("Test Repo".into()),
gitignores: Some("".into()),
issue_labels: Some("".into()),
license: Some("".into()),
name: name.into(),
object_format_name: None,
private: Some(false),
readme: None,
template: Some(false),
trust_model: Some(CreateRepoOptionTrustModel::Default),
};
let remote_repo = api.create_current_user_repo(repo_opt).await.unwrap();
assert!(
remote_repo.has_pull_requests.unwrap(),
"repo does not accept pull requests"
);
assert!(
remote_repo.owner.as_ref().unwrap().login.as_ref().unwrap() == "TestingAdmin",
"repo owner is not \"TestingAdmin\""
);
assert!(
remote_repo.name.as_ref().unwrap() == name,
"repo name is not \"{name}\""
);
let mut remote_url = remote_repo.clone_url.clone().unwrap();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
git.run(&["remote", "add", "origin", remote_url.as_str()]);
git.run(&["push", "-u", "origin", "main"]);
remote_repo
}
async fn basic_org_repo(
api: &forgejo_api::Forgejo,
git: &Git,
org: &str,
name: &str,
) -> Repository {
setup_local_repo(git).await;
let repo_opt = CreateRepoOption {
auto_init: Some(false),
default_branch: Some("main".into()),
description: Some("Test Repo".into()),
gitignores: Some("".into()),
issue_labels: Some("".into()),
license: Some("".into()),
name: name.into(),
object_format_name: None,
private: Some(false),
readme: None,
template: Some(false),
trust_model: Some(CreateRepoOptionTrustModel::Default),
};
let remote_repo = api.create_org_repo(org, repo_opt).await.unwrap();
assert!(
remote_repo.has_pull_requests.unwrap(),
"repo does not accept pull requests"
);
assert!(
remote_repo.owner.as_ref().unwrap().login.as_ref().unwrap() == org,
"repo owner is not \"TestingAdmin\""
);
assert!(
remote_repo.name.as_ref().unwrap() == name,
"repo name is not \"{name}\""
);
let mut remote_url = remote_repo.clone_url.clone().unwrap();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
git.run(&["remote", "add", "origin", remote_url.as_str()]);
git.run(&["push", "-u", "origin", "main"]);
remote_repo
}
use common::{basic_org_repo, basic_repo, Git};
#[tokio::test]
async fn pull_request() {
@ -401,7 +289,7 @@ async fn tag_protection() {
let git = Git::new("./test_repos/tag-protect");
let _ = basic_repo(&api, &git, "tag-protect").await;
let (_, tag_protections) = api
let tag_protections = api
.repo_list_tag_protection("TestingAdmin", "tag-protect")
.await
.expect("failed to list tag protections");