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
41
42
43
44
45

use super::{Github, Result, Iter};
use rep::PullCommit;

fn identity<T>(x: T) -> T { x }

/// A structure for interfacing with a pull commits
pub struct PullCommits<'a> {
    github: &'a Github<'a>,
    owner: String,
    repo: String,
    number: u64,
}

impl<'a> PullCommits<'a> {
    pub fn new<O, R>(github: &'a Github<'a>, owner: O, repo: R, number: u64) -> PullCommits<'a>
        where O: Into<String>,
              R: Into<String>
    {
        PullCommits {
            github: github,
            owner: owner.into(),
            repo: repo.into(),
            number: number,
        }
    }

    /// list pull commits
    pub fn list(&self) -> Result<Vec<PullCommit>> {
        let uri = format!("/repos/{}/{}/pulls/{}/commits",
                          self.owner,
                          self.repo,
                          self.number);
        self.github.get::<Vec<PullCommit>>(&uri)
    }

    // provides an iterator over all pages of pull commits
    pub fn iter(&'a self) -> Result<Iter<'a, Vec<PullCommit>, PullCommit>> {
        let uri = format!("/repos/{}/{}/pulls/{}/commits",
                          self.owner,
                          self.repo,
                          self.number);
        self.github.iter(uri, identity)
    }
}