fix commit

This commit is contained in:
Kasper Juul Hermansen 2022-11-27 01:56:07 +01:00
parent 9f2bc08429
commit 4345f9c39b
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
26 changed files with 2441 additions and 68 deletions

35
Cargo.lock generated
View File

@ -230,6 +230,27 @@ dependencies = [
"url",
]
[[package]]
name = "gitea_client"
version = "0.1.0"
dependencies = [
"async-trait",
"gitea_raw_client",
"reqwest",
]
[[package]]
name = "gitea_raw_client"
version = "1.17.3"
dependencies = [
"reqwest",
"serde",
"serde_derive",
"serde_json",
"url",
"uuid",
]
[[package]]
name = "h2"
version = "0.3.15"
@ -588,6 +609,7 @@ dependencies = [
"async-trait",
"eyre",
"git2",
"gitea_client",
"hex",
"rand",
"serde",
@ -602,6 +624,7 @@ version = "0.1.0"
dependencies = [
"eyre",
"octopush_core",
"tracing",
]
[[package]]
@ -610,18 +633,6 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "openapi"
version = "1.17.3"
dependencies = [
"reqwest",
"serde",
"serde_derive",
"serde_json",
"url",
"uuid",
]
[[package]]
name = "openssl"
version = "0.10.43"

View File

@ -11,6 +11,7 @@ members = [
"crates/octopush_infra",
"crates/octopush_core",
"crates/gitea_raw_client",
"crates/gitea_client",
]
[workspace.dependencies]

Binary file not shown.

View File

@ -1,6 +1,10 @@
package main
import "github.com/bitfield/script"
import (
"os"
"github.com/bitfield/script"
)
func main() {
_, err := script.
@ -10,4 +14,25 @@ func main() {
if err != nil {
panic(err)
}
println("ran stuff")
entries, err := os.ReadDir(".")
if err != nil {
panic(err)
}
for _, entry := range entries {
if !entry.IsDir() {
file, err := os.ReadFile(entry.Name())
if err != nil {
panic(err)
}
println(string(file))
}
}
wd, err := os.Getwd()
if err != nil {
panic(err)
}
println(wd)
}

View File

@ -1,19 +1,19 @@
apiVersion: action
name: write-a-readme
select:
github:
repositories:
- kjuulh/octopush-test
push:
pull-request:
name: "write a readme"
# github:
# repositories:
# - kjuulh/octopush-test
# push:
# pull-request:
# name: "write a readme"
gitea:
repositories:
- kjuulh/octopush-test
push:
pull-request:
name: "write a readme"
# gitea:
# repositories:
# - kjuulh/octopush-test
# push:
# pull-request:
# name: "write a readme"
git:
repositories:

View File

@ -0,0 +1,13 @@
[package]
name = "gitea_client"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gitea_raw_client = { path = "../gitea_raw_client" }
async-trait = { workspace = true }
reqwest = "0.11.13"

View File

@ -0,0 +1 @@
pub mod repository;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
pub mod defaults;
pub mod repository;

View File

@ -0,0 +1,841 @@
use std::sync::Arc;
use async_trait::async_trait;
use gitea_raw_client::{apis::Error, models};
pub use gitea_raw_client::apis::repository_api::*;
#[async_trait]
pub trait Repository {
async fn accept_transfer(
&self,
owner: &str,
repo: &str,
) -> Result<models::Repository, Error<AcceptRepoTransferError>>;
async fn create_current_user_repo(
&self,
body: Option<models::CreateRepoOption>,
) -> Result<models::Repository, Error<CreateCurrentUserRepoError>>;
async fn create_fork(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateForkOption>,
) -> Result<models::Repository, Error<CreateForkError>>;
async fn generate_repo(
&self,
template_owner: &str,
template_repo: &str,
body: Option<models::GenerateRepoOption>,
) -> Result<models::Repository, Error<GenerateRepoError>>;
async fn get_annotated_tag(
&self,
owner: &str,
repo: &str,
sha: &str,
) -> Result<models::AnnotatedTag, Error<GetAnnotatedTagError>>;
async fn get_blob(
&self,
owner: &str,
repo: &str,
sha: &str,
) -> Result<models::GitBlobResponse, Error<GetBlobError>>;
async fn get_tree(
&self,
owner: &str,
repo: &str,
sha: &str,
recursive: Option<bool>,
page: Option<i32>,
per_page: Option<i32>,
) -> Result<models::GitTreeResponse, Error<GetTreeError>>;
async fn list_forks(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Repository>, Error<ListForksError>>;
async fn reject_transfer(
&self,
owner: &str,
repo: &str,
) -> Result<models::Repository, Error<RejectRepoTransferError>>;
async fn add_collaborator(
&self,
owner: &str,
repo: &str,
collaborator: &str,
body: Option<models::AddCollaboratorOption>,
) -> Result<(), Error<RepoAddCollaboratorError>>;
async fn add_team(
&self,
owner: &str,
repo: &str,
team: &str,
) -> Result<(), Error<RepoAddTeamError>>;
async fn add_topic(
&self,
owner: &str,
repo: &str,
topic: &str,
) -> Result<(), Error<RepoAddTopicError>>;
async fn apply_diff_patch(
&self,
owner: &str,
repo: &str,
body: models::UpdateFileOptions,
) -> Result<models::FileResponse, Error<RepoApplyDiffPatchError>>;
async fn cancel_scheduled_auto_merge(
&self,
owner: &str,
repo: &str,
index: i64,
) -> Result<(), Error<RepoCancelScheduledAutoMergeError>>;
async fn check_collaborator(
&self,
owner: &str,
repo: &str,
collaborator: &str,
) -> Result<(), Error<RepoCheckCollaboratorError>>;
async fn check_team(
&self,
owner: &str,
repo: &str,
team: &str,
) -> Result<models::Team, Error<RepoCheckTeamError>>;
async fn create_branch(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateBranchRepoOption>,
) -> Result<models::Branch, Error<RepoCreateBranchError>>;
async fn create_branch_protection(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateBranchProtectionOption>,
) -> Result<models::BranchProtection, Error<RepoCreateBranchProtectionError>>;
async fn create_file(
&self,
owner: &str,
repo: &str,
filepath: &str,
body: models::CreateFileOptions,
) -> Result<models::FileResponse, Error<RepoCreateFileError>>;
async fn create_hook(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateHookOption>,
) -> Result<models::Hook, Error<RepoCreateHookError>>;
async fn create_key(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateKeyOption>,
) -> Result<models::DeployKey, Error<RepoCreateKeyError>>;
async fn create_pull_request(
&self,
owner: &str,
repo: &str,
body: Option<models::CreatePullRequestOption>,
) -> Result<models::PullRequest, Error<RepoCreatePullRequestError>>;
async fn create_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
body: models::CreatePullReviewOptions,
) -> Result<models::PullReview, Error<RepoCreatePullReviewError>>;
async fn create_pull_review_requests(
&self,
owner: &str,
repo: &str,
index: i64,
body: models::PullReviewRequestOptions,
) -> Result<Vec<models::PullReview>, Error<RepoCreatePullReviewRequestsError>>;
async fn create_release(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateReleaseOption>,
) -> Result<models::Release, Error<RepoCreateReleaseError>>;
async fn create_release_attachment(
&self,
owner: &str,
repo: &str,
id: i64,
attachment: std::path::PathBuf,
name: Option<&str>,
) -> Result<models::Attachment, Error<RepoCreateReleaseAttachmentError>>;
async fn create_status(
&self,
owner: &str,
repo: &str,
sha: &str,
body: Option<models::CreateStatusOption>,
) -> Result<models::CommitStatus, Error<RepoCreateStatusError>>;
async fn create_tag(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateTagOption>,
) -> Result<models::Tag, Error<RepoCreateTagError>>;
async fn create_wiki_page(
&self,
owner: &str,
repo: &str,
body: Option<models::CreateWikiPageOptions>,
) -> Result<models::WikiPage, Error<RepoCreateWikiPageError>>;
async fn delete(&self, owner: &str, repo: &str) -> Result<(), Error<RepoDeleteError>>;
async fn delete_branch(
&self,
owner: &str,
repo: &str,
branch: &str,
) -> Result<(), Error<RepoDeleteBranchError>>;
async fn delete_branch_protection(
&self,
owner: &str,
repo: &str,
name: &str,
) -> Result<(), Error<RepoDeleteBranchProtectionError>>;
async fn delete_collaborator(
&self,
owner: &str,
repo: &str,
collaborator: &str,
) -> Result<(), Error<RepoDeleteCollaboratorError>>;
async fn delete_file(
&self,
owner: &str,
repo: &str,
filepath: &str,
body: models::DeleteFileOptions,
) -> Result<models::FileDeleteResponse, Error<RepoDeleteFileError>>;
async fn delete_git_hook(
&self,
owner: &str,
repo: &str,
id: &str,
) -> Result<(), Error<RepoDeleteGitHookError>>;
async fn delete_hook(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<(), Error<RepoDeleteHookError>>;
async fn delete_key(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<(), Error<RepoDeleteKeyError>>;
async fn delete_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
) -> Result<(), Error<RepoDeletePullReviewError>>;
async fn delete_pull_review_requests(
&self,
owner: &str,
repo: &str,
index: i64,
body: models::PullReviewRequestOptions,
) -> Result<(), Error<RepoDeletePullReviewRequestsError>>;
async fn delete_release(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<(), Error<RepoDeleteReleaseError>>;
async fn delete_release_attachment(
&self,
owner: &str,
repo: &str,
id: i64,
attachment_id: i64,
) -> Result<(), Error<RepoDeleteReleaseAttachmentError>>;
async fn delete_release_by_tag(
&self,
owner: &str,
repo: &str,
tag: &str,
) -> Result<(), Error<RepoDeleteReleaseByTagError>>;
async fn delete_tag(
&self,
owner: &str,
repo: &str,
tag: &str,
) -> Result<(), Error<RepoDeleteTagError>>;
async fn delete_team(
&self,
owner: &str,
repo: &str,
team: &str,
) -> Result<(), Error<RepoDeleteTeamError>>;
async fn delete_topic(
&self,
owner: &str,
repo: &str,
topic: &str,
) -> Result<(), Error<RepoDeleteTopicError>>;
async fn delete_wiki_page(
&self,
owner: &str,
repo: &str,
page_name: &str,
) -> Result<(), Error<RepoDeleteWikiPageError>>;
async fn dismiss_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
body: models::DismissPullReviewOptions,
) -> Result<models::PullReview, Error<RepoDismissPullReviewError>>;
async fn download_commit_diff_or_patch(
&self,
owner: &str,
repo: &str,
sha: &str,
diff_type: &str,
) -> Result<String, Error<RepoDownloadCommitDiffOrPatchError>>;
async fn download_pull_diff_or_patch(
&self,
owner: &str,
repo: &str,
index: i64,
diff_type: &str,
binary: Option<bool>,
) -> Result<String, Error<RepoDownloadPullDiffOrPatchError>>;
async fn edit(
&self,
owner: &str,
repo: &str,
body: Option<models::EditRepoOption>,
) -> Result<models::Repository, Error<RepoEditError>>;
async fn edit_branch_protection(
&self,
owner: &str,
repo: &str,
name: &str,
body: Option<models::EditBranchProtectionOption>,
) -> Result<models::BranchProtection, Error<RepoEditBranchProtectionError>>;
async fn edit_git_hook(
&self,
owner: &str,
repo: &str,
id: &str,
body: Option<models::EditGitHookOption>,
) -> Result<models::GitHook, Error<RepoEditGitHookError>>;
async fn edit_hook(
&self,
owner: &str,
repo: &str,
id: i64,
body: Option<models::EditHookOption>,
) -> Result<models::Hook, Error<RepoEditHookError>>;
async fn edit_pull_request(
&self,
owner: &str,
repo: &str,
index: i64,
body: Option<models::EditPullRequestOption>,
) -> Result<models::PullRequest, Error<RepoEditPullRequestError>>;
async fn edit_release(
&self,
owner: &str,
repo: &str,
id: i64,
body: Option<models::EditReleaseOption>,
) -> Result<models::Release, Error<RepoEditReleaseError>>;
async fn edit_release_attachment(
&self,
owner: &str,
repo: &str,
id: i64,
attachment_id: i64,
body: Option<models::EditAttachmentOptions>,
) -> Result<models::Attachment, Error<RepoEditReleaseAttachmentError>>;
async fn edit_wiki_page(
&self,
owner: &str,
repo: &str,
page_name: &str,
body: Option<models::CreateWikiPageOptions>,
) -> Result<models::WikiPage, Error<RepoEditWikiPageError>>;
async fn get(&self, owner: &str, repo: &str)
-> Result<models::Repository, Error<RepoGetError>>;
async fn get_all_commits(
&self,
owner: &str,
repo: &str,
sha: Option<&str>,
path: Option<&str>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Commit>, Error<RepoGetAllCommitsError>>;
async fn get_archive(
&self,
owner: &str,
repo: &str,
archive: &str,
) -> Result<(), Error<RepoGetArchiveError>>;
async fn get_assignees(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::User>, Error<RepoGetAssigneesError>>;
async fn get_branch(
&self,
owner: &str,
repo: &str,
branch: &str,
) -> Result<models::Branch, Error<RepoGetBranchError>>;
async fn get_branch_protection(
&self,
owner: &str,
repo: &str,
name: &str,
) -> Result<models::BranchProtection, Error<RepoGetBranchProtectionError>>;
async fn get_by_id(&self, id: i64) -> Result<models::Repository, Error<RepoGetByIdError>>;
async fn get_combined_status_by_ref(
&self,
owner: &str,
repo: &str,
r#ref: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<models::CombinedStatus, Error<RepoGetCombinedStatusByRefError>>;
async fn get_contents(
&self,
owner: &str,
repo: &str,
filepath: &str,
r#ref: Option<&str>,
) -> Result<models::ContentsResponse, Error<RepoGetContentsError>>;
async fn get_contents_list(
&self,
owner: &str,
repo: &str,
r#ref: Option<&str>,
) -> Result<Vec<models::ContentsResponse>, Error<RepoGetContentsListError>>;
async fn get_editor_config(
&self,
owner: &str,
repo: &str,
filepath: &str,
r#ref: Option<&str>,
) -> Result<(), Error<RepoGetEditorConfigError>>;
async fn get_git_hook(
&self,
owner: &str,
repo: &str,
id: &str,
) -> Result<models::GitHook, Error<RepoGetGitHookError>>;
async fn get_hook(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<models::Hook, Error<RepoGetHookError>>;
async fn get_issue_templates(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::IssueTemplate>, Error<RepoGetIssueTemplatesError>>;
async fn get_key(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<models::DeployKey, Error<RepoGetKeyError>>;
async fn get_languages(
&self,
owner: &str,
repo: &str,
) -> Result<::std::collections::HashMap<String, i64>, Error<RepoGetLanguagesError>>;
async fn get_note(
&self,
owner: &str,
repo: &str,
sha: &str,
) -> Result<models::Note, Error<RepoGetNoteError>>;
async fn get_pull_request(
&self,
owner: &str,
repo: &str,
index: i64,
) -> Result<models::PullRequest, Error<RepoGetPullRequestError>>;
async fn get_pull_request_commits(
&self,
owner: &str,
repo: &str,
index: i64,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Commit>, Error<RepoGetPullRequestCommitsError>>;
async fn get_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
) -> Result<models::PullReview, Error<RepoGetPullReviewError>>;
async fn get_pull_review_comments(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
) -> Result<Vec<models::PullReviewComment>, Error<RepoGetPullReviewCommentsError>>;
async fn get_raw_file(
&self,
owner: &str,
repo: &str,
filepath: &str,
r#ref: Option<&str>,
) -> Result<(), Error<RepoGetRawFileError>>;
async fn get_raw_file_or_lfs(
&self,
owner: &str,
repo: &str,
filepath: &str,
r#ref: Option<&str>,
) -> Result<(), Error<RepoGetRawFileOrLfsError>>;
async fn get_release(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<models::Release, Error<RepoGetReleaseError>>;
async fn get_release_attachment(
&self,
owner: &str,
repo: &str,
id: i64,
attachment_id: i64,
) -> Result<models::Attachment, Error<RepoGetReleaseAttachmentError>>;
async fn get_release_by_tag(
&self,
owner: &str,
repo: &str,
tag: &str,
) -> Result<models::Release, Error<RepoGetReleaseByTagError>>;
async fn get_repo_permissions(
&self,
owner: &str,
repo: &str,
collaborator: &str,
) -> Result<models::RepoCollaboratorPermission, Error<RepoGetRepoPermissionsError>>;
async fn get_reviewers(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::User>, Error<RepoGetReviewersError>>;
async fn get_single_commit(
&self,
owner: &str,
repo: &str,
sha: &str,
) -> Result<models::Commit, Error<RepoGetSingleCommitError>>;
async fn get_tag(
&self,
owner: &str,
repo: &str,
tag: &str,
) -> Result<models::Tag, Error<RepoGetTagError>>;
async fn get_wiki_page(
&self,
owner: &str,
repo: &str,
page_name: &str,
) -> Result<models::WikiPage, Error<RepoGetWikiPageError>>;
async fn get_wiki_page_revisions(
&self,
owner: &str,
repo: &str,
page_name: &str,
page: Option<i32>,
) -> Result<models::WikiCommitList, Error<RepoGetWikiPageRevisionsError>>;
async fn get_wiki_pages(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::WikiPageMetaData>, Error<RepoGetWikiPagesError>>;
async fn list_all_git_refs(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::Reference>, Error<RepoListAllGitRefsError>>;
async fn list_branch_protection(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::BranchProtection>, Error<RepoListBranchProtectionError>>;
async fn list_branches(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Branch>, Error<RepoListBranchesError>>;
async fn list_collaborators(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::User>, Error<RepoListCollaboratorsError>>;
async fn list_git_hooks(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::GitHook>, Error<RepoListGitHooksError>>;
async fn list_git_refs(
&self,
owner: &str,
repo: &str,
r#ref: &str,
) -> Result<Vec<models::Reference>, Error<RepoListGitRefsError>>;
async fn list_hooks(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Hook>, Error<RepoListHooksError>>;
async fn list_keys(
&self,
owner: &str,
repo: &str,
key_id: Option<i32>,
fingerprint: Option<&str>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::DeployKey>, Error<RepoListKeysError>>;
async fn list_pull_requests(
&self,
owner: &str,
repo: &str,
state: Option<&str>,
sort: Option<&str>,
milestone: Option<i64>,
labels: Option<Vec<i64>>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::PullRequest>, Error<RepoListPullRequestsError>>;
async fn list_pull_reviews(
&self,
owner: &str,
repo: &str,
index: i64,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::PullReview>, Error<RepoListPullReviewsError>>;
async fn list_release_attachments(
&self,
owner: &str,
repo: &str,
id: i64,
) -> Result<Vec<models::Attachment>, Error<RepoListReleaseAttachmentsError>>;
async fn list_releases(
&self,
owner: &str,
repo: &str,
draft: Option<bool>,
pre_release: Option<bool>,
per_page: Option<i32>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Release>, Error<RepoListReleasesError>>;
async fn list_stargazers(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::User>, Error<RepoListStargazersError>>;
async fn list_statuses(
&self,
owner: &str,
repo: &str,
sha: &str,
sort: Option<&str>,
state: Option<&str>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::CommitStatus>, Error<RepoListStatusesError>>;
async fn list_statuses_by_ref(
&self,
owner: &str,
repo: &str,
r#ref: &str,
sort: Option<&str>,
state: Option<&str>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::CommitStatus>, Error<RepoListStatusesByRefError>>;
async fn list_subscribers(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::User>, Error<RepoListSubscribersError>>;
async fn list_tags(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::Tag>, Error<RepoListTagsError>>;
async fn list_teams(
&self,
owner: &str,
repo: &str,
) -> Result<Vec<models::Team>, Error<RepoListTeamsError>>;
async fn list_topics(
&self,
owner: &str,
repo: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<models::TopicName, Error<RepoListTopicsError>>;
async fn merge_pull_request(
&self,
owner: &str,
repo: &str,
index: i64,
body: Option<models::MergePullRequestOption>,
) -> Result<(), Error<RepoMergePullRequestError>>;
async fn migrate(
&self,
body: Option<models::MigrateRepoOptions>,
) -> Result<models::Repository, Error<RepoMigrateError>>;
async fn mirror_sync(&self, owner: &str, repo: &str) -> Result<(), Error<RepoMirrorSyncError>>;
async fn pull_request_is_merged(
&self,
owner: &str,
repo: &str,
index: i64,
) -> Result<(), Error<RepoPullRequestIsMergedError>>;
async fn search(
&self,
q: Option<&str>,
topic: Option<bool>,
include_desc: Option<bool>,
uid: Option<i64>,
priority_owner_id: Option<i64>,
team_id: Option<i64>,
starred_by: Option<i64>,
private: Option<bool>,
is_private: Option<bool>,
template: Option<bool>,
archived: Option<bool>,
mode: Option<&str>,
exclusive: Option<bool>,
sort: Option<&str>,
order: Option<&str>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<models::SearchResults, Error<RepoSearchError>>;
async fn signing_key(
&self,
owner: &str,
repo: &str,
) -> Result<String, Error<RepoSigningKeyError>>;
async fn submit_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
body: models::SubmitPullReviewOptions,
) -> Result<models::PullReview, Error<RepoSubmitPullReviewError>>;
async fn test_hook(
&self,
owner: &str,
repo: &str,
id: i64,
r#ref: Option<&str>,
) -> Result<(), Error<RepoTestHookError>>;
async fn tracked_times(
&self,
owner: &str,
repo: &str,
user: Option<&str>,
since: Option<String>,
before: Option<String>,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::TrackedTime>, Error<RepoTrackedTimesError>>;
async fn transfer(
&self,
owner: &str,
repo: &str,
body: models::TransferRepoOption,
) -> Result<models::Repository, Error<RepoTransferError>>;
async fn un_dismiss_pull_review(
&self,
owner: &str,
repo: &str,
index: i64,
id: i64,
) -> Result<models::PullReview, Error<RepoUnDismissPullReviewError>>;
async fn update_file(
&self,
owner: &str,
repo: &str,
filepath: &str,
body: models::UpdateFileOptions,
) -> Result<models::FileResponse, Error<RepoUpdateFileError>>;
async fn update_pull_request(
&self,
owner: &str,
repo: &str,
index: i64,
style: Option<&str>,
) -> Result<(), Error<RepoUpdatePullRequestError>>;
async fn update_topics(
&self,
owner: &str,
repo: &str,
body: Option<models::RepoTopicOptions>,
) -> Result<(), Error<RepoUpdateTopicsError>>;
async fn topic_search(
&self,
q: &str,
page: Option<i32>,
limit: Option<i32>,
) -> Result<Vec<models::TopicResponse>, Error<TopicSearchError>>;
async fn user_current_check_subscription(
&self,
owner: &str,
repo: &str,
) -> Result<models::WatchInfo, Error<UserCurrentCheckSubscriptionError>>;
async fn user_current_delete_subscription(
&self,
owner: &str,
repo: &str,
) -> Result<(), Error<UserCurrentDeleteSubscriptionError>>;
async fn user_current_put_subscription(
&self,
owner: &str,
repo: &str,
) -> Result<models::WatchInfo, Error<UserCurrentPutSubscriptionError>>;
async fn user_tracked_times(
&self,
owner: &str,
repo: &str,
user: &str,
) -> Result<Vec<models::TrackedTime>, Error<UserTrackedTimesError>>;
}
pub type DynRepository = Arc<dyn Repository + Send + Sync>;

View File

@ -0,0 +1,66 @@
use gitea_raw_client::apis::configuration::{ApiKey, Configuration};
use crate::client::GiteaClient;
pub struct GiteaClientBuilder {
conf: Configuration,
}
impl GiteaClientBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn set_basic_auth(mut self, username: String, password: Option<String>) -> Self {
self.conf.basic_auth = Some((username, password));
self
}
pub fn set_oauth(mut self, oauth_token: String) -> Self {
self.conf.oauth_access_token = Some(oauth_token);
self
}
pub fn set_bearer(mut self, bearer_token: String) -> Self {
self.conf.bearer_access_token = Some(bearer_token);
self
}
pub fn set_api_key(mut self, api_key: String, prefix: Option<String>) -> Self {
self.conf.api_key = Some(ApiKey {
key: api_key,
prefix,
});
self
}
pub fn set_base_path(mut self, base_path: &String) -> Self {
self.conf.base_path = base_path.clone();
self
}
pub fn set_client(mut self, client: reqwest::Client) -> Self {
self.conf.client = client;
self
}
pub fn build(self) -> GiteaClient {
GiteaClient::new(self.conf)
}
}
impl Default for GiteaClientBuilder {
fn default() -> Self {
Self {
conf: Configuration::default(),
}
}
}
impl From<Configuration> for GiteaClientBuilder {
fn from(conf: Configuration) -> Self {
let mut s = Self::default();
s.conf = conf;
s
}
}

View File

@ -0,0 +1,29 @@
use std::sync::Arc;
use gitea_raw_client::apis::configuration::Configuration;
use crate::apis::{defaults::repository::DefaultRepository, repository::DynRepository};
pub struct GiteaClient {
repository: DynRepository,
}
impl GiteaClient {
pub fn new(config: Configuration) -> Self {
let conf = Arc::new(config);
Self {
repository: Arc::new(DefaultRepository::new(conf.clone())),
}
}
pub fn repository(&self) -> DynRepository {
self.repository.clone()
}
}
impl From<Configuration> for GiteaClient {
fn from(conf: Configuration) -> Self {
Self::new(conf)
}
}

View File

@ -0,0 +1,8 @@
pub mod apis;
pub mod builder;
pub mod client;
pub mod models {
pub use gitea_raw_client::models::*;
}

View File

@ -13,4 +13,4 @@ eyre = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true }
clap = { version = "4.0.18" }
clap = { version = "4.0.18", features = ["env"] }

View File

@ -1,7 +1,10 @@
use std::{path::PathBuf, sync::Arc};
use clap::{Arg, ArgAction, ArgMatches, Command};
use octopush_core::schema;
use octopush_core::{
git::{git::LocalGitProviderOptions, gitea::client::DefaultGiteaClientOptions},
schema,
};
use octopush_infra::service_register::ServiceRegister;
use tokio::sync::Mutex;
@ -17,6 +20,12 @@ pub fn execute_cmd() -> Command {
.long_help("action path to your local octopush.yaml file")
.required(true),
)
.arg(
Arg::new("gitea-http-token")
.long("gitea-http-token")
.action(ArgAction::Set)
.required(false),
)
}
pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
@ -24,7 +33,17 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
.get_one::<String>("action")
.ok_or(eyre::anyhow!("--action is required"))?;
let service_register = ServiceRegister::new();
let gitea_http_token = args.get_one::<String>("gitea-http-token");
let service_register = ServiceRegister::new(
LocalGitProviderOptions {
http_auth: gitea_http_token.map(|t| t.clone()),
},
DefaultGiteaClientOptions {
url: "https://git.front.kjuulh.io/api/v1".into(),
basicauth: Some("kjuulh:379341972ba6d23ff85367ca1c10c82efea76f0c".into()),
},
);
let action_path: PathBuf = action.into();
@ -57,13 +76,15 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
}
let mut gitea_paths = Vec::new();
if let Some(gitea) = &select.gitea {
if let Some(gitea) = select.gitea.clone() {
let mut repo_clones = Vec::with_capacity(gitea.repositories.len());
for repo in gitea.repositories {
let gp = service_register.gitea_provider.clone();
repo_clones.push(tokio::spawn(
async move { gp.clone_from_qualified(repo).await },
))
repo_clones.push(tokio::spawn(async move {
gp.clone_from_qualified(repo.clone())
.await
.map(|(p, r)| (p, r, repo))
}))
}
for repo_clone in repo_clones {
@ -78,7 +99,7 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
if let Some(push) = git.push {
service_register
.git_provider
.create_branch(repo.clone(), &push.branch)
.create_branch(repo.clone(), &push.branch.name)
.await?;
}
}
@ -92,7 +113,33 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
if let Some(push) = git.push {
service_register
.git_provider
.push_branch(repo, &push.branch)
.push_branch(repo, &push.branch.name)
.await?;
}
}
}
for (path, repo, repo_name) in gitea_paths {
let repo = Arc::new(Mutex::new(repo));
if let Some(gitea) = select.gitea.clone() {
if let Some(push) = gitea.push {
service_register
.gitea_provider
.create_branch(repo.clone(), &push.pull_request)
.await?;
}
}
service_register
.executor
.execute(path.clone(), action_path.clone(), action.clone())
.await?;
if let Some(gitea) = select.gitea.clone() {
if let Some(push) = gitea.push {
service_register
.gitea_provider
.create_pull_request(repo, &repo_name, &push.pull_request)
.await?;
}
}

View File

@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gitea_client = { path = "../gitea_client" }
async-trait = { workspace = true }
eyre = { workspace = true }
tokio = { workspace = true }

View File

@ -27,9 +27,13 @@ impl Executor for DefaultExecutor {
action_path: PathBuf,
action: Action,
) -> eyre::Result<()> {
tracing::trace!(
victim_path = victim_path.to_string_lossy().to_string(),
"execute"
);
let bin = self.builder.build(action_path, action.clone()).await?;
match action {
Action::Go { entry } => {
Action::Go { .. } => {
GolangExecutor::new()
.execute(GolangExecutorOpts { bin, victim_path })
.await?

View File

@ -1,19 +1,29 @@
use std::{path::PathBuf, sync::Arc};
use eyre::ContextCompat;
use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
use tokio::sync::Mutex;
use crate::{schema::models::GitPushBranch, storage::DynStorageEngine};
use crate::storage::DynStorageEngine;
use super::GitProvider;
#[derive(Clone, Debug)]
pub struct LocalGitProviderOptions {
pub http_auth: Option<String>,
}
pub struct LocalGitProvider {
storage_engine: DynStorageEngine,
options: LocalGitProviderOptions,
}
impl LocalGitProvider {
pub fn new(storage_engine: DynStorageEngine) -> Self {
Self { storage_engine }
pub fn new(options: LocalGitProviderOptions, storage_engine: DynStorageEngine) -> Self {
Self {
storage_engine,
options,
}
}
}
@ -22,20 +32,37 @@ impl GitProvider for LocalGitProvider {
async fn clone_from_url(&self, url: String) -> eyre::Result<(PathBuf, Repository)> {
tracing::debug!(url, "allocating dir");
let dir = self.storage_engine.allocate_dir().await?;
let options = self.options.clone();
let dirpath = dir.clone().path();
let repo = tokio::task::spawn_blocking(move || {
let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(|url, username_from_url, _allowed_types| {
tracing::debug!(username_from_url, url, "pulling key from ssh-agent");
Cred::ssh_key_from_agent(username_from_url.unwrap())
if let Some(auth) = &options.http_auth {
tracing::trace!(auth, "authenticating");
let (user, pass) = auth
.split_once(":")
.ok_or("http_auth is not formatted correctly")
.unwrap();
Cred::userpass_plaintext(user, pass)
} else {
let username = username_from_url
.context("could not find username_from_url")
.unwrap();
Cred::ssh_key_from_agent(username)
}
});
let mut fo = git2::FetchOptions::new();
fo.remote_callbacks(callbacks);
let checkout_builder = git2::build::CheckoutBuilder::new();
let mut builder = git2::build::RepoBuilder::new();
builder.fetch_options(fo);
builder.fetch_options(fo).with_checkout(checkout_builder);
tracing::debug!(
url,
@ -54,7 +81,7 @@ impl GitProvider for LocalGitProvider {
async fn create_branch(
&self,
repo: Arc<Mutex<Repository>>,
branch: &GitPushBranch,
branch_name: &String,
) -> eyre::Result<()> {
let repo = repo.lock().await;
@ -64,7 +91,7 @@ impl GitProvider for LocalGitProvider {
.ok_or(eyre::anyhow!("could not get access to target commit"))?;
let head_commit = repo.find_commit(head_commit_oid)?;
let newbranch = repo.branch(
&branch.name.to_lowercase().replace(" ", "-"),
&branch_name.to_lowercase().replace(" ", "-"),
&head_commit,
true,
)?;
@ -82,13 +109,23 @@ impl GitProvider for LocalGitProvider {
async fn push_branch(
&self,
repo: Arc<Mutex<Repository>>,
branch: &GitPushBranch,
branch_name: &String,
) -> eyre::Result<()> {
let repo = repo.lock().await;
let options = self.options.clone();
tracing::trace!("pulling signature from local git");
let signature = repo.signature()?;
for rev in repo.revwalk()? {
let rev = rev?;
let commit = repo.find_commit(rev)?;
let summary = commit
.summary()
.ok_or(eyre::anyhow!("could not find commit"))?;
tracing::info!(summary, "summary")
}
tracing::trace!("fetching index and adding changed files to working tree");
let mut index = repo.index()?;
index.add_all(&["."], git2::IndexAddOption::DEFAULT, None)?;
@ -104,10 +141,10 @@ impl GitProvider for LocalGitProvider {
tracing::trace!("writing commit object");
repo.commit(
None,
Some("HEAD"),
&signature,
&signature,
branch.name.to_lowercase().replace(" ", "-").as_str(),
branch_name.to_lowercase().replace(" ", "-").as_str(),
&tree,
&[&parents],
)?;
@ -121,7 +158,19 @@ impl GitProvider for LocalGitProvider {
let mut remote_callbacks = RemoteCallbacks::new();
remote_callbacks.credentials(|url, username_from_url, _allowed_types| {
tracing::debug!(username_from_url, url, "pulling key from ssh-agent");
Cred::ssh_key_from_agent(username_from_url.unwrap())
if let Some(auth) = &options.http_auth {
tracing::trace!(auth, "authenticating");
let (user, pass) = auth
.split_once(":")
.ok_or("http_auth is not formatted correctly")
.unwrap();
Cred::userpass_plaintext(user, pass)
} else {
let username = username_from_url.unwrap();
Cred::ssh_key_from_agent(username)
}
});
let mut push_options = PushOptions::new();

View File

@ -1,7 +1,76 @@
pub struct DefaultGiteaClient {}
use std::sync::Arc;
use async_trait::async_trait;
use gitea_client::{builder::GiteaClientBuilder, models::CreatePullRequestOption};
use super::GiteaClient;
pub struct DefaultGiteaClientOptions {
pub url: String,
pub basicauth: Option<String>,
}
pub struct DefaultGiteaClient {
gitea_client: Arc<gitea_client::client::GiteaClient>,
}
impl DefaultGiteaClient {
pub fn new() -> Self {
Self {}
pub fn new(options: &DefaultGiteaClientOptions) -> Self {
let mut gitea = GiteaClientBuilder::new().set_base_path(&options.url);
if let Some(basicauth) = options.basicauth.clone() {
if let Some((username, password)) = basicauth.split_once(":") {
gitea = gitea.set_basic_auth(username.into(), Some(password.into()));
}
}
Self {
gitea_client: Arc::new(gitea.build()),
}
}
}
#[async_trait]
impl GiteaClient for DefaultGiteaClient {
async fn get_clone_url(&self, owner: String, repo_name: String) -> eyre::Result<String> {
let repo = self
.gitea_client
.repository()
.get(&owner, &repo_name)
.await?;
let clone_url = repo
.ssh_url
.ok_or(eyre::anyhow!("clone_url is not set for repository"))?;
Ok(clone_url)
}
async fn create_pull_request(
&self,
owner: &String,
repo_name: &String,
pull_request_name: &String,
) -> eyre::Result<()> {
self.gitea_client
.repository()
.create_pull_request(
&owner,
&repo_name,
Some(CreatePullRequestOption {
assignee: None,
assignees: None,
base: Some("main".into()),
body: None,
due_date: None,
head: Some(pull_request_name.to_lowercase().replace(" ", "-")),
labels: None,
milestone: None,
title: Some(pull_request_name.clone()),
}),
)
.await?;
Ok(())
}
}

View File

@ -1,17 +1,42 @@
pub mod client;
pub mod provider;
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};
use async_trait::async_trait;
use git2::Repository;
use tokio::sync::Mutex;
pub trait GiteaClient {}
use crate::schema::models::GitPushPullRequest;
#[async_trait]
pub trait GiteaClient {
async fn get_clone_url(&self, owner: String, repo_name: String) -> eyre::Result<String>;
async fn create_pull_request(
&self,
owner: &String,
repo_name: &String,
pull_request_name: &String,
) -> eyre::Result<()>;
}
pub type DynGiteaClient = Arc<dyn GiteaClient + Send + Sync>;
#[async_trait]
pub trait GiteaProvider {
async fn clone_from_qualified(repo: String) -> eyre::Result<String>;
async fn clone_from_qualified(&self, repo: String) -> eyre::Result<(PathBuf, Repository)>;
async fn create_branch(
&self,
repo: Arc<Mutex<Repository>>,
branch: &GitPushPullRequest,
) -> eyre::Result<()>;
async fn create_pull_request(
&self,
repo: Arc<Mutex<Repository>>,
repo_name: &String,
pull_request: &GitPushPullRequest,
) -> eyre::Result<()>;
}
pub type DynGiteaProvider = Arc<dyn GiteaProvider + Send + Sync>;

View File

@ -1,12 +1,16 @@
use async_trait::async_trait;
use std::{path::PathBuf, sync::Arc};
use crate::{git::DynGitProvider, storage::DynStorageEngine};
use async_trait::async_trait;
use git2::Repository;
use tokio::sync::Mutex;
use crate::{git::DynGitProvider, schema::models::GitPushPullRequest, storage::DynStorageEngine};
use super::{DynGiteaClient, GiteaProvider};
pub struct DefaultGiteaProvider {
git_provider: DynGitProvider,
storage_engine: DynStorageEngine,
_storage_engine: DynStorageEngine,
gitea_client: DynGiteaClient,
}
@ -18,7 +22,7 @@ impl DefaultGiteaProvider {
) -> Self {
Self {
git_provider,
storage_engine,
_storage_engine: storage_engine,
gitea_client,
}
}
@ -26,7 +30,50 @@ impl DefaultGiteaProvider {
#[async_trait]
impl GiteaProvider for DefaultGiteaProvider {
async fn clone_from_qualified(repo: String) -> eyre::Result<String> {
todo!()
async fn clone_from_qualified(&self, repo: String) -> eyre::Result<(PathBuf, Repository)> {
let (owner, repo_name) = repo
.split_once("/")
.ok_or(eyre::anyhow!("repo is not a valid format"))?;
let clone_url = self
.gitea_client
.get_clone_url(owner.into(), repo_name.into())
.await?;
let (path, repo) = self.git_provider.clone_from_url(clone_url).await?;
Ok((path, repo))
}
async fn create_branch(
&self,
repo: Arc<Mutex<Repository>>,
pull_request: &GitPushPullRequest,
) -> eyre::Result<()> {
tracing::trace!("creating branch");
self.git_provider
.create_branch(repo, &pull_request.name)
.await
}
async fn create_pull_request(
&self,
repo: Arc<Mutex<Repository>>,
repo_name: &String,
pull_request: &GitPushPullRequest,
) -> eyre::Result<()> {
let (owner, repo_name) = repo_name
.split_once("/")
.ok_or(eyre::anyhow!("repo is not a valid format"))?;
tracing::trace!("push_branch");
self.git_provider
.push_branch(repo, &pull_request.name)
.await?;
tracing::trace!("create_pull_request");
self.gitea_client
.create_pull_request(&owner.into(), &repo_name.into(), &pull_request.name)
.await
}
}

View File

@ -15,12 +15,12 @@ pub trait GitProvider {
async fn create_branch(
&self,
repo: Arc<Mutex<Repository>>,
branch: &GitPushBranch,
branch_name: &String,
) -> eyre::Result<()>;
async fn push_branch(
&self,
repo: Arc<Mutex<Repository>>,
branch: &GitPushBranch,
branch_name: &String,
) -> eyre::Result<()>;
}

View File

@ -25,12 +25,14 @@ pub struct Git {
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct GitHubPush {
pub branch: GitPushPullRequest,
#[serde(rename = "pull-request")]
pub pull_request: GitPushPullRequest,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct GiteaPush {
pub branch: GitPushPullRequest,
#[serde(rename = "pull-request")]
pub pull_request: GitPushPullRequest,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]

View File

@ -43,7 +43,7 @@ pub async fn execute_shell(cmd: String, path: Option<PathBuf>) -> eyre::Result<(
});
while let Some(line) = reader.next_line().await? {
tracing::trace!("something: {}", line)
tracing::trace!("{}", line)
}
Ok(())

View File

@ -9,3 +9,4 @@ edition = "2021"
octopush_core = { path = "../octopush_core" }
eyre = { workspace = true }
tracing = { workspace = true }

View File

@ -4,8 +4,12 @@ use octopush_core::{
builder::{builder_capabilities::BuilderCapabilities, DynBuilder},
executor::{default_executor::DefaultExecutor, executor::DynExecutor},
git::{
git::LocalGitProvider,
gitea::{provider::DefaultGiteaProvider, DynGiteaProvider},
git::{LocalGitProvider, LocalGitProviderOptions},
gitea::{
client::{DefaultGiteaClient, DefaultGiteaClientOptions},
provider::DefaultGiteaProvider,
DynGiteaProvider,
},
DynGitProvider,
},
schema::parser::{DefaultSchemaParser, DynSchemaParser},
@ -22,13 +26,24 @@ pub struct ServiceRegister {
}
impl ServiceRegister {
pub fn new() -> Self {
pub fn new(
git_provider_options: LocalGitProviderOptions,
gitea_client_options: DefaultGiteaClientOptions,
) -> Self {
let storage_engine = Arc::new(LocalStorageEngine::new("/tmp/octopush".into()));
let git_provider = Arc::new(LocalGitProvider::new(storage_engine.clone()));
let git_provider = Arc::new(LocalGitProvider::new(
git_provider_options,
storage_engine.clone(),
));
let schema_parser = Arc::new(DefaultSchemaParser::new());
let builder = Arc::new(BuilderCapabilities::new());
let executor = Arc::new(DefaultExecutor::new(builder.clone()));
let gitea_provider = Arc::new(DefaultGiteaProvider::new(git_provider.clone()));
let gitea_client = Arc::new(DefaultGiteaClient::new(&gitea_client_options));
let gitea_provider = Arc::new(DefaultGiteaProvider::new(
git_provider.clone(),
storage_engine.clone(),
gitea_client.clone(),
));
Self {
storage_engine,