GitWatcherBot
1.0.0
A Telegram Bot that notifies you when a new change is made in your repositories (issues, pull requests, stars, forks, and watches)
Main Page
Namespaces
Namespace List
Namespace Members
All
Typedefs
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
f
g
i
l
o
p
r
s
t
u
w
~
Functions
a
b
f
g
i
l
o
r
t
u
~
Variables
a
c
d
f
i
l
o
p
s
t
u
w
Files
File List
File Members
All
Functions
Variables
Macros
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Macros
Repository.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
#include <string>
5
#include <cstring>
6
#include "sqlite_orm/sqlite_orm.h"
7
#include "
User.hpp
"
8
9
10
namespace
models
{
11
using
RepositoryId
= std::int64_t;
12
13
struct
Repository
{
14
RepositoryId
id
{};
15
std::string
full_name
;
16
std::int64_t
stargazers_count
{};
17
std::int64_t
watchers_count
{};
18
std::int64_t
open_issues_count
{};
19
std::int64_t
pulls_count
{};
20
std::int64_t
forks_count
{};
21
std::string
description
;
22
std::size_t
size
{};
23
std::string
language
;
24
std::time_t
createdAt
{};
25
std::time_t
updatedAt
{};
26
std::unique_ptr<UserId>
watcher_id
;
27
28
static
auto
table
() {
29
using namespace
sqlite_orm;
30
return
make_table(
"Repositories"
,
31
make_column(
"id"
, &
Repository::id
),
// this is repository id from GitHub Api, don't make it primary_key() since multiple users can watch the same repository
32
make_column(
"full_name"
, &
Repository::full_name
),
33
make_column(
"stargazers_count"
, &
Repository::stargazers_count
),
34
make_column(
"watchers_count"
, &
Repository::watchers_count
),
35
make_column(
"open_issues_count"
, &
Repository::open_issues_count
),
36
make_column(
"pulls_count"
, &
Repository::pulls_count
),
37
make_column(
"forks_count"
, &
Repository::forks_count
),
38
make_column(
"description"
, &
Repository::description
),
39
make_column(
"size"
, &
Repository::size
),
40
make_column(
"language"
, &
Repository::language
),
41
make_column(
"createdAt"
, &
Repository::createdAt
),
42
make_column(
"updatedAt"
, &
Repository::updatedAt
),
43
make_column(
"watcher_id"
, &
Repository::watcher_id
),
44
foreign_key(&
Repository::watcher_id
).references(&
User::id
)
45
//primary_key(&Repository::id, &Repository::watcher_id) // TODO: don't try this, doesn't work with sqlite orm,
46
// try it later in separate project (Primary key ownership is repo id + watcher id since multiple
47
// users can watch the same repository, this way we can call storage.update(repo))
48
);
49
}
50
51
#define DESERIALIZE(field) \
52
try {\
53
field = json[#field]; \
54
}\
55
catch(const std::exception& e)\
56
{\
57
throw std::runtime_error("Failed to deserialize json field '"
+ std::string(#field) + "': " + e.what());\
58
}
59
60
Repository
() =
default
;
61
62
explicit
Repository
(
const
nl::json &json) {
63
64
DESERIALIZE
(
id
);
65
DESERIALIZE
(
full_name
);
66
DESERIALIZE
(
stargazers_count
);
67
DESERIALIZE
(
watchers_count
);
68
DESERIALIZE
(
open_issues_count
);
69
DESERIALIZE
(
forks_count
);
70
DESERIALIZE
(
description
);
71
DESERIALIZE
(
size
);
72
DESERIALIZE
(
language
);
73
74
75
76
// for pulls its different https://stackoverflow.com/questions/40534533/count-open-pull-requests-and-issues-on-github
77
// https://api.github.com/search/issues?q=repo:baderouaich/tgbotxx%20is:pr%20is:open&per_page=1
78
try
{
79
auto
res = cpr::Get(cpr::Url(
"https://api.github.com/search/issues?q=repo:"
+
full_name
+
"%20is:pr%20is:open&per_page=1"
));
80
nl::json data = nl::json::parse(res.text);
81
pulls_count
= data[
"total_count"
];
82
}
catch
(
const
std::exception &e) {
83
throw
std::runtime_error(
"Failed to get pulls_count for "
+
full_name
+
": "
+ e.what());
84
}
85
86
createdAt
= std::time(
nullptr
);
87
updatedAt
=
createdAt
;
88
}
89
90
};
91
92
#undef DESERIALIZE
93
}
DESERIALIZE
#define DESERIALIZE(field)
Definition:
Repository.hpp:51
User.hpp
models
Definition:
Log.hpp:12
models::RepositoryId
std::int64_t RepositoryId
Definition:
Repository.hpp:11
models::Repository
Definition:
Repository.hpp:13
models::Repository::forks_count
std::int64_t forks_count
Definition:
Repository.hpp:20
models::Repository::table
static auto table()
Definition:
Repository.hpp:28
models::Repository::createdAt
std::time_t createdAt
Definition:
Repository.hpp:24
models::Repository::watchers_count
std::int64_t watchers_count
Definition:
Repository.hpp:17
models::Repository::full_name
std::string full_name
Definition:
Repository.hpp:15
models::Repository::pulls_count
std::int64_t pulls_count
Definition:
Repository.hpp:19
models::Repository::language
std::string language
Definition:
Repository.hpp:23
models::Repository::description
std::string description
Definition:
Repository.hpp:21
models::Repository::watcher_id
std::unique_ptr< UserId > watcher_id
! User id who is watching changes on this repo
Definition:
Repository.hpp:26
models::Repository::Repository
Repository()=default
models::Repository::stargazers_count
std::int64_t stargazers_count
Definition:
Repository.hpp:16
models::Repository::Repository
Repository(const nl::json &json)
Definition:
Repository.hpp:62
models::Repository::updatedAt
std::time_t updatedAt
Definition:
Repository.hpp:25
models::Repository::id
RepositoryId id
Definition:
Repository.hpp:14
models::Repository::open_issues_count
std::int64_t open_issues_count
Definition:
Repository.hpp:18
models::Repository::size
std::size_t size
Definition:
Repository.hpp:22
models::User::id
UserId id
Definition:
User.hpp:16
src
db
models
Repository.hpp
Generated on Sat Jun 22 2024 16:34:05 for GitWatcherBot by
1.9.1