From fd3d10af891f6ab3d75631b4c3126e666e192d32 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Sat, 26 Aug 2023 11:57:52 +0200 Subject: [PATCH] feat: add small program to check for missing type definitions --- Cargo.lock | 30 +++--- Cargo.toml | 2 +- README.md | 2 +- src/bin/all_models.txt | 181 +++++++++++++++++++++++++++++++++++++ src/bin/checker.rs | 48 ++++++++++ src/bin/missing_models.txt | 27 ++++++ 6 files changed, 273 insertions(+), 17 deletions(-) create mode 100644 src/bin/all_models.txt create mode 100644 src/bin/checker.rs create mode 100644 src/bin/missing_models.txt diff --git a/Cargo.lock b/Cargo.lock index 91d317a..3615002 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] @@ -487,7 +487,7 @@ checksum = "3c02bfa6b3ba8af5434fa0531bf5701f750d983d4260acd6867faca51cdc4484" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] @@ -526,7 +526,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] @@ -603,18 +603,18 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "serde" -version = "1.0.175" +version = "1.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d25439cd7397d044e2748a6fe2432b5e85db703d6d097bd014b3c0ad1ebff0b" +checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1" dependencies = [ "serde_derive", ] [[package]] name = "serde-email" -version = "2.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d888a6d080f7abd2527a60468943a4ca4bf719ffaca33d5d689728896a740db5" +checksum = "b8f07d6907a91e7d43c1a2f2698a81a1cf025d89daed97fe211b3d25e8cef109" dependencies = [ "email_address", "serde", @@ -622,13 +622,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.175" +version = "1.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b23f7ade6f110613c0d63858ddb8b94c1041f550eab58a16b371bdf2c9c80ab4" +checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] @@ -676,7 +676,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] @@ -692,9 +692,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.27" +version = "2.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" dependencies = [ "proc-macro2", "quote", @@ -877,7 +877,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", "wasm-bindgen-shared", ] @@ -899,7 +899,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index d328d6c..54ddc1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,6 @@ derive-new = "0.5" hyper = "0.14.27" palette = { version = "0.7.2", features = ["serializing"] } serde = { version = "1.0", features = ["derive"] } -serde-email = "2.1" +serde-email = "3.0" strum = { version = "0.25", features = ["derive"] } url = { version = "2.4", features = ["serde"] } diff --git a/README.md b/README.md index 603d39d..502bf68 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ ![Progress](./progress.png) -docs: https://codeberg.org/api/swagger#/organization/orgCreateHook +docs: https://codeberg.org/api/swagger diff --git a/src/bin/all_models.txt b/src/bin/all_models.txt new file mode 100644 index 0000000..6f315a5 --- /dev/null +++ b/src/bin/all_models.txt @@ -0,0 +1,181 @@ +Don't delete this line! Copy all names under "models" from https://codeberg.org/api/swagger below this line +APIError +AccessToken represents an API access token. +Activity +ActivityPub +AddCollaboratorOption +AddTimeOption +AnnotatedTag +AnnotatedTagObject +Attachment +BlockedUser represents a blocked user. +Branch +BranchProtection +ChangeFileOperation +ChangeFilesOptions +ChangedFile +CombinedStatus +Comment +Commit contains information generated from a Git commit. +CommitAffectedFiles +CommitDateOptions +CommitMeta contains meta information of a commit in terms of API. +CommitStats +CommitStatus +CommitStatusState +CommitUser contains information of a user in the context of a commit. +ContentsResponse +CreateAccessTokenOption +CreateBranchProtectionOption +CreateBranchRepoOption +CreateEmailOption +CreateFileOptions +CreateForkOption +CreateGPGKeyOption +CreateHookOption +CreateHookOptionConfig +CreateIssueCommentOption +CreateIssueOption +CreateKeyOption +CreateLabelOption +CreateMilestoneOption +CreateOAuth2ApplicationOptions +CreateOrgOption +CreatePullRequestOption +CreatePullReviewComment +CreatePullReviewOptions +CreatePushMirrorOption represents need information to create a push mirror of a repository. +CreateReleaseOption +CreateRepoOption +CreateStatusOption +CreateTagOption +CreateTeamOption +CreateUserOption +CreateWikiPageOptions +Cron +DeleteEmailOption +DeleteFileOptions +DeployKey +DismissPullReviewOptions +EditAttachmentOptions +EditBranchProtectionOption +EditDeadlineOption +EditGitHookOption +EditHookOption +EditIssueCommentOption +EditIssueOption +EditLabelOption +EditMilestoneOption +EditOrgOption +EditPullRequestOption +EditReactionOption +EditReleaseOption +EditRepoOption +EditTeamOption +EditUserOption +Email +ExternalTracker +ExternalWiki +FileCommitResponse contains information generated from a Git commit for a repo's file. +FileDeleteResponse +FileLinksResponse +FileResponse +FilesResponse +GPGKey +GPGKeyEmail +GeneralAPISettings +GeneralAttachmentSettings +GeneralRepoSettings +GeneralUISettings +GenerateRepoOption +GitBlobResponse +GitEntry +GitHook +GitObject represents a Git object. +GitTreeResponse +GitignoreTemplateInfo +Hook +Identity +InternalTracker +Issue +IssueConfig +IssueConfigContactLink +IssueConfigValidation +IssueDeadline +IssueFormField +IssueFormFieldType defines issue form field type, can be "markdown", "textarea", "input", "dropdown" or "checkboxes" +IssueLabelsOption +IssueMeta +IssueTemplate +IssueTemplateLabels +Label +LabelTemplate +LicenseTemplateInfo +LicensesTemplateListEntry +MarkdownOption +MarkupOption +MergePullRequestOption +MigrateRepoOptions +Milestone +NewIssuePinsAllowed +NodeInfo +NodeInfoServices +NodeInfoSoftware +NodeInfoUsage +NodeInfoUsageUsers +Note +NotificationCount +NotificationSubject +NotificationThread +NotifySubjectType +OAuth2Application represents an OAuth2 application. +Organization +OrganizationPermissions +PRBranchInfo +Package +PackageFile +PayloadCommit +PayloadCommitVerification +PayloadUser +Permission +PublicKey +PullRequest +PullRequestMeta +PullReview +PullReviewComment +PullReviewRequestOptions +PushMirror +Reaction +Reference represents a Git reference. +Release +RenameUserOption +RepoCollaboratorPermission +RepoCommit contains information of a commit in the context of a repository. +RepoTopicOptions +RepoTransfer +Repository +RepositoryMeta +ReviewStateType +SearchResults +ServerVersion +StateType +StopWatch +SubmitPullReviewOptions +Tag +Team +TimeStamp +TimelineComment +TopicName +TopicResponse +TrackedTime +TransferRepoOption +UpdateFileOptions +User +UserHeatmapData +UserSettings +UserSettingsOptions +WatchInfo +WikiCommit +WikiCommitList +WikiPage +WikiPageMetaData diff --git a/src/bin/checker.rs b/src/bin/checker.rs new file mode 100644 index 0000000..c219e5f --- /dev/null +++ b/src/bin/checker.rs @@ -0,0 +1,48 @@ +use std::process::Command; + +fn main() -> Result<(), impl std::error::Error> { + println!(" + This program checks wether there are type definitions missing in the crate. + + Please: + + - provide a list of all model names in the all_models.txt file. You can find all models here: + https://codeberg.org/api/swagger + - make sure to run the program in the repo root directory + + The results should be located in a file src/bin/missing_models.txt after the program exited successfully. + "); + + let file = std::fs::read_to_string("src/bin/all_models.txt")?; + + _ = std::fs::remove_file("src/bin/missing_models.txt"); + + let not_found = file + .lines() + .skip(1) + .filter(|l| { + // checks if todo for this type was added + let output1 = exec_rg(&[format!("//.*{l}").as_str(), "-n"]).unwrap_or_default(); + // checks if actual rust type exists already + let output2 = exec_rg(&[format!("struct {l}").as_str(), "-n"]).unwrap_or_default(); + + !(output1.lines().any(|cmd1out| cmd1out.contains(":1:")) + || output2.lines().any(|cmd2out| cmd2out.contains(l))) + }) + .map(String::from) + .reduce(|a, b| a + "\n" + &b) + .unwrap_or_default(); + + std::fs::write("src/bin/missing_models.txt", not_found)?; + + Ok::<(), std::io::Error>(()) +} + +fn exec_rg(args: &[&str]) -> Option { + Command::new("rg") + .args(args) + .output() + .ok() + .filter(|o| o.status.success()) + .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) +} diff --git a/src/bin/missing_models.txt b/src/bin/missing_models.txt new file mode 100644 index 0000000..a6cb2ef --- /dev/null +++ b/src/bin/missing_models.txt @@ -0,0 +1,27 @@ +FilesResponse +GitignoreTemplateInfo +IssueConfig +IssueConfigContactLink +IssueConfigValidation +IssueDeadline +IssueMeta +LabelTemplate +LicenseTemplateInfo +LicensesTemplateListEntry +MarkdownOption +MarkupOption +NewIssuePinsAllowed +NodeInfo +NodeInfoServices +NodeInfoSoftware +NodeInfoUsage +NodeInfoUsageUsers +NotificationCount +NotificationSubject +NotificationThread +NotifySubjectType +RenameUserOption +ServerVersion +TimeStamp +TopicResponse +WikiPageMetaData \ No newline at end of file