JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Rebrand to requests over command

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨688fc97

Showing ⁨⁨11⁩ changed files⁩ with ⁨⁨160⁩ insertions⁩ and ⁨⁨160⁩ deletions⁩

src/backend/git.rs

View file
@@ -1,8 +1,8 @@
1 1 use std::error::Error;
2 2
3 3 use crate::{
4 command::repository::{
5 CreateRepositoryCommand, CreateRepositoryResponse, RepositoryFileInspectionCommand,
4 messages::repository::{
5 CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest,
6 6 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
7 7 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse,
8 8 RepositoryIssuesRequest, RepositoryIssuesResponse,
@@ -23,7 +23,7 @@ impl GitBackend {
23 23 impl RepositoryBackend for GitBackend {
24 24 fn create_repository(
25 25 &mut self,
26 request: &CreateRepositoryCommand,
26 request: &CreateRepositoryRequest,
27 27 ) -> Result<CreateRepositoryResponse, Box<dyn Error + Send>> {
28 28 todo!()
29 29 }
@@ -37,7 +37,7 @@ impl RepositoryBackend for GitBackend {
37 37
38 38 fn repository_file_inspect(
39 39 &mut self,
40 request: &RepositoryFileInspectionCommand,
40 request: &RepositoryFileInspectRequest,
41 41 ) -> Result<RepositoryFileInspectionResponse, Box<dyn Error + Send>> {
42 42 todo!()
43 43 }

src/backend/mod.rs

View file
@@ -3,8 +3,8 @@ pub mod git;
3 3 use std::error::Error;
4 4
5 5 use crate::{
6 command::repository::{
7 CreateRepositoryCommand, CreateRepositoryResponse, RepositoryFileInspectionCommand,
6 messages::repository::{
7 CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest,
8 8 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
9 9 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse,
10 10 RepositoryIssuesRequest, RepositoryIssuesResponse,
@@ -15,7 +15,7 @@ use crate::{
15 15 pub trait RepositoryBackend {
16 16 fn create_repository(
17 17 &mut self,
18 request: &CreateRepositoryCommand,
18 request: &CreateRepositoryRequest,
19 19 ) -> Result<CreateRepositoryResponse, Box<dyn Error + Send>>;
20 20 fn repository_info(
21 21 &mut self,
@@ -23,7 +23,7 @@ pub trait RepositoryBackend {
23 23 ) -> Result<RepositoryView, Box<dyn Error + Send>>;
24 24 fn repository_file_inspect(
25 25 &mut self,
26 request: &RepositoryFileInspectionCommand,
26 request: &RepositoryFileInspectRequest,
27 27 ) -> Result<RepositoryFileInspectionResponse, Box<dyn Error + Send>>;
28 28
29 29 fn repository_issues_count(

src/connection.rs

View file
@@ -14,7 +14,7 @@ use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
14 14
15 15 use crate::{
16 16 backend::RepositoryBackend,
17 command::{
17 messages::{
18 18 issues::IssuesCountResponse,
19 19 repository::{
20 20 RepositoryFileInspectionResponse, RepositoryIssueLabelsResponse,
@@ -62,7 +62,7 @@ pub async fn connection_worker(
62 62 ) {
63 63 let mut handshaked = false;
64 64 let this_instance = Instance {
65 url: String::from("giterated.com"),
65 url: String::from("127.0.0.1:8080"),
66 66 };
67 67
68 68 while let Some(message) = socket.next().await {
@@ -213,7 +213,7 @@ pub async fn connection_worker(
213 213 .await
214 214 .unwrap();
215 215 }
216 RepositoryRequest::RepositoryFileInspection(request) => {
216 RepositoryRequest::RepositoryFileInspect(request) => {
217 217 let mut backend = backend.lock().await;
218 218 let response = backend.repository_file_inspect(request);
219 219

src/lib.rs

View file
@@ -1,5 +1,5 @@
1 1 pub mod backend;
2 pub mod command;
2 pub mod messages;
3 3 pub mod connection;
4 4 pub mod handshake;
5 5 pub mod listener;

src/listener.rs

View file
@@ -3,7 +3,7 @@ use std::collections::HashMap;
3 3 use tokio::sync::broadcast::{Receiver, Sender};
4 4
5 5 use crate::{
6 command::{repository::RepositoryMessage, MessageKind},
6 messages::{repository::RepositoryMessage, MessageKind},
7 7 model::{instance::Instance, repository::Repository, user::User},
8 8 };
9 9

src/messages/issues.rs

View file
@@ -0,0 +1,18 @@
1 use serde::{Deserialize, Serialize};
2
3 use crate::model::repository::Repository;
4
5 #[derive(Clone)]
6 pub struct IssuesCountCommand {
7 pub respository: Repository,
8 }
9
10 #[derive(Clone, Serialize, Deserialize)]
11 pub struct IssuesCountResponse {
12 pub count: u64,
13 }
14
15 #[derive(Clone)]
16 pub struct IssuesLabelsCommand {
17 pub repository: Repository,
18 }

src/messages/mod.rs

View file
@@ -0,0 +1,14 @@
1 use serde::{Deserialize, Serialize};
2
3 use crate::handshake::HandshakeMessage;
4
5 use self::repository::RepositoryMessage;
6
7 pub mod issues;
8 pub mod repository;
9
10 #[derive(Clone, Serialize, Deserialize)]
11 pub enum MessageKind {
12 Handshake(HandshakeMessage),
13 Repository(RepositoryMessage),
14 }

src/messages/repository.rs

View file
@@ -0,0 +1,115 @@
1 use serde::{Deserialize, Serialize};
2
3 use crate::model::{
4 repository::{CommitMetadata, Repository, RepositoryFile, RepositoryView},
5 user::User,
6 };
7
8 use super::issues::IssuesCountResponse;
9
10 #[derive(Clone, Serialize, Deserialize)]
11 pub struct RepositoryMessage {
12 pub target: Repository,
13 pub command: RepositoryMessageKind,
14 }
15
16 #[derive(Clone, Serialize, Deserialize)]
17 pub enum RepositoryMessageKind {
18 Request(RepositoryRequest),
19 Response(RepositoryResponse),
20 }
21
22 #[derive(Clone, Serialize, Deserialize)]
23 pub enum RepositoryRequest {
24 CreateRepository(CreateRepositoryRequest),
25 RepositoryFileInspect(RepositoryFileInspectRequest),
26 RepositoryInfo(RepositoryInfoRequest),
27 IssuesCount(RepositoryIssuesCountRequest),
28 IssueLabels(RepositoryIssueLabelsRequest),
29 Issues(RepositoryIssuesRequest),
30 }
31
32 #[derive(Clone, Serialize, Deserialize)]
33 pub enum RepositoryResponse {
34 CreateRepository(CreateRepositoryResponse),
35 RepositoryFileInspection(RepositoryFileInspectionResponse),
36 RepositoryInfo(RepositoryView),
37 IssuesCount(RepositoryIssuesCountResponse),
38 IssueLabels(RepositoryIssueLabelsResponse),
39 Issues(RepositoryIssuesResponse),
40 }
41
42 #[derive(Clone, Serialize, Deserialize)]
43 pub struct CreateRepositoryRequest {
44 pub name: String,
45 pub description: String,
46 pub default_branch: String,
47 pub owner: User,
48 }
49
50 #[derive(Clone, Serialize, Deserialize)]
51 pub enum CreateRepositoryResponse {
52 Created,
53 Failed,
54 }
55
56 #[derive(Clone, Serialize, Deserialize)]
57 pub struct RepositoryFileInspectRequest {
58 pub path: RepositoryFile,
59 }
60
61 #[derive(Clone, Serialize, Deserialize)]
62 pub enum RepositoryFileInspectionResponse {
63 File {
64 commit_metadata: CommitMetadata,
65 },
66 Folder {
67 commit_metadata: CommitMetadata,
68 members: Vec<RepositoryFile>,
69 },
70 Invalid {
71 path: RepositoryFile,
72 },
73 }
74
75 #[derive(Clone, Serialize, Deserialize)]
76 pub struct RepositoryIssuesCountRequest;
77
78 #[derive(Clone, Serialize, Deserialize)]
79 pub struct RepositoryIssuesCountResponse {
80 pub count: u64,
81 }
82
83 #[derive(Clone, Serialize, Deserialize)]
84 pub struct RepositoryIssueLabelsRequest;
85
86 #[derive(Clone, Serialize, Deserialize)]
87 pub struct RepositoryIssueLabelsResponse {
88 pub labels: Vec<IssueLabel>,
89 }
90
91 #[derive(Clone, Serialize, Deserialize)]
92 pub struct IssueLabel {
93 pub name: String,
94 pub color: String,
95 }
96
97 #[derive(Clone, Serialize, Deserialize)]
98 pub struct RepositoryIssuesRequest;
99
100 #[derive(Clone, Serialize, Deserialize)]
101 pub struct RepositoryIssuesResponse {
102 pub issues: Vec<RepositoryIssue>,
103 }
104
105 #[derive(Clone, Serialize, Deserialize)]
106 pub struct RepositoryIssue {
107 pub author: User,
108 pub id: u64,
109 pub title: String,
110 pub contents: String,
111 pub labels: Vec<IssueLabel>,
112 }
113
114 #[derive(Clone, Serialize, Deserialize)]
115 pub struct RepositoryInfoRequest;