Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 85f9bb9

Browse files
committed
Add conversion for response to GitHubIssue
- Define struct `GitHubIssueResponse` and implement `TryFrom<T>` trait to parse/convert GitHub API response - Add few implementations of `From<T>` trait to convert contents of struct `GitHubIssueResponse` to struct `GitHubIssue`
1 parent c601fd1 commit 85f9bb9

File tree

5 files changed

+455
-324
lines changed

5 files changed

+455
-324
lines changed

src/api/issue.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ use serde::{Deserialize, Serialize};
1010
use crate::{
1111
api,
1212
api::DateTimeUtc,
13-
database::{self, Database, TryFromKeyValue},
14-
outbound::{
15-
issues::{IssueState, PullRequestState},
16-
GitHubIssue,
17-
},
13+
database::{self, Database, GitHubIssue, TryFromKeyValue},
14+
outbound::issues::{IssueState, PullRequestState},
1815
};
1916

2017
scalar!(IssueState);
@@ -241,7 +238,7 @@ impl IssueQuery {
241238

242239
#[cfg(test)]
243240
mod tests {
244-
use crate::{api::TestSchema, outbound::GitHubIssue};
241+
use crate::{api::TestSchema, database::GitHubIssue};
245242

246243
fn create_issues(n: usize) -> Vec<GitHubIssue> {
247244
(1..=n)

src/api/issue_stat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ impl IssueStatQuery {
7777
mod tests {
7878
use jiff::Timestamp;
7979

80-
use crate::{api::TestSchema, outbound::GitHubIssue};
80+
use crate::{api::TestSchema, database::GitHubIssue};
8181

8282
fn create_issues(n: usize) -> Vec<GitHubIssue> {
83-
(0..n)
83+
(1..=n)
8484
.map(|i| GitHubIssue {
8585
number: i.try_into().unwrap(),
8686
..Default::default()

src/database.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use regex::Regex;
66
use serde::Serialize;
77

88
pub mod discussion;
9+
pub mod issue;
910

1011
pub(crate) use discussion::DiscussionDbSchema;
12+
pub(crate) use issue::GitHubIssue;
1113

12-
use crate::{
13-
api::{issue::Issue, pull_request::PullRequest},
14-
outbound::{GitHubIssue, GitHubPullRequestNode},
15-
};
14+
use crate::{api::pull_request::PullRequest, outbound::GitHubPullRequestNode};
1615

1716
const GLOBAL_PARTITION_NAME: &str = "global";
1817
const ISSUE_PARTITION_NAME: &str = "issues";
@@ -86,19 +85,6 @@ impl Database {
8685
bail!("Failed to get db value");
8786
}
8887

89-
pub(crate) fn insert_issues(
90-
&self,
91-
resp: Vec<GitHubIssue>,
92-
owner: &str,
93-
name: &str,
94-
) -> Result<()> {
95-
for item in resp {
96-
let keystr: String = format!("{owner}/{name}#{}", item.number);
97-
Database::insert(&keystr, item, &self.issue_partition)?;
98-
}
99-
Ok(())
100-
}
101-
10288
pub(crate) fn insert_pull_requests(
10389
&self,
10490
resp: Vec<GitHubPullRequestNode>,
@@ -112,15 +98,6 @@ impl Database {
11298
Ok(())
11399
}
114100

115-
pub(crate) fn issues(&self, start: Option<&[u8]>, end: Option<&[u8]>) -> Iter<Issue> {
116-
let start = start.unwrap_or(b"\x00");
117-
if let Some(end) = end {
118-
Iter::new(self.issue_partition.range(start..end))
119-
} else {
120-
Iter::new(self.issue_partition.range(start..))
121-
}
122-
}
123-
124101
pub(crate) fn pull_requests(
125102
&self,
126103
start: Option<&[u8]>,

0 commit comments

Comments
 (0)