项目管理系统Jira中的扩展组件

举报
码乐 发表于 2025/04/06 09:58:22 2025/04/06
【摘要】 1 简介本文将 FSM(有限状态机) 扩展到 Scrum 项目管理系统,我们可以围绕 Sprint 管理、用户故事流转 进行设计,实现完整的任务状态管理流程。这个组件可以嵌入到 Scrum 项目管理系统 中,例如 Jira、Trello、Azure DevOps 的自定义状态流转。 2. 设计数据库模型在 MySQL 中创建三个核心表:sprints:管理 Sprint 计划user_st...

1 简介

本文将 FSM(有限状态机) 扩展到 Scrum 项目管理系统,我们可以围绕 Sprint 管理、用户故事流转 进行设计,实现完整的任务状态管理流程。

这个组件可以嵌入到 Scrum 项目管理系统 中,例如 Jira、Trello、Azure DevOps 的自定义状态流转。

2. 设计数据库模型

在 MySQL 中创建三个核心表:

sprints:管理 Sprint 计划

user_stories:存储用户故事信息

tasks:管理任务及其 FSM 状态流转

(1) sprints 表

CREATE TABLE sprints (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    start_date DATE NOT NULL,
    end_date DATE NOT NULL,
    status ENUM('planned', 'active', 'completed', 'cancelled') DEFAULT 'planned'
);

(2) user_stories 表

  CREATE TABLE user_stories (
      id INT AUTO_INCREMENT PRIMARY KEY,
      sprint_id INT,
      title VARCHAR(255) NOT NULL,
      description TEXT,
      status ENUM('backlog', 'selected', 'in_progress', 'completed') DEFAULT 'backlog',
      FOREIGN KEY (sprint_id) REFERENCES sprints(id) ON DELETE SET NULL
  );

(3) tasks 表

  CREATE TABLE tasks (
      id INT AUTO_INCREMENT PRIMARY KEY,
      user_story_id INT,
      title VARCHAR(255) NOT NULL,
      status ENUM('to_do', 'in_progress', 'in_testing', 'done') DEFAULT 'to_do',
      assigned_to VARCHAR(255),
      FOREIGN KEY (user_story_id) REFERENCES user_stories(id) ON DELETE CASCADE
  );

3. FSM + MySQL 结合

我们使用 transitions 处理任务的状态转换,并结合 MySQL 来存储任务状态。

(1) 安装必要的库

		pip install mysql-connector-python transitions

(2) 连接 MySQL 数据库

    import mysql.connector
    from transitions import Machine
  • 连接到 MySQL

    db = mysql.connector.connect(
        host="localhost",
        user="root",
        password="password",
        database="scrum_db"
    )
      	cursor = db.cursor()
    

(3) 任务状态机(FSM)实现

  class TaskFSM:
      states = ['to_do', 'in_progress', 'in_testing', 'done']

      def __init__(self, task_id):
          self.task_id = task_id
          self.state = self.get_task_state()  # 从数据库获取当前状态
          self.machine = Machine(model=self, states=TaskFSM.states, initial=self.state)

          # 定义状态转换
          self.machine.add_transition('start_task', 'to_do', 'in_progress', after=self.update_db)
          self.machine.add_transition('submit_for_testing', 'in_progress', 'in_testing', after=self.update_db)
          self.machine.add_transition('approve', 'in_testing', 'done', after=self.update_db)
          self.machine.add_transition('reopen', '*', 'to_do', after=self.update_db)

      def get_task_state(self):
          cursor.execute("SELECT status FROM tasks WHERE id = %s", (self.task_id,))
          result = cursor.fetchone()
          return result[0] if result else 'to_do'

      def update_db(self):
          cursor.execute("UPDATE tasks SET status = %s WHERE id = %s", (self.state, self.task_id))
          db.commit()
          print(f"Task {self.task_id} moved to {self.state}")
  • 示例使用

      task = TaskFSM(task_id=1)
      print(task.state)  # 获取当前状态
    
      task.start_task()  # 任务开始
      task.submit_for_testing()  # 任务提交测试
      task.approve()  # 任务完成
    
  • 扩展 Sprint 和 用户故事的 FSM

类似地,我们可以为 Sprint 和 用户故事 添加 FSM。

(1) Sprint FSM

  class SprintFSM:
      states = ['planned', 'active', 'completed', 'cancelled']

      def __init__(self, sprint_id):
          self.sprint_id = sprint_id
          self.state = self.get_sprint_state()
          self.machine = Machine(model=self, states=SprintFSM.states, initial=self.state)

          # 状态转换
          self.machine.add_transition('start_sprint', 'planned', 'active', after=self.update_db)
          self.machine.add_transition('complete_sprint', 'active', 'completed', after=self.update_db)
          self.machine.add_transition('cancel_sprint', 'planned', 'cancelled', after=self.update_db)

      def get_sprint_state(self):
          cursor.execute("SELECT status FROM sprints WHERE id = %s", (self.sprint_id,))
          result = cursor.fetchone()
          return result[0] if result else 'planned'

      def update_db(self):
          cursor.execute("UPDATE sprints SET status = %s WHERE id = %s", (self.state, self.sprint_id))
          db.commit()
          print(f"Sprint {self.sprint_id} moved to {self.state}")
  • 示例使用

    sprint = SprintFSM(sprint_id=1)
    sprint.start_sprint()
    sprint.complete_sprint()
    

(2) 用户故事 FSM

  class UserStoryFSM:
      states = ['backlog', 'selected', 'in_progress', 'completed']

      def __init__(self, user_story_id):
          self.user_story_id = user_story_id
          self.state = self.get_story_state()
          self.machine = Machine(model=self, states=UserStoryFSM.states, initial=self.state)

          # 状态转换
          self.machine.add_transition('select_story', 'backlog', 'selected', after=self.update_db)
          self.machine.add_transition('start_story', 'selected', 'in_progress', after=self.update_db)
          self.machine.add_transition('complete_story', 'in_progress', 'completed', after=self.update_db)

      def get_story_state(self):
          cursor.execute("SELECT status FROM user_stories WHERE id = %s", (self.user_story_id,))
          result = cursor.fetchone()
          return result[0] if result else 'backlog'

      def update_db(self):
          cursor.execute("UPDATE user_stories SET status = %s WHERE id = %s", (self.state, self.user_story_id))
          db.commit()
          print(f"User Story {self.user_story_id} moved to {self.state}")
  • 示例使用

    story = UserStoryFSM(user_story_id=1)
    story.select_story()
    story.start_story()
    story.complete_story()
    

4. 小结

MySQL 负责存储任务、用户故事、Sprint 的状态,确保数据持久化。

FSM 负责管理状态流转,确保流程符合 Scrum 规范。

Python + transitions 负责处理状态转换逻辑,并自动更新数据库。

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。