Skip to content

Commit 205db23

Browse files
committed
[IMP] migration_issue_bot: Prevent overwriting migration issue
A new migration PR can overwrite the PR in the migration issue only if the latter is closed
1 parent d6b4161 commit 205db23

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/oca_github_bot/tasks/migration_issue_bot.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,22 @@ def migration_issue_start(org, repo, pr, username, module=None, dry_run=False):
122122
new_body, old_pr_number = _set_lines_issue(
123123
gh_pr.user.login, gh_pr.number, issue.body, module
124124
)
125-
issue.edit(body=new_body)
126125
if old_pr_number and old_pr_number != pr:
127126
old_pr = gh.pull_request(org, repo, old_pr_number)
128-
github.gh_call(
129-
gh_pr.create_comment,
130-
f"The migration issue (#{issue.number}) has been updated"
131-
f" to reference the current pull request.\n"
132-
f"however, a previous pull request was referenced :"
133-
f" #{old_pr_number}.\n"
134-
f"Perhaps you should check that there is no duplicate work.\n"
135-
f"CC : @{old_pr.user.login}",
136-
)
127+
if old_pr.state == "closed":
128+
issue.edit(body=new_body)
129+
else:
130+
github.gh_call(
131+
gh_pr.create_comment,
132+
f"The migration issue (#{issue.number})"
133+
f" has not been updated to reference the current pull request"
134+
f" because a previous pull request (#{old_pr_number})"
135+
f" is not closed.\n"
136+
f"Perhaps you should check that there is no duplicate work.\n"
137+
f"CC @{old_pr.user.login}",
138+
)
139+
else:
140+
issue.edit(body=new_body)
137141
except Exception as e:
138142
github.gh_call(
139143
gh_pr.create_comment,

0 commit comments

Comments
 (0)