summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@noreply.codeberg.org>2024-04-26 19:25:13 +0200
committerCyborus <cyborus@noreply.codeberg.org>2024-04-26 19:25:13 +0200
commit1d321c66e36d43a1bef285a79a81b599f4ae8a2f (patch)
treea4596400fd3f12005353ebb28cf831131c8739ec
parentMerge pull request 'fix `repo_get_raw_file{_or_lfs}` not returning `Vec<u8>`'... (diff)
parentimplement `From<DefaultMergeStyle>` for `MergePullRequestOptionDo` (diff)
downloadforgejo-api-1d321c66e36d43a1bef285a79a81b599f4ae8a2f.tar.xz
forgejo-api-1d321c66e36d43a1bef285a79a81b599f4ae8a2f.zip
Merge pull request 'strongly type repository default merge style' (#48) from enum-repo-merge-style into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-api/pulls/48
-rw-r--r--generator/src/main.rs11
-rw-r--r--src/generated/structs.rs18
-rw-r--r--src/lib.rs16
-rw-r--r--swagger.v1.json17
4 files changed, 53 insertions, 9 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs
index 64173bf..5d9d2c7 100644
--- a/generator/src/main.rs
+++ b/generator/src/main.rs
@@ -72,12 +72,21 @@ fn schema_type_name(
match ty {
SchemaType::One(prim) => {
let name = match prim {
- Primitive::String => match schema.format.as_deref() {
+ Primitive::String if schema._enum.is_none() => match schema.format.as_deref() {
Some("date") => "time::Date",
Some("date-time") => "time::OffsetDateTime",
_ => "String",
}
.to_string(),
+ Primitive::String => {
+ match (&schema.title, definition_name) {
+ // Some of the titles are actually descriptions; not sure why
+ // Checking for a space filters that out
+ (Some(title), _) if !title.contains(' ') => title.to_string(),
+ (_, Some(definition_name)) => definition_name.to_string(),
+ (_, None) => "String".to_string(),
+ }
+ }
Primitive::Number => match schema.format.as_deref() {
Some("float") => "f32",
Some("double") => "f64",
diff --git a/src/generated/structs.rs b/src/generated/structs.rs
index a4d920c..bcb8682 100644
--- a/src/generated/structs.rs
+++ b/src/generated/structs.rs
@@ -793,6 +793,19 @@ pub struct Cron {
pub schedule: Option<String>,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+pub enum DefaultMergeStyle {
+ #[serde(rename = "merge")]
+ Merge,
+ #[serde(rename = "rebase")]
+ Rebase,
+ #[serde(rename = "rebase-merge")]
+ RebaseMerge,
+ #[serde(rename = "squash")]
+ Squash,
+ #[serde(rename = "fast-forward-only")]
+ FastForwardOnly,
+}
/// DeleteEmailOption options when deleting email addresses
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DeleteEmailOption {
@@ -1039,8 +1052,7 @@ pub struct EditRepoOption {
pub default_branch: Option<String>,
/// set to `true` to delete pr branch after merge by default
pub default_delete_branch_after_merge: Option<bool>,
- /// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", or "fast-forward-only".
- pub default_merge_style: Option<String>,
+ pub default_merge_style: Option<DefaultMergeStyle>,
/// a short description of the repository.
pub description: Option<String>,
/// enable prune - remove obsolete remote-tracking references
@@ -2212,7 +2224,7 @@ pub struct Repository {
pub default_allow_maintainer_edit: Option<bool>,
pub default_branch: Option<String>,
pub default_delete_branch_after_merge: Option<bool>,
- pub default_merge_style: Option<String>,
+ pub default_merge_style: Option<DefaultMergeStyle>,
pub description: Option<String>,
pub empty: Option<bool>,
pub external_tracker: Option<ExternalTracker>,
diff --git a/src/lib.rs b/src/lib.rs
index 3a53fcb..90d1137 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -253,3 +253,19 @@ fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(
deserializer.deserialize_str(EmptyUrlVisitor)
}
+
+impl From<structs::DefaultMergeStyle> for structs::MergePullRequestOptionDo {
+ fn from(value: structs::DefaultMergeStyle) -> Self {
+ match value {
+ structs::DefaultMergeStyle::Merge => structs::MergePullRequestOptionDo::Merge,
+ structs::DefaultMergeStyle::Rebase => structs::MergePullRequestOptionDo::Rebase,
+ structs::DefaultMergeStyle::RebaseMerge => {
+ structs::MergePullRequestOptionDo::RebaseMerge
+ }
+ structs::DefaultMergeStyle::Squash => structs::MergePullRequestOptionDo::Squash,
+ structs::DefaultMergeStyle::FastForwardOnly => {
+ structs::MergePullRequestOptionDo::FastForwardOnly
+ }
+ }
+ }
+}
diff --git a/swagger.v1.json b/swagger.v1.json
index 274063a..299afd3 100644
--- a/swagger.v1.json
+++ b/swagger.v1.json
@@ -17622,6 +17622,16 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
+ "DefaultMergeStyle": {
+ "type": "string",
+ "enum": [
+ "merge",
+ "rebase",
+ "rebase-merge",
+ "squash",
+ "fast-forward-only"
+ ]
+ },
"DeleteEmailOption": {
"description": "DeleteEmailOption options when deleting email addresses",
"type": "object",
@@ -18269,9 +18279,7 @@
"x-go-name": "DefaultDeleteBranchAfterMerge"
},
"default_merge_style": {
- "description": "set to a merge style to be used by this repository: \"merge\", \"rebase\", \"rebase-merge\", \"squash\", or \"fast-forward-only\".",
- "type": "string",
- "x-go-name": "DefaultMergeStyle"
+ "$ref": "#/definitions/DefaultMergeStyle"
},
"description": {
"description": "a short description of the repository.",
@@ -21151,8 +21159,7 @@
"x-go-name": "DefaultDeleteBranchAfterMerge"
},
"default_merge_style": {
- "type": "string",
- "x-go-name": "DefaultMergeStyle"
+ "$ref": "#/definitions/DefaultMergeStyle"
},
"description": {
"type": "string",