hubcaps_ex/
pull_commits.rs

1//! Pull Commits interface
2use serde::Deserialize;
3
4use crate::users::User;
5use crate::{Future, Github, Stream};
6
7/// A structure for interfacing with a pull commits
8pub struct PullCommits {
9    github: Github,
10    owner: String,
11    repo: String,
12    number: u64,
13}
14
15impl PullCommits {
16    #[doc(hidden)]
17    pub fn new<O, R>(github: Github, owner: O, repo: R, number: u64) -> Self
18    where
19        O: Into<String>,
20        R: Into<String>,
21    {
22        PullCommits {
23            github,
24            owner: owner.into(),
25            repo: repo.into(),
26            number,
27        }
28    }
29
30    /// list pull commits
31    pub fn list(&self) -> Future<Vec<PullCommit>> {
32        let uri = format!(
33            "/repos/{}/{}/pulls/{}/commits",
34            self.owner, self.repo, self.number
35        );
36        self.github.get::<Vec<PullCommit>>(&uri)
37    }
38
39    /// provides a stream over all pages of pull commits
40    pub fn iter(&self) -> Stream<PullCommit> {
41        self.github.get_stream(&format!(
42            "/repos/{}/{}/pulls/{}/commits",
43            self.owner, self.repo, self.number
44        ))
45    }
46}
47
48// representations
49
50/// Representation of a pull request commit
51#[derive(Debug, Deserialize)]
52pub struct PullCommit {
53    pub url: String,
54    pub sha: String,
55    pub html_url: String,
56    pub comments_url: String,
57    pub commit: CommitDetails,
58    pub author: User,
59    pub committer: User,
60    pub parents: Vec<CommitRef>,
61}
62
63/// Representation of a pull request commit details
64#[derive(Debug, Deserialize)]
65pub struct CommitDetails {
66    pub url: String,
67    pub author: UserStamp,
68    pub committer: Option<UserStamp>,
69    pub message: String,
70    pub tree: CommitRef,
71    pub comment_count: u64,
72}
73
74/// Representation of a reference to a commit
75#[derive(Debug, Deserialize)]
76pub struct CommitRef {
77    pub url: String,
78    pub sha: String,
79}
80
81/// Representation of a git user
82#[derive(Debug, Deserialize)]
83pub struct UserStamp {
84    pub name: String,
85    pub email: String,
86    pub date: String,
87}