summaryrefslogtreecommitdiff
path: root/crates/nixpkgs-tracker-http/src/github.rs
blob: 12ee832d7c9ba0bd9f42c7115bc1871bf1d9878a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::{Error, PullRequest};

use std::future::Future;

use log::trace;

const GITHUB_API: &str = "https://api.github.com";

pub trait Ext {
	/// GET `/repos/{repo_owner}/{repo_name}/pulls/{id}`
	///
	/// # Errors
	///
	/// Will return [`Err`] if the merge commit cannot be found
	fn pull_request(
		&self,
		repo_owner: &str,
		repo_name: &str,
		id: u64,
	) -> impl Future<Output = Result<PullRequest, Error>> + Send;
}

impl Ext for super::Client {
	async fn pull_request(
		&self,
		repo_owner: &str,
		repo_name: &str,
		id: u64,
	) -> Result<PullRequest, Error> {
		let url = format!("{GITHUB_API}/repos/{repo_owner}/{repo_name}/pulls/{id}");

		let request = self.get(&url).build()?;
		trace!("Making GET request to `{}`", request.url());
		let response = self.execute(request).await?;
		response.error_for_status_ref()?;
		let pull_request: PullRequest = response.json().await?;

		Ok(pull_request)
	}
}