summaryrefslogtreecommitdiff
path: root/docs/src/contribs.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-05-17 14:31:55 +0200
committerLaurenz <laurmaedje@gmail.com>2023-05-17 14:31:55 +0200
commit8971588486b6ffa9269344b4bda71de86af9d908 (patch)
tree420a51975c654741c99d00b7869a58cf291f3a6a /docs/src/contribs.rs
parentd14d1e867f83de631e7252ec5bdb2aa2dd870c8e (diff)
Externalize contributor fetching
Diffstat (limited to 'docs/src/contribs.rs')
-rw-r--r--docs/src/contribs.rs25
1 files changed, 7 insertions, 18 deletions
diff --git a/docs/src/contribs.rs b/docs/src/contribs.rs
index 7e43249a..901b5f69 100644
--- a/docs/src/contribs.rs
+++ b/docs/src/contribs.rs
@@ -4,23 +4,15 @@ use std::fmt::Write;
use serde::Deserialize;
-use super::Html;
+use super::{Html, Resolver};
/// Build HTML detailing the contributors between two tags.
-pub fn contributors(from: &str, to: &str) -> Option<Html> {
+pub fn contributors(resolver: &dyn Resolver, from: &str, to: &str) -> Option<Html> {
let staff = ["laurmaedje", "reknih"];
- let url = format!("https://api.github.com/repos/typst/typst/compare/{from}...{to}");
- let response: Response = ureq::get(&url)
- .set("X-GitHub-Api-Version", "2022-11-28")
- .call()
- .ok()?
- .into_json()
- .ok()?;
-
// Determine number of contributions per person.
let mut contributors = HashMap::<String, Contributor>::new();
- for commit in response.commits {
+ for commit in resolver.commits(from, to) {
contributors
.entry(commit.author.login.clone())
.or_insert_with(|| Contributor {
@@ -80,18 +72,15 @@ struct Contributor {
contributions: usize,
}
+/// A commit on the `typst` repository.
#[derive(Debug, Deserialize)]
-struct Response {
- commits: Vec<Commit>,
-}
-
-#[derive(Debug, Deserialize)]
-struct Commit {
+pub struct Commit {
author: Author,
}
+/// A commit author.
#[derive(Debug, Deserialize)]
-struct Author {
+pub struct Author {
login: String,
avatar_url: String,
}