Skip to content

Commit dfececd

Browse files
committed
chore: add support for next page leaderboard
1 parent b591753 commit dfececd

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

Diff for: .dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
target/
1+
target/
2+
.git/

Diff for: graphql/TeamYearThankQuery.graphql

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
query TeamYearThankQuery(
22
$selectedHandle: String!
33
$year: Int
4+
$cursor: String!
45
) {
56
selectedTeam: team(handle: $selectedHandle) {
67
...TeamThanksSelectedTeam
@@ -11,8 +12,11 @@ fragment TeamThanksSelectedTeam on Team {
1112
name
1213
state
1314
handle
14-
participants(first: 100, year: $year) {
15-
year_range
15+
participants(first: 999, year: $year, after: $cursor) {
16+
pageInfo {
17+
hasNextPage
18+
endCursor
19+
}
1620
edges {
1721
node {
1822
id

Diff for: src/sexurity-discord/src/subscriptions/reputation.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ fn build_embed_data(diff: Vec<models::RepData>, handle: &str) -> Option<Embed> {
9595
let old = &diff[0];
9696
let new = &diff[1];
9797

98-
if old.rank == -1 {
98+
if old.reputation == -1 {
9999
// new user added to leaderboard
100-
let text = format!(
100+
let mut text = format!(
101101
"[**``{}``**]({}) was added to [**``{}``**]({}) with **{} reputation** (rank: #{})",
102102
new.user_name,
103103
format!("https://hackerone.com/{}", new.user_name),
@@ -107,15 +107,26 @@ fn build_embed_data(diff: Vec<models::RepData>, handle: &str) -> Option<Embed> {
107107
new.rank
108108
);
109109

110+
if new.rank == -1 {
111+
text = format!(
112+
"[**``{}``**]({}) was added to [**``{}``**]({}) with **{} reputation** (rank: <100)",
113+
new.user_name,
114+
format!("https://hackerone.com/{}", new.user_name),
115+
handle,
116+
format!("https://hackerone.com/{}", handle),
117+
new.reputation
118+
);
119+
}
120+
110121
let embed = EmbedBuilder::new()
111122
.description(text)
112123
.color(models::embed_colors::POSTIVE)
113124
.build();
114125
return Some(embed);
115-
} else if new.rank == -1 {
126+
} else if new.reputation == -1 {
116127
// user removed from leaderboard
117128
let text = format!(
118-
"[**``{}``**]({}) was removed from top 100",
129+
"[**``{}``**]({}) was removed from the leaderboard",
119130
old.user_name,
120131
format!("https://hackerone.com/{}", old.user_name),
121132
);

Diff for: src/sexurity-poller/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn ensure_args(client: &HackerOneClient, args: &Arguments) -> bool {
7676
let variables = hackerone::team_year_thank_query::Variables {
7777
selected_handle: args.hackerone_handle.clone(),
7878
year: Some(now.year().into()),
79+
cursor: "".into(),
7980
};
8081

8182
let query = hackerone::TeamYearThankQuery::build_query(variables);

Diff for: src/sexurity-poller/src/polls/reputation.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn run_poll(config: &PollConfiguration) -> Result<(), Box<dyn std::error::Er
2828
.arg(models::redis_keys::REPUTATION_QUEUE_LAST_RUN_TIME)
2929
.query(&mut redis_conn)?;
3030
let mut last_rep_data = get_old_reputation_data(&mut redis_conn);
31-
let rep_data = get_reputation_data(&config.team_handle, &config.hackerone).unwrap();
31+
let rep_data = get_reputation_data(&config.team_handle, &config.hackerone, None, None).unwrap();
3232

3333
debug!(
3434
"reputation poll event: last_run_time {}",
@@ -150,10 +150,14 @@ fn set_last_run_time_now(conn: &mut redis::Connection) {
150150
fn get_reputation_data(
151151
handle: &str,
152152
client: &HackerOneClient,
153+
previous_data: Option<Vec<models::RepData>>,
154+
next_cursor: Option<String>,
153155
) -> Result<Vec<models::RepData>, Box<dyn std::error::Error>> {
156+
debug!("get reputation data, cursor: {}", next_cursor.as_ref().unwrap_or(&String::from("")));
154157
let variables = hackerone::team_year_thank_query::Variables {
155158
selected_handle: handle.to_string(),
156159
year: None,
160+
cursor: next_cursor.unwrap_or(String::from("")),
157161
};
158162

159163
let query = hackerone::TeamYearThankQuery::build_query(variables);
@@ -164,16 +168,35 @@ fn get_reputation_data(
164168
.send()?;
165169

166170
let mut result: Vec<models::RepData> = vec![];
167-
// (TODO): find a better way to do this?
171+
if previous_data.is_some() {
172+
result = previous_data.unwrap();
173+
}
174+
168175
let data = response.json::<graphql_client::Response<<hackerone::TeamYearThankQuery as GraphQLQuery>::ResponseData>>().unwrap();
176+
let page_info = &data
177+
.data
178+
.as_ref()
179+
.unwrap()
180+
.selected_team
181+
.as_ref()
182+
.unwrap()
183+
.participants
184+
.as_ref()
185+
.unwrap()
186+
.page_info;
187+
169188
let researchers = data
170189
.data
190+
.as_ref()
171191
.unwrap()
172192
.selected_team
193+
.as_ref()
173194
.unwrap()
174195
.participants
196+
.as_ref()
175197
.unwrap()
176198
.edges
199+
.as_ref()
177200
.unwrap();
178201
for researcher in researchers {
179202
let user = researcher.as_ref().unwrap().node.as_ref().unwrap();
@@ -196,6 +219,11 @@ fn get_reputation_data(
196219
result.push(data);
197220
}
198221

222+
if page_info.has_next_page {
223+
let end_cursor = page_info.end_cursor.as_ref().unwrap();
224+
return Ok(get_reputation_data(handle, client, Some(result), Some(end_cursor.clone())).unwrap());
225+
}
226+
199227
Ok(result)
200228
}
201229

0 commit comments

Comments
 (0)