azure_rust/pull_requests/
pull.rs

1use super::{PullRequestResponse, PullStatus, PullUpdateOptions};
2use crate::{AzureClient, Future};
3
4pub struct PullRequest {
5    ops: AzureClient,
6    project: String,
7    repo: String,
8    id: u64,
9}
10
11impl PullRequest {
12    #[doc(hidden)]
13    pub fn new<P, R>(ops: AzureClient, project: P, repo: R, id: u64) -> Self
14    where
15        P: Into<String>,
16        R: Into<String>,
17    {
18        Self {
19            ops: ops,
20            project: project.into(),
21            repo: repo.into(),
22            id: id,
23        }
24    }
25
26    /// https://dev.azure.com/bentestingacc/Azure-Testing/_apis/git/repositories/064ad20f-f240-4747-8cc0-057175cab664/pullrequests?api-version=5.1
27    fn path(&self, more: &str) -> String {
28        format!(
29            "/{}/{}/_apis/git/repositories/{}/pullrequests/{}{}",
30            self.ops.org, self.project, self.repo, self.id, more
31        )
32    }
33    /// Request a pull requests information
34    pub fn get(&self) -> Future<PullRequestResponse> {
35        self.ops.get(&self.path(""))
36    }
37
38    /// Update a pull request
39    pub fn update(&self, pr: &PullUpdateOptions) -> Future<PullRequestResponse> {
40        let body = json!(pr);
41        self.ops
42            .patch::<PullRequestResponse>(&self.path("?"), body)
43    }
44
45    /// short hand for updating pr status = active
46    pub fn active(&self) -> Future<PullRequestResponse> {
47        self.update(&PullUpdateOptions::builder().status(PullStatus::Active).build())
48    }
49
50    /// short hand for updating pr status = abandoned
51    pub fn abandon(&self) -> Future<PullRequestResponse> {
52        self.update(&PullUpdateOptions::builder().status(PullStatus::Abandoned).build())
53    }
54
55}