aboutsummaryrefslogtreecommitdiff
path: root/src/query
diff options
context:
space:
mode:
authortilpner2020-05-29 11:36:29 +0200
committertilpner2020-05-29 11:36:29 +0200
commit23e93564ca7de185aacab4c494312d8b732922dd (patch)
tree1644046fe27dc48be07aa15a1d35a416eb95b6ba /src/query
parent32139f8f178a40e3aff155a5bc035157f2cfca42 (diff)
downloadgithub-label-feed-23e93564ca7de185aacab4c494312d8b732922dd.tar.gz
github-label-feed-23e93564ca7de185aacab4c494312d8b732922dd.tar.xz
github-label-feed-23e93564ca7de185aacab4c494312d8b732922dd.zip
atom: add option to only include open issues
Diffstat (limited to 'src/query')
-rw-r--r--src/query/issues.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/query/issues.rs b/src/query/issues.rs
index b9473d3..525ebe5 100644
--- a/src/query/issues.rs
+++ b/src/query/issues.rs
@@ -21,23 +21,34 @@ type DateTime = String;
)]
pub struct IssuesQuery;
-fn state_to_integer(state: issues_query::IssueState) -> i64 {
- use issues_query::IssueState::*;
- match state {
- OPEN => 0,
- CLOSED => 1,
- Other(_) => 2
+pub use issues_query::IssueState;
+impl IssueState {
+ pub fn from_integer(i: i64) -> Option<Self> {
+ match i {
+ 0 => Some(Self::OPEN),
+ 1 => Some(Self::CLOSED),
+ _ => None
+ }
}
-}
-pub fn integer_to_state_desc(state: i64) -> Option<String> {
- match state {
- 0 => Some("open"),
- 1 => Some("closed"),
- _ => None
- }.map(str::to_owned)
+ pub fn to_integer(&self) -> i64 {
+ match self {
+ Self::OPEN => 0,
+ Self::CLOSED => 1,
+ Self::Other(_) => 2
+ }
+ }
+
+ pub fn to_string(&self) -> Option<String> {
+ match self {
+ Self::OPEN => Some("open"),
+ Self::CLOSED => Some("closed"),
+ Self::Other(_) => None
+ }.map(str::to_owned)
+ }
}
+
pub async fn update(mut conn: &mut Conn, github_api_token: &str, (ref owner, ref name): (String, String)) -> anyhow::Result<()> {
let repo = repo_id(conn, owner, name).await?;
@@ -90,7 +101,7 @@ pub async fn update(mut conn: &mut Conn, github_api_token: &str, (ref owner, ref
"REPLACE INTO issues (repo, number, state, title, body, user_login, html_url, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
).bind(repo).bind(issue.number)
- .bind(state_to_integer(issue.state)).bind(issue.title).bind(issue.body_html)
+ .bind(issue.state.to_integer()).bind(issue.title).bind(issue.body_html)
.bind(author).bind(issue.url).bind(ts)
.execute(&mut conn)
.await?;