fix: null team reviews
This commit is contained in:
parent
e6339d7c4f
commit
03c2ff9a17
|
@ -1079,6 +1079,9 @@ pub struct Schema {
|
||||||
pub xml: Option<Xml>,
|
pub xml: Option<Xml>,
|
||||||
pub external_docs: Option<ExternalDocs>,
|
pub external_docs: Option<ExternalDocs>,
|
||||||
pub example: Option<serde_json::Value>,
|
pub example: Option<serde_json::Value>,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub extensions: BTreeMap<String, serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JsonDeref for Schema {
|
impl JsonDeref for Schema {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::openapi::*;
|
use crate::openapi::*;
|
||||||
use eyre::WrapErr;
|
use eyre::WrapErr;
|
||||||
use heck::ToPascalCase;
|
use heck::ToPascalCase;
|
||||||
use std::fmt::Write;
|
use std::{collections::BTreeMap, fmt::Write};
|
||||||
|
|
||||||
pub fn create_structs(spec: &OpenApiV2) -> eyre::Result<String> {
|
pub fn create_structs(spec: &OpenApiV2) -> eyre::Result<String> {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
|
@ -51,6 +51,13 @@ pub fn create_struct_for_definition(
|
||||||
|
|
||||||
let mut subtypes = Vec::new();
|
let mut subtypes = Vec::new();
|
||||||
|
|
||||||
|
let parse_with = schema
|
||||||
|
.extensions
|
||||||
|
.get("x-parse-with")
|
||||||
|
.map(|ex| serde_json::from_value::<BTreeMap<String, String>>(ex.clone()))
|
||||||
|
.transpose()?
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let docs = create_struct_docs(schema)?;
|
let docs = create_struct_docs(schema)?;
|
||||||
let mut fields = String::new();
|
let mut fields = String::new();
|
||||||
let required = schema.required.as_deref().unwrap_or_default();
|
let required = schema.required.as_deref().unwrap_or_default();
|
||||||
|
@ -90,6 +97,11 @@ pub fn create_struct_for_definition(
|
||||||
if field_ty == "Option<time::OffsetDateTime>" {
|
if field_ty == "Option<time::OffsetDateTime>" {
|
||||||
fields.push_str("#[serde(with = \"time::serde::rfc3339::option\")]\n");
|
fields.push_str("#[serde(with = \"time::serde::rfc3339::option\")]\n");
|
||||||
}
|
}
|
||||||
|
if let Some(parse_method) = parse_with.get(prop_name) {
|
||||||
|
fields.push_str("#[serde(deserialize_with = \"crate::");
|
||||||
|
fields.push_str(parse_method);
|
||||||
|
fields.push_str("\")]\n");
|
||||||
|
}
|
||||||
if let MaybeRef::Value { value } = &prop_schema {
|
if let MaybeRef::Value { value } = &prop_schema {
|
||||||
if let Some(desc) = &value.description {
|
if let Some(desc) = &value.description {
|
||||||
for line in desc.lines() {
|
for line in desc.lines() {
|
||||||
|
|
|
@ -2034,6 +2034,7 @@ pub struct PullRequest {
|
||||||
#[serde(deserialize_with = "crate::none_if_blank_url")]
|
#[serde(deserialize_with = "crate::none_if_blank_url")]
|
||||||
pub patch_url: Option<url::Url>,
|
pub patch_url: Option<url::Url>,
|
||||||
pub pin_order: Option<u64>,
|
pub pin_order: Option<u64>,
|
||||||
|
#[serde(deserialize_with = "crate::requested_reviewers_ignore_null")]
|
||||||
pub requested_reviewers: Option<Vec<User>>,
|
pub requested_reviewers: Option<Vec<User>>,
|
||||||
pub state: Option<StateType>,
|
pub state: Option<StateType>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -358,6 +358,18 @@ where
|
||||||
.or(Ok(None))
|
.or(Ok(None))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn requested_reviewers_ignore_null<'de, D, DE>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> Result<Option<Vec<structs::User>>, DE>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
DE: serde::de::Error,
|
||||||
|
{
|
||||||
|
let list: Option<Vec<Option<structs::User>>> =
|
||||||
|
Option::deserialize(deserializer).map_err(DE::custom)?;
|
||||||
|
Ok(list.map(|list| list.into_iter().filter_map(|x| x).collect::<Vec<_>>()))
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_ssh_url(raw_url: &String) -> Result<Url, url::ParseError> {
|
fn parse_ssh_url(raw_url: &String) -> Result<Url, url::ParseError> {
|
||||||
// in case of a non-standard ssh-port (not 22), the ssh url coming from the forgejo API
|
// in case of a non-standard ssh-port (not 22), the ssh url coming from the forgejo API
|
||||||
// is actually parseable by the url crate, so try to do that first
|
// is actually parseable by the url crate, so try to do that first
|
||||||
|
|
|
@ -20667,7 +20667,10 @@
|
||||||
"$ref": "#/definitions/User"
|
"$ref": "#/definitions/User"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs",
|
||||||
|
"x-parse-with": {
|
||||||
|
"requested_reviewers": "requested_reviewers_ignore_null"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"PullRequestMeta": {
|
"PullRequestMeta": {
|
||||||
"description": "PullRequestMeta PR info if an issue is a PR",
|
"description": "PullRequestMeta PR info if an issue is a PR",
|
||||||
|
|
113
tests/repo.rs
113
tests/repo.rs
|
@ -20,7 +20,7 @@ impl Git {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn basic_repo(api: &forgejo_api::Forgejo, git: &Git, name: &str) -> Repository {
|
async fn setup_local_repo(git: &Git) {
|
||||||
git.run(&["config", "--global", "init.defaultBranch", "main"]);
|
git.run(&["config", "--global", "init.defaultBranch", "main"]);
|
||||||
git.run(&["init"]);
|
git.run(&["init"]);
|
||||||
git.run(&["config", "user.name", "TestingAdmin"]);
|
git.run(&["config", "user.name", "TestingAdmin"]);
|
||||||
|
@ -30,7 +30,10 @@ async fn basic_repo(api: &forgejo_api::Forgejo, git: &Git, name: &str) -> Reposi
|
||||||
.unwrap();
|
.unwrap();
|
||||||
git.run(&["add", "."]);
|
git.run(&["add", "."]);
|
||||||
git.run(&["commit", "-m", "initial commit"]);
|
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 {
|
let repo_opt = CreateRepoOption {
|
||||||
auto_init: Some(false),
|
auto_init: Some(false),
|
||||||
default_branch: Some("main".into()),
|
default_branch: Some("main".into()),
|
||||||
|
@ -68,6 +71,51 @@ async fn basic_repo(api: &forgejo_api::Forgejo, git: &Git, name: &str) -> Reposi
|
||||||
remote_repo
|
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
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pull_request() {
|
async fn pull_request() {
|
||||||
let api = common::login();
|
let api = common::login();
|
||||||
|
@ -274,3 +322,66 @@ async fn delete_repo() {
|
||||||
.await
|
.await
|
||||||
.expect("failed to delete repo");
|
.expect("failed to delete repo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn team_pr_review_request() {
|
||||||
|
let api = common::login();
|
||||||
|
|
||||||
|
let org_opt = CreateOrgOption {
|
||||||
|
description: Some("Testing team review requests".into()),
|
||||||
|
email: None,
|
||||||
|
full_name: None,
|
||||||
|
location: None,
|
||||||
|
repo_admin_change_team_access: None,
|
||||||
|
username: "team-review-org".into(),
|
||||||
|
visibility: None,
|
||||||
|
website: None,
|
||||||
|
};
|
||||||
|
api.org_create(org_opt).await.unwrap();
|
||||||
|
|
||||||
|
let git = Git::new("./test_repos/team-pr-review");
|
||||||
|
let _ = basic_org_repo(&api, &git, "team-review-org", "team-pr-review").await;
|
||||||
|
|
||||||
|
git.run(&["switch", "-c", "test"]);
|
||||||
|
tokio::fs::write(
|
||||||
|
"./test_repos/team-pr-review/example.rs",
|
||||||
|
"fn add_one(x: u32) -> u32 { x + 1 }",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
git.run(&["add", "."]);
|
||||||
|
git.run(&["commit", "-m", "egg"]);
|
||||||
|
git.run(&["push", "-u", "origin", "test"]);
|
||||||
|
|
||||||
|
let pr_opt = CreatePullRequestOption {
|
||||||
|
assignee: None,
|
||||||
|
assignees: Some(vec!["TestingAdmin".into()]),
|
||||||
|
base: Some("main".into()),
|
||||||
|
body: Some("This is a test PR".into()),
|
||||||
|
due_date: None,
|
||||||
|
head: Some("test".into()),
|
||||||
|
labels: None,
|
||||||
|
milestone: None,
|
||||||
|
title: Some("test pr".into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Wait for... something to happen, or else creating a PR will return 404
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
|
||||||
|
api.repo_create_pull_request("team-review-org", "team-pr-review", pr_opt)
|
||||||
|
.await
|
||||||
|
.expect("couldn't create pr");
|
||||||
|
|
||||||
|
let review_opt = PullReviewRequestOptions {
|
||||||
|
reviewers: None,
|
||||||
|
team_reviewers: Some(vec!["Owners".into()]),
|
||||||
|
};
|
||||||
|
api.repo_create_pull_review_requests("team-review-org", "team-pr-review", 1, review_opt)
|
||||||
|
.await
|
||||||
|
.expect("couldn't request review");
|
||||||
|
|
||||||
|
let pr = api
|
||||||
|
.repo_get_pull_request("team-review-org", "team-pr-review", 1)
|
||||||
|
.await
|
||||||
|
.expect("couldn't get pr");
|
||||||
|
assert_eq!(pr.requested_reviewers, Some(Vec::new()));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue