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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! The commit API.
mod associated_check_runs;
mod associated_pull_requests;
mod compare_commit;
mod create_comment;

pub use associated_pull_requests::PullRequestTarget;

pub use self::create_comment::CreateCommentBuilder;
use crate::params::repos::Reference;
use crate::{models, Octocrab, Result};

pub struct CommitHandler<'octo> {
    crab: &'octo Octocrab,
    owner: String,
    repo: String,
}

impl<'octo> CommitHandler<'octo> {
    pub(crate) fn new(crab: &'octo Octocrab, owner: String, repo: String) -> Self {
        Self { crab, owner, repo }
    }

    // pub fn create(&self, title: impl Into<String>) -> create::CreateIssueBuilder<'_, '_> {
    //     create::CreateIssueBuilder::new(self, title.into())
    // }

    pub fn compare(
        &self,
        base: impl Into<String>,
        head: impl Into<String>,
    ) -> compare_commit::CompareCommitsBuilder<'_, '_> {
        compare_commit::CompareCommitsBuilder::new(self, base.into(), head.into())
    }

    pub fn associated_check_runs(
        &self,
        reference: impl Into<Reference>,
    ) -> associated_check_runs::AssociatedCheckRunsBuilder<'_, '_> {
        associated_check_runs::AssociatedCheckRunsBuilder::new(self, reference)
    }

    pub fn associated_pull_requests(
        &self,
        target: PullRequestTarget,
    ) -> associated_pull_requests::AssociatedPullRequestsBuilder<'_, '_> {
        associated_pull_requests::AssociatedPullRequestsBuilder::new(self, target)
    }

    pub fn create_comment(
        &self,
        sha: impl Into<String>,
        body: impl Into<String>,
    ) -> create_comment::CreateCommentBuilder<'_, '_> {
        create_comment::CreateCommentBuilder::new(self, sha.into(), body.into())
    }

    pub async fn get(&self, reference: impl Into<String>) -> Result<models::repos::RepoCommit> {
        let route = format!(
            "/repos/{owner}/{repo}/commits/{reference}",
            owner = self.owner,
            repo = self.repo,
            reference = reference.into(),
        );
        self.crab.get(route, None::<&()>).await
    }
}