浏览代码

autoadd team label on issue assignment

apiraino 1 年之前
父节点
当前提交
4f53243193
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      src/handlers/assign.rs

+ 16 - 0
src/handlers/assign.rs

@@ -487,6 +487,22 @@ pub(super) async fn handle_command(
                     name.to_string()
                 } else {
                     let teams = crate::team_data::teams(&ctx.github).await?;
+                    // Determine if assignee is a team. If yes, add the corresponding label
+                    // team name here is without prefix 't-' (e.g. 'compiler', 'libs', etc.)
+                    if let Some(team) = teams.teams.get(&name) {
+                        let t_label = format!("t-{}", &team.name);
+                        if let Err(err) = issue
+                            .add_labels(&ctx.github, vec![github::Label { name: t_label }])
+                            .await
+                        {
+                            if let Some(github::UnknownLabels { .. }) = err.downcast_ref() {
+                                log::warn!("Error assigning label: {}", err);
+                            } else {
+                                return Err(err);
+                            }
+                        }
+                    }
+
                     match find_reviewer_from_names(&teams, config, issue, &[name]) {
                         Ok(assignee) => assignee,
                         Err(e) => {