Skip to content

Commit

Permalink
fix creater
Browse files Browse the repository at this point in the history
  • Loading branch information
freeziyou committed Feb 20, 2024
1 parent 68a71bf commit 99941be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
11 changes: 6 additions & 5 deletions server/tasks/lark/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
)
Expand All @@ -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":
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 3 additions & 22 deletions server/tasks/lark/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 99941be

Please sign in to comment.