Last active
May 2, 2019 17:35
-
-
Save FFY00/e5366536ca946fa1f94a52ef9fd65c04 to your computer and use it in GitHub Desktop.
Solaar Migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Requires https://github.com/PyGithub/PyGithub/pull/1107 | |
from github import Github | |
from github.GithubException import UnknownObjectException | |
g = Github("TOKEN_HERE") | |
print("Logged...") | |
repo_from = g.get_repo('pwr/Solaar') | |
repo_to = g.get_repo('pwr-Solaar/Solaar') | |
start = 1 | |
end = 523 | |
old_closed_msg = "This %s was moved to https://github.com/pwr-Solaar/Solaar/issues/%d." | |
old_open_issue_msg = """Hi! This issue was moved to https://github.com/pwr-Solaar/Solaar/issues/%d.. | |
If the reported issue is still valid, please consider reopening the new issue. | |
For more information on this mass migration, see https://github.com/pwr-Solaar/Solaar/issues/524. | |
Thank you for your interest!""" | |
old_open_pull_msg = """Hi! This pull request was closed in the migration to the new repository. | |
If it is still valid, please consider reopening it in https://github.com/pwr-Solaar/Solaar. | |
For more information on this mass migration, see https://github.com/pwr-Solaar/Solaar/issues/524. | |
Thank you for your interest!""" | |
new_msg = "This %s was originally reported at https://github.com/pwr/Solaar/issues/%d by @%s.%s" | |
new_issue_extra_msg = "\nFurther discussion may take place here." | |
for i in range(start, end+1): | |
print("Migrating #%d" % i) | |
obj_type = "pull request" | |
# All pull requests are issues, not all issues are pull requests | |
try: | |
repo_from.get_pull(i) | |
except UnknownObjectException: | |
obj_type = "issue" | |
# Get issue instance, even if it is a pull request | |
obj = repo_from.get_issue(i) | |
# Open new issue | |
new_obj = repo_to.create_issue(obj.title, labels=["migrated"], | |
body=(new_msg % (obj_type, i, obj.user.login, | |
new_issue_extra_msg if obj_type == "issue" else ""))) | |
# Add migration comment to old issue/pull | |
if obj.state == "closed": | |
obj.create_comment(old_closed_msg % (obj_type, i)) | |
# Close new issue if old one was also closed | |
new_obj.edit(state="closed") | |
elif obj.state == "open": | |
if obj_type == "issue": | |
obj.create_comment(old_open_issue_msg % i) | |
elif obj_type == "pull request": | |
obj.create_comment(old_open_pull_msg) | |
# Close old issue/pull | |
obj.edit(state="closed") | |
obj.lock("resolved") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment