From 99941be9c63828f666acbcda4c4e3e21c7353ff2 Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Tue, 20 Feb 2024 19:45:33 +0800 Subject: [PATCH] fix creater --- server/tasks/lark/issue.py | 11 ++++++----- server/tasks/lark/pull_request.py | 25 +++---------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/server/tasks/lark/issue.py b/server/tasks/lark/issue.py index a374a6cb..6ebc4c6f 100644 --- a/server/tasks/lark/issue.py +++ b/server/tasks/lark/issue.py @@ -80,9 +80,9 @@ def get_assignees_by_issue(issue, team): return assignees -def get_creater_by_issue(issue, team): - code_name = issue.extra["user"].get("login", None) - +def get_creater_by_item(item, team): + code_name = item.extra["user"].get("login", None) + creater = None if code_name: creater = ( db.session.query(IMUser.openid) @@ -94,6 +94,7 @@ def get_creater_by_issue(issue, team): .filter( TeamMember.team_id == team.id, CodeUser.name == code_name, + CodeUser.status == 0, ) .scalar() ) @@ -102,7 +103,7 @@ def get_creater_by_issue(issue, team): def gen_issue_card_by_issue(bot, issue, repo_url, team, maunal=False): assignees = get_assignees_by_issue(issue, team) - creater, code_name = get_creater_by_issue(issue, team) + creater, code_name = get_creater_by_item(issue, team) tags = [i["name"] for i in issue.extra.get("labels", [])] status = issue.extra.get("state", "opened") if status == "closed": @@ -344,7 +345,7 @@ def send_issue_card(issue_id): db.session.commit() assignees = get_assignees_by_issue(issue, team) - creater, _ = get_creater_by_issue(issue, team) + creater, _ = get_creater_by_item(issue, team) if creater not in assignees and creater: assignees.append(creater) diff --git a/server/tasks/lark/pull_request.py b/server/tasks/lark/pull_request.py index 20a8a6b9..f4e90cc4 100644 --- a/server/tasks/lark/pull_request.py +++ b/server/tasks/lark/pull_request.py @@ -17,6 +17,7 @@ from model.team import get_assignees_by_openid from tasks.lark.issue import ( gen_comment_post_message, + get_creater_by_item, get_github_name_by_openid, replace_im_name_to_github_name, replace_images_with_keys, @@ -93,29 +94,9 @@ def get_assignees_by_pr(pr, team): return assignees -def get_creater_by_pr(pr, team): - code_name = pr.extra["user"].get("login", None) - - if code_name: - creater = ( - db.session.query(IMUser.openid) - .join(TeamMember, TeamMember.im_user_id == IMUser.id) - .join( - CodeUser, - CodeUser.id == TeamMember.code_user_id, - ) - .filter( - TeamMember.team_id == team.id, - CodeUser.name == code_name, - ) - .scalar() - ) - return creater, code_name - - def gen_pr_card_by_pr(pr: PullRequest, repo_url, team, maunal=False): assignees = get_assignees_by_pr(pr, team) - creater, code_name = get_creater_by_pr(pr, team) + creater, code_name = get_creater_by_item(pr, team) reviewers = pr.extra.get("requested_reviewers", []) if len(reviewers): @@ -371,7 +352,7 @@ def send_pull_request_card(pull_request_id: str): db.session.commit() assignees = get_assignees_by_pr(pr, team) - creater, _ = get_creater_by_pr(pr, team) + creater, _ = get_creater_by_item(pr, team) if creater not in assignees and creater: assignees.append(creater)