tracking_issue.rs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #![cfg(empty)]
  2. use crate::{
  3. github::GithubClient,
  4. registry::{Event, Handler},
  5. team::Team,
  6. IssueCommentAction, IssueCommentEvent,
  7. };
  8. use failure::Error;
  9. use lazy_static::lazy_static;
  10. use regex::Regex;
  11. pub struct TrackingIssueHandler {
  12. pub client: GithubClient,
  13. }
  14. impl TrackingIssueHandler {
  15. /// Automates creating tracking issues.
  16. ///
  17. /// This command is initially restricted to members of Rust teams.
  18. ///
  19. /// This command is rare, and somewhat high-impact, so it requires the `@bot` prefix.
  20. /// The syntax for creating a tracking issue follows. Note that only the libs and lang teams are
  21. /// currently supported; it's presumed that the other teams may want significantly different
  22. /// issue formats, so only these two are supported for the time being.
  23. ///
  24. /// `@bot tracking-issue create feature="<short feature description>" team=[libs|lang]`
  25. ///
  26. /// This creates the tracking issue, though it's likely that the invokee will want to edit its
  27. /// body/title.
  28. ///
  29. /// Long-term, this will also create a thread on internals and lock the tracking issue,
  30. /// directing commentary to the thread, but for the time being we limit the scope of work as
  31. /// well as project impact.
  32. fn handle_create(&self, event: &IssueCommentEvent) -> Result<(), Error> {
  33. lazy_static! {
  34. static ref RE_TRACKING: Regex = Regex::new(&format!(
  35. r#"\b@{} tracking-issue create feature=("[^"]+|\S+) team=(libs|lang)"#,
  36. crate::BOT_USER_NAME,
  37. ))
  38. .unwrap();
  39. }
  40. // Skip this event if the comment is edited or deleted.
  41. if event.action != IssueCommentAction::Created {
  42. return Ok(());
  43. }
  44. #[allow(unused)]
  45. let feature;
  46. #[allow(unused)]
  47. let team;
  48. if let Some(captures) = RE_TRACKING.captures(&event.comment.body) {
  49. #[allow(unused)]
  50. {
  51. feature = captures.get(1).unwrap();
  52. team = captures.get(2).unwrap().as_str().parse::<Team>()?;
  53. }
  54. } else {
  55. // no tracking issue creation comment
  56. return Ok(());
  57. }
  58. // * Create tracking issue (C-tracking-issue, T-{team})
  59. // * Post comment with link to issue and suggestion on what to do next
  60. Ok(())
  61. }
  62. /// Links issues to tracking issues.
  63. ///
  64. /// We verify that the tracking issue listed is in fact a tracking issue (i.e., has the
  65. /// C-tracking-issue label). Next, the tracking issue's top comment is updated with a link and
  66. /// title of the issue linked as a checkbox in the bugs list.
  67. ///
  68. /// We also label the issue with `tracked-bug`.
  69. ///
  70. /// TODO: Check the checkbox in the tracking issue when `tracked-bug` is closed.
  71. ///
  72. /// Syntax: `link: #xxx`
  73. fn handle_link(&self, _event: &IssueCommentEvent) -> Result<(), Error> {
  74. Ok(())
  75. }
  76. }
  77. impl Handler for TrackingIssueHandler {
  78. fn handle_event(&self, event: &Event) -> Result<(), Error> {
  79. //self.handle_create(&event)?;
  80. //self.handle_link(&event)?;
  81. Ok(())
  82. }
  83. }