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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
use chrono::{DateTime, Utc}; use Client; use Error; use ProjectGroup; /// Represents a task from the storyboard API. #[derive(Serialize, Deserialize, Debug)] pub struct Task { /// The ID of the user that this task is assigned. pub assignee_id: Option<i32>, /// The ID of the branch. pub branch_id: Option<i32>, /// The ID of the user that created this task. pub creator_id: Option<i32>, /// The due dates related with this task pub due_dates: Option<Vec<DateTime<Utc>>>, /// The link to the related resource to this task. pub link: Option<String>, /// The ID of the corresponding milestone. pub milestone_id: Option<i32>, /// The priority of this task. // TODO: Change this to an enum. pub priority: Option<String>, /// The ID of the corresponding project. pub project_id: Option<i32>, /// The status of this task. // TODO: Change this to an enum. pub status: Option<String>, /// The ID of the corresponding story. pub story_id: i32, /// An optional short label for this task. pub title: String, } /// A counter of task status changes. /// /// This type is usually used internally. // TODO: Change this type to be private. #[derive(Serialize, Deserialize, Debug)] pub struct TaskStatusCount { /// The counter of changes pub count: Option<i32>, /// The key. pub key: String, } impl Client { /// Search tasks with the given search string /// /// # Example /// /// ```rust /// extern crate storyboard_client; /// /// use storyboard_client::{Client, Error}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<(), Error> { /// let client = Client::new("https://storyboard.openstack.org/api/v1"); /// let tasks = client.search_tasks("stx")?; /// assert_ne!(tasks.len(), 0); /// Ok(()) /// } /// ``` pub fn search_tasks(&self, s: &str) -> Result<Vec<Task>, Error> { let url = format!("{}/tasks/search?q={}", self.uri, s); let stories: Vec<Task> = self.fetch_url(&url)?; Ok(stories) } /// Get all tasks with the given `ProjectGroup` /// /// # Example /// /// ```rust /// extern crate storyboard_client; /// /// use storyboard_client::{Client, Error, ProjectGroup}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<(), Error> { /// let client = Client::new("https://storyboard.openstack.org/api/v1"); /// let group = ProjectGroup { id: 86, ..Default::default() }; /// let tasks = client.get_tasks_in_project_group(&group)?; /// assert_ne!(tasks.len(), 0); /// Ok(()) /// } /// ``` pub fn get_tasks_in_project_group(&self, g: &ProjectGroup) -> Result<Vec<Task>, Error> { let url = format!("{}/tasks?project_group_id={}", self.uri, g.id); let tasks: Vec<Task> = self.fetch_url(&url)?; Ok(tasks) } }